NEW LINK: #6
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 New Awesome List | |
| on: | |
| issues: | |
| types: [labeled] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.issue.number || github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish-awesome-list: | |
| if: github.event.label.name == 'approved' && contains(github.event.issue.labels.*.name, 'new-resource') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install deps | |
| run: pip install jsonschema requests | |
| - name: Idempotency check (existing PR?) | |
| id: pr_check | |
| env: | |
| ISSUE: ${{ github.event.issue.number }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| existing=$(gh pr list --state open --json number,title,body,headRefName | jq --arg ref "#${ISSUE}" '[ .[] | select((.title|contains($ref)) or (.body|contains($ref))) ]') | |
| count=$(echo "$existing" | jq 'length') | |
| if [ "$count" -gt 0 ]; then | |
| echo "PR already exists referencing issue #$ISSUE"; | |
| echo "skip_pr=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip_pr=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Extract metadata from last analysis comment | |
| id: meta | |
| env: | |
| ISSUE: ${{ github.event.issue.number }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api repos/${{ github.repository }}/issues/$ISSUE/comments --jq '.[-1].body' > comment.txt || echo '' > comment.txt | |
| python .github/scripts/extract_meta_from_comment.py comment.txt | |
| - name: Add to resources.json | |
| if: steps.pr_check.outputs.skip_pr != 'true' | |
| run: | | |
| python .github/scripts/add_resource.py \ | |
| --url "${{ steps.meta.outputs.url }}" \ | |
| --title "${{ steps.meta.outputs.title }}" \ | |
| --description "${{ steps.meta.outputs.description }}" \ | |
| --category "${{ steps.meta.outputs.category }}" \ | |
| --issue ${{ github.event.issue.number }} \ | |
| --approve | |
| - name: Regenerate README (skip if none approved yet) | |
| if: steps.pr_check.outputs.skip_pr != 'true' | |
| run: python .github/scripts/generate_readme.py | |
| - name: Validate schema & sync | |
| if: steps.pr_check.outputs.skip_pr != 'true' | |
| run: | | |
| python .github/scripts/validate_resources.py | |
| python .github/scripts/check_readme_sync.py | |
| - name: Commit & PR | |
| if: steps.pr_check.outputs.skip_pr != 'true' | |
| env: | |
| ISSUE: ${{ github.event.issue.number }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name 'github-actions[bot]' | |
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| BRANCH="add-resource-${ISSUE}" | |
| git checkout -B "$BRANCH" | |
| git add resources.json README.md || true | |
| if git diff --cached --quiet; then echo 'No changes'; exit 0; fi | |
| git commit -m "feat: add resource from issue #${ISSUE}" || exit 0 | |
| git push origin "$BRANCH" --force | |
| gh pr create --fill --head "$BRANCH" || true | |
| - name: Already had PR - annotate issue | |
| if: steps.pr_check.outputs.skip_pr == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.issues.createComment({owner:context.repo.owner,repo:context.repo.repo,issue_number:context.issue.number,body:'Skipping approval workflow: PR already exists for this issue.'}); |