Skip to content

Fix YAML syntax error in workflow #16

Fix YAML syntax error in workflow

Fix YAML syntax error in workflow #16

Workflow file for this run

name: Publish to dev.to
on:
push:
branches:
- main
paths:
- "_posts/**.md"
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install Python dependencies
run: pip3 install pyyaml
- name: Detect new posts and publish to dev.to
env:
DEVTO_API_KEY: ${{ secrets.DEVTO_API_KEY }}
BLOG_URL: "https://ewertoncodes.github.io"
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
NEW_POSTS=$(ls _posts/*.md 2>/dev/null || true)
else
NEW_POSTS=$(git diff --name-only --diff-filter=AM HEAD~1 HEAD -- '_posts/**.md')
fi
if [ -z "$NEW_POSTS" ]; then
echo "Nenhum post novo encontrado."
exit 0
fi
for POST in $NEW_POSTS; do
echo "Publicando: $POST"
python3 -c "
import os, re, json, urllib.request, urllib.error, yaml

Check failure on line 42 in .github/workflows/publish-devto.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/publish-devto.yml

Invalid workflow file

You have an error in your yaml syntax on line 42
post_path = '$POST'
blog_url = '$BLOG_URL'
api_key = '$DEVTO_API_KEY'
with open(post_path, 'r') as f:
content = f.read()
parts = content.split('---', 2)
if len(parts) >= 3:
front_matter = yaml.safe_load(parts[1])
body = parts[2].strip()
title = front_matter.get('title', '')
description = front_matter.get('description', '')
tags = front_matter.get('tags', [])
if isinstance(tags, list):
tags = [str(tag).strip() for tag in tags if tag]
else:
tags = [str(tags)] if tags else []
tags = tags[:4]
if not tags:
tags = ['database']
print('⚠️ Nenhuma tag encontrada, usando database como padrão')
else:
title = ''
description = ''
tags = ['database']
body = content
filename = os.path.basename(post_path).replace('.md', '')
slug = re.sub(r'^\d{4}-\d{2}-\d{2}-', '', filename)
canonical = f'{blog_url}/posts/{slug}/'
body = re.sub(r'\{:\s*\.prompt-\w+\s*\}', '', body)
print(f'Título: {title}')
print(f'Tags: {tags}')
print(f'Canonical: {canonical}')
payload = {
'article': {
'title': title,
'body_markdown': body,
'published': True,
'canonical_url': canonical,
'description': description,
'tags': tags,
}
}
data = json.dumps(payload).encode('utf-8')
req = urllib.request.Request(
'https://dev.to/api/articles',
data=data,
headers={'Content-Type': 'application/json', 'api-key': api_key},
method='POST',
)
try:
with urllib.request.urlopen(req) as res:
result = json.loads(res.read())
print(f'Publicado com sucesso!')
print(f'URL: {result.get('url')}')
print(f'Canonical: {canonical}')
except urllib.error.HTTPError as e:
error_msg = e.read().decode()
print(f'Erro ao publicar: {e.code} - {error_msg}')
exit(1)
"
done