Files
hatchet/.github/workflows/gen-examples.yml
T
dependabot[bot] b02f085c34 chore(deps): bump actions/checkout from 4 to 5 (#2147)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: abelanger5 <belanger@sas.upenn.edu>
2025-09-10 07:31:06 -04: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@v5
- uses: actions/setup-python@v6
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