add aws roles anywhere #301
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to dev.to | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'articles/**/*.md' | |
| workflow_dispatch: | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get changed files | |
| id: changed-files | |
| uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 | |
| with: | |
| files: articles/*.md | |
| - name: Publish articles | |
| env: | |
| DEVTO_API_KEY: ${{ secrets.DEVTO_API_KEY }} | |
| run: | | |
| # Determine which files to publish | |
| if [ "${{ steps.changed-files.outputs.any_changed }}" == "true" ]; then | |
| FILES="${{ steps.changed-files.outputs.all_changed_files }}" | |
| echo "Detected changed files: $FILES" | |
| else | |
| # On manual trigger or if no specific changes detected in articles/ | |
| FILES=$(ls articles/*.md) | |
| echo "No specific changes detected or manual trigger. Processing all files." | |
| fi | |
| # Install devto-cli | |
| npm install -g @sinedied/devto-cli | |
| for file in $FILES; do | |
| if [ -f "$file" ]; then | |
| echo "------------------------------------------------------" | |
| echo "Publishing $file..." | |
| dev push "$file" -t $DEVTO_API_KEY -r ${{ github.repository }} | |
| # Wait to avoid 429 Too Many Requests | |
| # dev.to API rate limit is around 3 requests per second, | |
| # but giving it more breath is safer for large batches. | |
| echo "Waiting 5 seconds..." | |
| sleep 5 | |
| fi | |
| done | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Stage all potential changes (article IDs or dates updated by devto-cli) | |
| git add articles/*.md | |
| if ! git diff --cached --exit-code; then | |
| echo "Changes detected in frontmatter. Committing..." | |
| git commit -m "chore: update article metadata from dev.to [skip ci]" | |
| git push | |
| else | |
| echo "No changes to commit." | |
| fi |