Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a workflow for updating tools (and OS) on custom runners #1302

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
81318d1
Update workflow
jonsimantov May 2, 2023
48866d5
Use JSON
jonsimantov May 2, 2023
b68b545
Hard code hostname as a test
jonsimantov May 2, 2023
1cc5f29
Fix if statement
jonsimantov May 2, 2023
45d1296
Fix inputs.
jonsimantov May 2, 2023
c2508ae
Fix matrix.
jonsimantov May 2, 2023
5ffbe24
Update matrix again
jonsimantov May 2, 2023
4781859
Matrix JSON list
jonsimantov May 2, 2023
90d7c59
Fix input
jonsimantov May 2, 2023
173b4b5
Fix output
jonsimantov May 2, 2023
a4a717d
Fix bash script.
jonsimantov May 2, 2023
7b48979
Error checking.
jonsimantov May 2, 2023
aee8099
Fix logging.
jonsimantov May 2, 2023
355a0b7
Print OS updates correctly.
jonsimantov May 2, 2023
6054439
msg
jonsimantov May 2, 2023
ebd526a
Always print OS update output.
jonsimantov May 2, 2023
f501f32
Output normally as well.
jonsimantov May 2, 2023
f3b40fe
Fix output.
jonsimantov May 2, 2023
0c5ecea
Fix update
jonsimantov May 2, 2023
f26c982
Enable sudo for update script.
jonsimantov May 2, 2023
bedbce7
Fix trap
jonsimantov May 2, 2023
c95f0ac
Fix sudo.
jonsimantov May 2, 2023
06193e5
Fix ifs, and sudo
jonsimantov May 2, 2023
545d0ad
Update sudo script for softwareupdate
jonsimantov May 2, 2023
fe2b0df
Download updates first.
jonsimantov May 2, 2023
7fc6a23
Typo
jonsimantov May 2, 2023
eda103e
Separate out download step.
jonsimantov May 2, 2023
3deedf0
Separate out download step
jonsimantov May 2, 2023
a58c0af
Simplify installation.
jonsimantov May 2, 2023
0fe9e65
Actually do the installation now.
jonsimantov May 2, 2023
ba0b382
Run the update in the background so the runner job can finish.
jonsimantov May 2, 2023
19f6735
Don't prompt for plaintext password.
jonsimantov May 2, 2023
43c295a
Don't run in background after all.
jonsimantov May 2, 2023
cc5bceb
Print update better.
jonsimantov May 2, 2023
5b669da
Fix script.
jonsimantov May 2, 2023
324e171
Fix log.
jonsimantov May 2, 2023
aac9b10
Merge branch 'main' into allow-updating-custom-runners
jonsimantov May 2, 2023
708338d
Merge branch 'main' into allow-updating-custom-runners
jonsimantov May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions .github/workflows/update-custom-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
runner_list:
description: 'Runner hostname to update (comma-separated)'
description: 'Runner hostnames (comma-separated)'
default: 'fplmac1,fplmac2'
required: true
update_tools:
Expand All @@ -20,33 +20,78 @@ env:
GITHUB_TOKEN: ${{ github.token }}

jobs:
prepare:
name: prepare
runs-on: ubuntu-20.04
if: github.event.inputs.runner_list != ''
outputs:
runner_hostnames: ${{ steps.prepare_inputs.outputs.runner_hostnames }}
steps:
- name: Prepare inputs
id: prepare_inputs
shell: bash
run: |
csv='${{github.event.inputs.runner_list}}'
json="['$(echo ${csv} | sed s/,/\',\'/g)']"
echo "runner_hostnames=${json}"
echo "runner_hostnames=${json}" >> $GITHUB_OUTPUT

update_custom_runners:
name: update-custom-runner-${{ matrix.runner_hostname }}
needs: [ prepare ]
runs-on: [self-hosted, '${{ matrix.runner_hostname }}' ]
if: ${{ github.event.input.runner_list }}
if: github.event.inputs.runner_list != ''

strategy:
matrix:
runner_hostname: ${{ github.event.input.runner_list }}
runner_hostname: ${{ fromJson(needs.prepare.outputs.runner_hostnames) }}

steps:
- name: Update tools
if: ${{ github.event.inputs.update_tools }}
if: github.event.inputs.update_tools == 1
shell: bash
run: |
echo "npm install -g firebase-tools"
set -ex
npm install -g firebase-tools

- name: Check for OS updates
shell: bash
run: |
if softwareupdate -l -r | grep -q 'No new software available'
then
echo "::warning ::No OS updates available."
else
echo "softwareupdate -l -r | tr '\n' '|' | sed 's/|/%0A/g' | sed "

- name: Update OS
if: ${{ github.event.inputs.update_os }}
# If there is new software, print the list.
set +e
softwareupdate -l -r 2>&1 | grep -q 'No new software' && exit
softwareupdate -l -r | tr '\n' '|' | sed 's/|/%0A/g' | sed 's/^/::warning ::/'

- name: Install OS updates
if: github.event.inputs.update_os == 1
shell: bash
run: |
echo "softwareupdate -i -r -f"
# Ignore errors
set +e

# Pause a minute before installing updates.
sleep 60

# Need to use sudo to run the update with reboot. Set up a temporary
# "askpass" script to provide sudo with the password.
tmpfile="$(mktemp)"
trap "rm -f \"${tmpfile}\"" EXIT HUP QUIT PIPE INT

# Generate a script for sudo to use, which immediately deletes itself.
cat > "${tmpfile}" <<EOF
#!/usr/bin/env bash
rm -f "${tmpfile}"
EOF

chmod u+x "${tmpfile}"

# Continue without variable substitution, to output the password:
cat >> "${tmpfile}" <<'EOF'
cat <<'END_OF_FILE'
${{secrets.CUSTOM_RUNNER_PW}}
END_OF_FILE
EOF

# sudo -A -k will force run the generated script, which will then
# immediately delete itself.
SUDO_ASKPASS="${tmpfile}" sudo -A -k softwareupdate -i -r -R --user root --stdinpass '' 2>&1