auto-go-upgrade #388
This file contains 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: auto-go-upgrade | |
concurrency: auto-go-upgrade | |
on: | |
workflow_dispatch: {} | |
schedule: | |
# 10pm daily | |
- cron: '0 22 * * *' | |
permissions: | |
contents: read | |
jobs: | |
go_upgrade_pr: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
SOURCE_BRANCH: "${{ github.ref_name }}" | |
SELF_UPGRADE_BRANCH: "go-version-bump-${{ github.ref_name }}" | |
steps: | |
- name: Fail if branch is not head of branch. | |
if: ${{ !startsWith(github.ref, 'refs/heads/') && env.SOURCE_BRANCH != '' && env.SELF_UPGRADE_BRANCH != '' }} | |
run: | | |
echo "This workflow should not be run on a non-branch-head." | |
exit 1 | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- run: | | |
git checkout -B "$SELF_UPGRADE_BRANCH" | |
- run: | | |
make patch-go-version | |
- id: is-up-to-date | |
shell: bash | |
run: | | |
git_status=$(git status -s) | |
is_up_to_date="true" | |
if [ -n "$git_status" ]; then | |
is_up_to_date="false" | |
echo "The following changes will be committed:" | |
echo "$git_status" | |
fi | |
echo "result=$is_up_to_date" >> "$GITHUB_OUTPUT" | |
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }} | |
run: | | |
git config --global user.name "cert-manager-bot" | |
git config --global user.email "[email protected]" | |
git add -A && git commit -m "BOT: run 'make upgrade-klone' and 'make generate'" --signoff | |
git push -f origin "$SELF_UPGRADE_BRANCH" | |
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }} | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
script: | | |
const { repo, owner } = context.repo; | |
const pulls = await github.rest.pulls.list({ | |
owner: owner, | |
repo: repo, | |
head: owner + ':' + process.env.SELF_UPGRADE_BRANCH, | |
base: process.env.SOURCE_BRANCH, | |
state: 'open', | |
}); | |
if (pulls.data.length < 1) { | |
const result = await github.rest.pulls.create({ | |
title: '[CI] Bump vendored Go version to latest patch version on ' + process.env.SOURCE_BRANCH, | |
owner: owner, | |
repo: repo, | |
head: process.env.SELF_UPGRADE_BRANCH, | |
base: process.env.SOURCE_BRANCH, | |
body: [ | |
'This PR is auto-generated to bump the vendored go version in the tools module to the latest available patch version', | |
].join('\n'), | |
}); | |
await github.rest.issues.addLabels({ | |
owner, | |
repo, | |
issue_number: result.data.number, | |
labels: ['skip-review'] | |
}); | |
} |