Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
ci: automatically bump the version number in rust-lang/gha-self-hosted
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Feb 24, 2023
1 parent 251a3ef commit bca51f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 48 deletions.
53 changes: 5 additions & 48 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -479,51 +479,8 @@ jobs:
asset_name: actions-runner-linux-arm64-${{ steps.releaseNote.outputs.version }}-trimmedpackages.json
asset_content_type: application/octet-stream

publish-image:
needs: release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/actions-runner
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Compute image version
id: image
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const runnerVersion = fs.readFileSync('${{ github.workspace }}/releaseVersion', 'utf8').replace(/\n$/g, '')
console.log(`Using runner version ${runnerVersion}`)
core.setOutput('version', runnerVersion);
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v3
with:
context: ./images
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.image.outputs.version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
build-args: |
RUNNER_VERSION=${{ steps.image.outputs.version }}
push: true
labels: |
org.opencontainers.image.source=${{github.server_url}}/${{github.repository}}
org.opencontainers.image.description=https://github.com/actions/runner/releases/tag/v${{ steps.image.outputs.version }}
org.opencontainers.image.licenses=MIT
# Bump the version number in rust-lang/gha-self-hosted
- name: Bump the version number in rust-lang/gha-self-hosted
run: ./rust-bump-gha-self-hosted.sh
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
47 changes: 47 additions & 0 deletions rust-bump-gha-self-hosted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# This script updates the version number in rust-lang/gha-self-hosted after a
# release is made, removing the need for someone on the infrastructure team to
# bump the version number manually.
#
# It's executed by .github/workflows/release.yml

set -euo pipefail
IFS=$'\n\t'

repository_url="[email protected]:rust-lang/gha-self-hosted.git"
version_file="images/ubuntu/files/gha-runner-version"

git_name="rust-lang/gha-runner"
git_email="[email protected]"

# Load the deploy key on a temporary file.
key="$(mktemp)"
trap "rm ${key}" EXIT
echo "${DEPLOY_KEY}" > "${key}"

# Use the SSH key stored earlier for all git operations, and ignore ssh-agent.
export GIT_SSH_COMMAND="ssh -i ${key}"
unset SSH_AUTH_SOCK

# Clone the repository
clone="$(mktemp -d)"
trap "rm -rf ${clone}" EXIT
git clone "${repository_url}" "${clone}"

# Update the version file
version="$(cat releaseVersion)"
if [[ "$(cat "${clone}/${version_file}")" = "${version}" ]]; then
echo "nothing to update, exiting"
else
echo "${version}" > "${clone}/${version_file}"
(
cd "${clone}"
git add .
git \
-c commit.gpgsign=false \
-c "user.name=${git_name}" \
-c "user.email=${git_email}" \
commit -m "Bump the GitHub Actions runner to version ${version}"
git push
)
fi

0 comments on commit bca51f2

Please sign in to comment.