-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
53 lines (48 loc) · 2.26 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: emulate
description: Emulate unsupported operating systems using QEMU.
inputs:
operating-system:
description: The operating-system specifier.
required: true
runs:
using: composite
steps:
- name: Boot guest ${{ inputs.operating-system }}.
shell: bash
working-directory: ${{ runner.temp }}
env:
EMULATE_OPERATING_SYSTEM: ${{ inputs.operating-system }}
run: |
case "$EMULATE_OPERATING_SYSTEM" in
openbsd-latest) EMULATE_OPERATING_SYSTEM=openbsd-7.3 ;;
freebsd-latest) EMULATE_OPERATING_SYSTEM=freebsd-13.0 ;;
netbsd-latest) EMULATE_OPERATING_SYSTEM=netbsd-9.2 ;;
esac
# >VAGRANT_HOME can be set to change the directory where Vagrant
# >stores global state. By default, this is set to ~/.vagrant.d.
#
# Because ~/.vagrant.d is not readable/writable on the macos-12.15
# runner, we need to create a new readable/writeable VAGRANT_HOME.
export VAGRANT_HOME="$(mktemp -d)"
# >VAGRANT_CWD can be set to change the working directory of Vagrant.
# >By default, Vagrant uses the current directory you are in. The working
# >directory is important because it is where Vagrant looks for the Vagrantfile.
#
# While we can `cd` into the proper Vagrant directory (and did once),
# setting the VAGRANT_CWD environment variable is cleaner.
export VAGRANT_CWD="$GITHUB_ACTION_PATH/$EMULATE_OPERATING_SYSTEM"
# Generate a Bash script that will hijack/interrupt the original
# Actions-user-specified run step and proxy the contents of that
# run step to the guest VM.
EMULATE_BASH_HIJACKER="$(mktemp)"
cat > "$EMULATE_BASH_HIJACKER" << EOF
# Determine the path to the bash script containing the body of "this" run step.
RUN_SCRIPT="\$(ps -p \$$ -o args= | xargs -n 1 | tail -n 1)"
# Proxy the body of the run step to the guest virtual machine.
# It's important that this is `exec`uted, because this is what
# causes this BASH_ENV script to "hijack" the original script's
# execution.
VAGRANT_HOME="$VAGRANT_HOME" VAGRANT_CWD="$VAGRANT_CWD" exec vagrant ssh -c 'exec \$SHELL -se' < "\$RUN_SCRIPT"
EOF
echo "BASH_ENV=$EMULATE_BASH_HIJACKER" >> "$GITHUB_ENV"
vagrant up