Skip to content

self-update

self-update #44

Workflow file for this run

# Check for updates against releases from github.com/actions/runner
name: self-update
on:
schedule:
- cron: '0 9 * * 1'
workflow_dispatch:
jobs:
get-runner-version:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.get-runner-version.outputs.result }}
steps:
- name: Get latest runner version
id: get-runner-version
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const latest = await github.rest.repos.getLatestRelease({
owner: 'actions',
repo: 'runner'
})
return latest.data.tag_name
- name: Log latest runner version
run: echo ${{ steps.get-runner-version.outputs.result }}
# Compare the latest runner version with the contents of VERSION
# If they don't match, update VERSION and create a pull request
update-runner-version:
needs: get-runner-version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Update runner version
id: update-runner-version
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
const path = require('path')
const latest = '${{ needs.get-runner-version.outputs.latest }}'.substring(1)
const versionPath = path.join('${{ github.workspace }}', 'VERSION')
const current = fs.readFileSync(versionPath, 'utf8')
if (current.trim() === latest.trim()) {
console.log('Runner is already up to date')
return
}
fs.writeFileSync(versionPath, latest)
const branch = `update-runner-${latest}`
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/heads/${branch}`,
sha: context.sha
})
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `[bot] Update runner to ${latest}`,
head: branch,
base: 'main',
body: 'This PR updates the runner to the latest version \n https://github.com/actions/runner/releases/latest'
})
console.log(`Created pull request #${context.payload.pull_request.number}`)