Files
hatchet/.github/workflows/gen-examples.yml
matt f8e5f357d9 Fix: More examples / snippets fixes + rework (#2150)
* feat: start reworking snippets

* feat: start cleaning up gen script

* fix: start updating refs everywhere

* feat: start fixing broken snippet links

* fix: more snippets

* fix: more updates

* chore: lint

* fix: taskfile

* fix: script

* fix: escaping issue + mergent blog

* fix: bunch more

* chore: lint

* fix: implement more of them

* fix: retry

* fix: the rest

* chore: lint

* fix: highlight

* fix: ugh

* fix: start removing dead code from old snippet method

* fix: rest of the refs

* fix: remove all of the rest of the <GithubSnippet uses

* fix: couple more

* fix: last few errors

* fix: handle example writes

* fix: delete to test update

* fix: CI, attempt 1

* feat: helpful error on no snippet

* fix: lint

* chore: rm unused js file

* feat: improve GHA

* debug: run action on branch

* fix: rm pnpm

* fix: try to leave comment instead

* fix: don't run on branch

* fix: factor out GH info

* fix: include code path

* fix: ts
2025-08-17 10:22:16 -05:00

97 lines
3.4 KiB
YAML

name: generate examples
on:
push:
branches: [ main ]
jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Generate snippets
working-directory: frontend/snippets
run: python3 generate.py
- name: Check for changes in examples directory
id: verify-changed-files
run: |
# Check if there are any changes
if [ -n "$(git status --porcelain)" ]; then
CHANGED_FILES=$(git status --porcelain | awk '{print $2}')
NON_EXAMPLES_CHANGES=$(echo "$CHANGED_FILES" | grep -v "^examples/" || true)
if [ -n "$NON_EXAMPLES_CHANGES" ]; then
echo "Error: Changes detected outside of examples directory:"
echo "$NON_EXAMPLES_CHANGES"
echo "changed=false" >> $GITHUB_OUTPUT
exit 1
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Create branch and commit changes
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
BRANCH_NAME="regenerate-examples-${{ github.sha }}"
git checkout -b "$BRANCH_NAME"
git add examples/
git commit -m "chore: regenerate examples"
git push origin "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
id: create-branch
- name: Close existing autogenerated-docs PRs
if: steps.verify-changed-files.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
EXISTING_PRS=$(gh pr list --label "autogenerated-docs" --state open --json number --jq '.[].number')
for pr in $EXISTING_PRS; do
if [ -n "$pr" ]; then
echo "Closing existing autogenerated-docs PR #$pr"
gh pr close $pr --comment "Closing in favor of newer autogenerated-docs PR"
fi
done
- name: Create Pull Request
if: steps.verify-changed-files.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--title "chore: regenerate examples" \
--body "Automated regeneration of examples from the main branch." \
--head "${{ steps.create-branch.outputs.branch_name }}" \
--base main \
--label "autogenerated-docs"
echo "pr_number=$(gh pr list --head ${{ steps.create-branch.outputs.branch_name }} --json number --jq '.[0].number')" >> $GITHUB_OUTPUT
id: create-pr
- name: Request review from triggering author
if: steps.verify-changed-files.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
AUTHOR="${{ github.actor }}"
if [ "$AUTHOR" != "github-actions[bot]" ]; then
gh pr edit "${{ steps.create-branch.outputs.branch_name }}" --add-reviewer "$AUTHOR" || {
gh pr comment "${{ steps.create-branch.outputs.branch_name }}" --body "@$AUTHOR Please review this autogenerated PR"
}
echo "Requested review from $AUTHOR"
else
echo "Skipping review request as author is github-actions bot"
fi