Skip to content

Update Phan stubs

Update Phan stubs #25

name: Update Phan stubs
on:
workflow_dispatch:
schedule:
- cron: '22 0 * * 1,2,3,4,5'
concurrency:
group: update-phan-stubs-${{ github.ref }}
permissions:
contents: write
pull-requests: write
env:
GIT_AUTHOR_NAME: matticbot
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: matticbot
GIT_COMMITTER_EMAIL: [email protected]
jobs:
update-stubs:
name: Update stubs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Use the matticbot token so CI runs on the created PR.
token: ${{ secrets.API_TOKEN_GITHUB }}
- name: Update stubs
run: tools/stubs/update-stubs.sh
- name: Check for changes
id: changes
run: |
if git diff --exit-code; then
echo "::notice::No changes"
echo "needed=false" >> "$GITHUB_OUTPUT"
elif ! [[ "$(date +%e)" -le 7 && "$(date +%A)" == Thursday ]] && git diff --exit-code --ignore-matching-lines='^ \* Stubs automatically generated from' >/dev/null; then
echo "::notice::No changes (other than version bumps) and it's not the first Thursday"
echo "needed=false" >> "$GITHUB_OUTPUT"
elif git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin update/phan-custom-stubs >/dev/null; then
TMP=$( git -c core.quotepath=off diff --name-only )
mapfile -t FILES <<<"$TMP"
if git diff --quiet --exit-code origin/update/phan-custom-stubs "${FILES[@]}"; then
echo "::notice::Branch already exists and is up to date with these changes"
echo "needed=false" >> "$GITHUB_OUTPUT"
else
echo "::notice::Branch needs updating"
echo "has-branch=true" >> "$GITHUB_OUTPUT"
echo "needed=true" >> "$GITHUB_OUTPUT"
fi
else
echo "::notice::Branch needs creating"
echo "has-branch=false" >> "$GITHUB_OUTPUT"
echo "needed=true" >> "$GITHUB_OUTPUT"
fi
- name: Create commit and PR
if: steps.changes.outputs.needed == 'true' && steps.changes.outputs.has-branch == 'false'
env:
GH_TOKEN: ${{ secrets.API_TOKEN_GITHUB }}
run: |
git checkout -b update/phan-custom-stubs
git commit -am 'phan: Update custom stubs'
git push origin HEAD
gh pr create --title 'phan: Update custom stubs' --body 'This is an automatic update generated by a GitHub Action. If closed it will be recreated the next time the action runs.' --label '[Pri] Normal' --label '[Type] Janitorial' --label '[Status] Needs Review'
- name: Update existing branch
if: steps.changes.outputs.needed == 'true' && steps.changes.outputs.has-branch == 'true'
run: |
git commit -am 'phan: Update custom stubs'
SHA=$( git rev-parse HEAD )
git checkout update/phan-custom-stubs
git reset --hard "$SHA"
git push --force-with-lease origin HEAD