This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
Upgrade #172911
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: Upgrade | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: {} | |
jobs: | |
upgrade: | |
name: Upgrade | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Git Config | |
run: | | |
git config --global user.name github-actions[bot] | |
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com | |
gh auth login --with-token <<< ${{ github.token }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Upgrade | |
run: | | |
set -xeo pipefail | |
echo 'Checking for updates' | |
LATEST="$(curl -sSLf --retry 5 https://api.github.com/repos/actions/runner/releases/latest | jq -r '.tag_name | ltrimstr("v")')" | |
echo "Latest version is ${LATEST}" | |
if grep -qE "^RUNNER_VERSION \?= ${LATEST}$" ./runner/Makefile | |
then | |
echo 'Everything up-to-date' | |
elif git ls-remote --exit-code origin "feat/actions-runner-v${LATEST}" | |
then | |
echo 'Pending merge' | |
elif [ "$(git ls-remote origin master | cut -f 1)" != "$(git fetch -q origin master && git rev-parse origin/master)" ] | |
then | |
echo 'Master already changed' | |
else | |
echo 'Update available' | |
sed -Ei "s/^AGENT_VERSION \?= .*/AGENT_VERSION ?= ${LATEST}/" ./operator/Makefile | |
sed -Ei "s/^RUNNER_VERSION \?= .*/RUNNER_VERSION ?= ${LATEST}/" ./runner/Makefile | |
git add -A | |
echo 'Creating branch remotely' | |
git push -fu "$(git remote show)" "$(git branch --show-current):feat/actions-runner-v${LATEST}" | |
echo 'Sending signed commit' | |
cat <<-EOF | gh api graphql -F query=@- | |
mutation { | |
createCommitOnBranch( | |
input: { | |
branch: { | |
repositoryNameWithOwner: "${GITHUB_REPOSITORY}", | |
branchName: "feat/actions-runner-v${LATEST}", | |
}, | |
fileChanges: { | |
additions: [$( | |
for F in $(git diff --cached --name-only) | |
do | |
printf '{path:"%s",contents:"%s"},' "${F}" "$(base64 ${F} | sed -e ':a' -e '$!N' -e '$!ba' -e 's/\n//g')" | |
done | |
)], | |
}, | |
message: { | |
headline: "feat: actions/runner#v${LATEST}", | |
}, | |
expectedHeadOid: "$(git rev-parse HEAD)", | |
}, | |
) { | |
commit { | |
oid | |
} | |
} | |
} | |
EOF | |
echo 'Creating PR' | |
gh pr create -t "Actions Runner v${LATEST}" -H "feat/actions-runner-v${LATEST}" -b "https://github.com/actions/runner/releases/tag/v${LATEST}" | |
fi |