Automated trunk upgrade #293
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Automated trunk upgrade | |
| on: | |
| issue_comment: | |
| types: | |
| - created | |
| push: | |
| branches: | |
| - updates | |
| paths: | |
| - .trunk/** | |
| schedule: | |
| - cron: 27 5 * * * | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| trunk-upgrade: | |
| name: trunk upgrade | |
| runs-on: ubuntu-24.04 | |
| environment: automated | |
| if: github.event_name != 'issue_comment' || (startsWith(github.event.issue.title, 'Automated trunk upgrade') && contains(github.event.comment.body, | |
| '/rerun')) | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GH_TOKEN }} | |
| ref: updates | |
| - name: Set up Trunk | |
| run: curl https://get.trunk.io -fsSL | bash -s -- -y | |
| - name: Trunk upgrade | |
| run: | | |
| trunk upgrade --yes-to-all --no-progress --ci --color | tee .github/update.log | |
| sed -e '/Downloading Trunk/,/Unpacking Trunk... done/d' -e 's/\x1b\[[0-9;]*m//g' -e 's/^\( \)\{0,1\} /\1- /' .github/update.log > .github/pr_body.log | |
| perl -0777 -ne 'print join ", ", map {s/://gr} map {s/^- //r} grep {/^(-|cli) /} split "\n"' .github/pr_body.log > .github/pr_title.log | |
| - name: Check for changes | |
| run: | | |
| if git diff --exit-code; then | |
| echo "changes=false" >> $GITHUB_ENV | |
| else | |
| echo "changes=true" >> $GITHUB_ENV | |
| fi | |
| - name: Trunk Check | |
| if: env.changes == 'true' | |
| uses: trunk-io/trunk-action@v1 | |
| with: | |
| check-mode: all | |
| continue-on-error: true | |
| - name: Commit and push to branch | |
| if: env.changes == 'true' | |
| uses: EndBug/add-and-commit@v9 | |
| with: | |
| github_token: ${{ secrets.GH_TOKEN }} | |
| default_author: github_actions | |
| message: Automated trunk upgrade [skip ci] | |
| new_branch: automated/trunk-upgrade | |
| fetch: false | |
| push: origin automated/trunk-upgrade --set-upstream --force | |
| - name: Create pull request | |
| if: env.changes == 'true' | |
| run: |- | |
| if [[ $(gh pr view automated/trunk-upgrade --json state --jq .state || true) != "OPEN" ]]; then | |
| gh pr create \ | |
| --base updates \ | |
| --head automated/trunk-upgrade \ | |
| --title "Automated trunk upgrade $(cat .github/pr_title.log) [skip ci]" \ | |
| --body-file .github/pr_body.log \ | |
| --label automated | |
| else | |
| gh pr edit automated/trunk-upgrade \ | |
| --title "Automated trunk upgrade $(cat .github/pr_title.log) [skip ci]" \ | |
| --body-file .github/pr_body.log | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| - name: Close pull request | |
| if: env.changes == 'false' | |
| run: gh pr list --head automated/trunk-upgrade --json number --jq '.[].number' | xargs -rn1 gh pr close --delete-branch | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} |