Skip to content

💻 Programs count #10757

💻 Programs count

💻 Programs count #10757

# Script to update files that should have been automatically generated.
name: Automatically update generated files
on:
push:
branches: [ main ]
pull_request_target:
branches: [ main ]
types: [opened, synchronize, reopened]
jobs:
autopr:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write
steps:
- name: Print event (for debugging)
run: cat $GITHUB_EVENT_PATH
#----------------------------------------------------------------------
# Either use FELIENNE_GITHUB_ACCESS_TOKEN or GITHUB_TOKEN
# GITHUB_TOKEN can do fewer things (push to main, trigger new GHAs, etc).
- name: Check for presence of GitHub Token
id: secret
run: |
if [ ! -z "${{ secrets.FELIENNE_GITHUB_ACCESS_TOKEN }}" ]; then
echo "We have a token!"
echo "secret=${{ secrets.FELIENNE_GITHUB_ACCESS_TOKEN }}" >> $GITHUB_OUTPUT
else
echo "We do not have a token"
echo "secret=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
fi
- name: Determine branch name
id: branch
run: |
if [[ "${{ github.event_name }}" == "pull_request"* ]]; then
echo "Pull Request"
echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
echo "repo=${{ github.event.pull_request.head.repo.full_name }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "push" ]]; then
echo "Push Event"
echo "branch=${{ github.ref }}" >> $GITHUB_OUTPUT
echo "repo=${{ github.event.repository.full_name }}" >> $GITHUB_OUTPUT
else
echo "Unsupported event type!" >&2
exit 1
fi
#----------------------------------------------------------------------
# Checkout source
#
# We need to pass the token here -- the commit action below will not overwrite the token to push.
# This is necessary to bypass branch protection (which will disallow non-reviewed pushes otherwise)
#
# Make a distinction between Pull Request checkout and Push checkout. Push checkout
# works mostly automatically, but for PRs we must be very explicit to get the right
# branch and also support forks.
- uses: actions/checkout@v4
name: Checkout branch
with:
fetch-depth: 1
ref: ${{ steps.branch.outputs.branch }}
repository: ${{ steps.branch.outputs.repo }}
token: ${{ steps.secret.outputs.secret }}
#----------------------------------------------------------------------
# Actual build
- name: Set up Python 3.12
uses: actions/setup-python@v1
with:
python-version: 3.12
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
- name: Automatically update generated files
run: |
doit run _autopr
#----------------------------------------------------------------------
# Commit back
# For some reason, we must supply the token here again, even though
# we already supplied it during checkout.
- name: Commit changed files (with token)
uses: stefanzweifel/[email protected]
with:
commit_message: 🤖 Automatically update generated files
branch: ${{ steps.branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ steps.secret.outputs.secret }}