From 19ccfde91c2fc8ad3bd20320dac90ad73464aee3 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Wed, 17 Jan 2024 17:56:53 +0400 Subject: [PATCH] Always install the latest GitHub Actions Runner (#117) --- scripts/install-actions-runner.sh | 20 ++++++++++++++++++++ templates/base.pkr.hcl | 19 ++++++------------- templates/xcode.pkr.hcl | 21 +++++---------------- variables.pkrvars.hcl | 1 - 4 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 scripts/install-actions-runner.sh diff --git a/scripts/install-actions-runner.sh b/scripts/install-actions-runner.sh new file mode 100644 index 0000000..e3e1c91 --- /dev/null +++ b/scripts/install-actions-runner.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Set shell options to enable fail-fast behavior +# +# * -e: fail the script when an error occurs or command fails +# * -u: fail the script when attempting to reference unset parameters +# * -o pipefail: by default an exit status of a pipeline is that of its +# last command, this fails the pipe early if an error in +# any of its commands occurs +# +set -euo pipefail + +source ~/.zprofile +brew install jq + +DOWNLOAD_URL=$(curl -sS 'https://api.github.com/repos/actions/runner/releases/latest' | jq --raw-output '.assets[] | select(.name | test("actions-runner-osx-arm64-[0-9.]+.tar.gz")) | .browser_download_url') + +rm -rf actions-runner && mkdir actions-runner && cd actions-runner + +wget -O - "${DOWNLOAD_URL}" | tar xz diff --git a/templates/base.pkr.hcl b/templates/base.pkr.hcl index a529356..95f2b61 100644 --- a/templates/base.pkr.hcl +++ b/templates/base.pkr.hcl @@ -11,10 +11,6 @@ variable "macos_version" { type = string } -variable "gha_version" { - type = string -} - source "tart-cli" "tart" { vm_base_name = "ghcr.io/cirruslabs/macos-${var.macos_version}-vanilla:latest" vm_name = "${var.macos_version}-base" @@ -53,15 +49,6 @@ build { ] } - provisioner "shell" { - inline = [ - "cd $HOME", - "mkdir actions-runner && cd actions-runner", - "curl -O -L https://github.com/actions/runner/releases/download/v${var.gha_version}/actions-runner-osx-arm64-${var.gha_version}.tar.gz", - "tar xzf ./actions-runner-osx-arm64-${var.gha_version}.tar.gz", - "rm actions-runner-osx-arm64-${var.gha_version}.tar.gz", - ] - } provisioner "shell" { inline = [ "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"", @@ -76,6 +63,12 @@ build { "git lfs install", ] } + + // Install the GitHub Actions runner + provisioner "shell" { + script = "scripts/install-actions-runner.sh" + } + provisioner "shell" { inline = [ "source ~/.zprofile", diff --git a/templates/xcode.pkr.hcl b/templates/xcode.pkr.hcl index 9d0b2ca..04c1e48 100644 --- a/templates/xcode.pkr.hcl +++ b/templates/xcode.pkr.hcl @@ -15,10 +15,6 @@ variable "xcode_version" { type = string } -variable "gha_version" { - type = string -} - variable "android_sdk_tools_version" { type = string default = "9477386" # https://developer.android.com/studio/#command-tools @@ -39,18 +35,6 @@ source "tart-cli" "tart" { build { sources = ["source.tart-cli.tart"] - // re-install the actions runner - provisioner "shell" { - inline = [ - "cd $HOME", - "rm -rf actions-runner", - "mkdir actions-runner && cd actions-runner", - "curl -O -L https://github.com/actions/runner/releases/download/v${var.gha_version}/actions-runner-osx-arm64-${var.gha_version}.tar.gz", - "tar xzf ./actions-runner-osx-arm64-${var.gha_version}.tar.gz", - "rm actions-runner-osx-arm64-${var.gha_version}.tar.gz", - ] - } - provisioner "shell" { inline = [ "source ~/.zprofile", @@ -62,6 +46,11 @@ build { ] } + // Re-install the GitHub Actions runner + provisioner "shell" { + script = "scripts/install-actions-runner.sh" + } + provisioner "shell" { inline = [ "source ~/.zprofile", diff --git a/variables.pkrvars.hcl b/variables.pkrvars.hcl index 85b7fc9..19cce86 100644 --- a/variables.pkrvars.hcl +++ b/variables.pkrvars.hcl @@ -1,3 +1,2 @@ macos_version = "sonoma" -gha_version = "2.312.0" xcode_version = "15.2"