Skip to content

.github/workflows/generateSnippets.yml #95

.github/workflows/generateSnippets.yml

.github/workflows/generateSnippets.yml #95

on:
schedule:
# At 00:00 on Monday.
- cron: '0 0 * * 1'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install deps
run: |
npm install
- name: Generate HubL Snippets
run: |
node ./scripts/generate.js
- name: Check git diff for changes
run: |
if [[ $(git diff --stat ./snippets ) != '' ]]; then
echo "SNIPPET_DIR_CHANGES=true" >> $GITHUB_ENV
echo "Changes to snippet definitions have been detected"
else
echo "There are no snippet changes"
fi
- name: Commit and push changes
if: env.SNIPPET_DIR_CHANGES == 'true'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b 'update_snippets'
git add .
git commit -m "Add updated snippets"
git push -u origin update_snippets --force
- name: Create PR if needed
if: env.SNIPPET_DIR_CHANGES == 'true'
run: |
if [[ $(gh pr list --search "is:open 'Update HubL Snippets'") == '' ]]; then
gh pr create --title "[Automatic] Update HubL Snippets" --body "This PR is autogenerated via GitHub Actions and should be reviewed before merging changes"
echo "Created 'Update HubL Snippets' PR"
else
echo "The 'Update HubL Snippets' PR is already open"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}