Skip to content

Commit a87e3cd

Browse files
authored
Fix ubuntu-latest (Ubuntu 24.04) support (#3)
### Two issues prevented the existing action from working - `Ubuntu 24.04` no longer provides `vagrant` package - Due to the adoption of the Business Source License (BSL) by Vagrant - `vagrant` package from `Hashicorp` installs to `/opt` with a `bash` wrapper in `/usr/bin/vagrant` - This was breaking the `bash` override method used by this action Also added tests for `ubuntu-22.04`
1 parent 025a5d7 commit a87e3cd

2 files changed

Lines changed: 99 additions & 21 deletions

File tree

.github/workflows/tests.yml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,72 @@ on:
55
push:
66

77
jobs:
8-
Linux:
9-
name: Linux (${{ matrix.box }}) (${{ matrix.provider }})
8+
Ubuntu2204:
9+
name: Ubuntu 22.04 (${{ matrix.box }}) (${{ matrix.provider }})
10+
runs-on: ubuntu-22.04
11+
strategy:
12+
matrix:
13+
box:
14+
- generic/arch
15+
provider:
16+
- libvirt
17+
- virtualbox
18+
fail-fast: false
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set `CPUS`
24+
run: |
25+
echo "CPUS=$(nproc)" >> ${GITHUB_ENV}
26+
27+
- name: Provision VM
28+
uses: ./
29+
with:
30+
box: ${{ matrix.box }}
31+
cpus: ${{ env.CPUS }}
32+
provider: ${{ matrix.provider }}
33+
34+
- name: Run Test (/etc/os-release) (VM)
35+
run: |
36+
source /etc/os-release
37+
if [ "${NAME}" = "Arch Linux" ]; then
38+
echo "Arch Linux detected."
39+
else
40+
echo "Arch Linux not detected."
41+
exit 1
42+
fi
43+
shell: bash --noprofile --norc -euo pipefail {0}
44+
45+
- name: Run Test (/etc/os-release) (Host)
46+
run: |
47+
source /etc/os-release
48+
if [ "${NAME}" = "Arch Linux" ]; then
49+
echo "Arch Linux detected."
50+
exit 1
51+
else
52+
echo "Arch Linux not detected."
53+
fi
54+
shell: /bin/bash --noprofile --norc -euo pipefail {0}
55+
56+
- name: Prepare Test (working-directory) (VM)
57+
run: |
58+
mkdir new_working_directory
59+
shell: bash --noprofile --norc -euo pipefail {0}
60+
61+
- name: Run Test (working-directory) (VM)
62+
run: |
63+
if [ "$(basename ${PWD})" = "new_working_directory" ]; then
64+
echo "Expected working directory detected."
65+
else
66+
echo "Expected working directory not detected."
67+
exit 1
68+
fi
69+
shell: bash --noprofile --norc -euo pipefail {0}
70+
working-directory: new_working_directory
71+
72+
UbuntuLatest:
73+
name: Ubuntu Latest (${{ matrix.box }}) (${{ matrix.provider }})
1074
runs-on: ubuntu-latest
1175
strategy:
1276
matrix:

action.yml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ inputs:
4343
options:
4444
- libvirt
4545
- virtualbox
46-
type: string
46+
type: choice
4747
provision_commands:
4848
default: >-
4949
echo 'AcceptEnv *' >> /etc/ssh/sshd_config;
@@ -88,9 +88,18 @@ runs:
8888
env:
8989
DEBIAN_FRONTEND: noninteractive
9090
run: |
91+
if [ "${ImageOS}" = "ubuntu24" ]; then
92+
# Ubuntu 24.04 no longer provides Vagrant, install from Hashicorp
93+
sudo bash -c 'curl --silent https://apt.releases.hashicorp.com/gpg | gpg --dearmor > /usr/share/keyrings/hashicorp-archive-keyring.gpg'
94+
sudo bash -c 'echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com '$(lsb_release -cs)' main" > /etc/apt/sources.list.d/hashicorp.list'
95+
fi
9196
sudo apt-get update
9297
sudo apt-get --yes install \
9398
vagrant
99+
if [ "${ImageOS}" = "ubuntu24" ]; then
100+
# Vagrant from Hashicorp installs a bash wrapper
101+
sudo ln --force --symbolic /opt/vagrant/bin/vagrant /usr/bin/vagrant
102+
fi
94103
shell: bash
95104
if: runner.os == 'Linux'
96105

@@ -100,7 +109,8 @@ runs:
100109
run: |
101110
sudo apt-get --yes install \
102111
libvirt-daemon-system \
103-
qemu
112+
libvirt-dev \
113+
qemu-system
104114
sudo setfacl -m user:$USER:rw /var/run/libvirt/libvirt-sock
105115
shell: bash
106116
if: runner.os == 'Linux' && env.PROVIDER == 'libvirt'
@@ -203,21 +213,25 @@ runs:
203213

204214
- name: Generate /bin/bash override script
205215
run: |
206-
echo "#!/bin/bash" | sudo tee /usr/local/bin/bash
207-
echo "SCRIPT=\$(mktemp)" | sudo tee -a /usr/local/bin/bash
208-
echo "echo \"#!/usr/bin/env bash\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
209-
echo "echo \"cd \${PWD}\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
210-
echo "echo \"set -euxo pipefail\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
211-
echo "echo \"bash \$@\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
212-
echo "mv \${SCRIPT} ${{ runner.temp }}/command.sh" | sudo tee -a /usr/local/bin/bash
213-
echo "chmod a+x ${{ runner.temp }}/command.sh" | sudo tee -a /usr/local/bin/bash
214-
echo "rsync --archive --delete ${{ github.workspace }}/ vagrantbox:${{ github.workspace }}/" | sudo tee -a /usr/local/bin/bash
215-
echo "rsync --archive --delete ${{ runner.temp }}/ vagrantbox:${{ runner.temp }}/" | sudo tee -a /usr/local/bin/bash
216-
echo "vagrant ssh --command \"${{ runner.temp }}/command.sh\"" | sudo tee -a /usr/local/bin/bash
217-
echo "EXIT_STATUS=\$?" | sudo tee -a /usr/local/bin/bash
218-
echo "rsync --archive --delete vagrantbox:${{ github.workspace }}/ ${{ github.workspace }}/" | sudo tee -a /usr/local/bin/bash
219-
echo "rsync --archive --delete vagrantbox:${{ runner.temp }}/ ${{ runner.temp }}/" | sudo tee -a /usr/local/bin/bash
220-
echo "exit \${EXIT_STATUS}" | sudo tee -a /usr/local/bin/bash
216+
cat > bash <<EOF
217+
#!/bin/bash
218+
set -euxo pipefail
219+
SCRIPT=\$(mktemp)
220+
echo "#!/usr/bin/env bash" >> \${SCRIPT}
221+
echo "cd \${PWD}" >> \${SCRIPT}
222+
echo "set -euxo pipefail" >> \${SCRIPT}
223+
echo "bash \$@" >> \${SCRIPT}
224+
mv \${SCRIPT} ${{ runner.temp }}/command.sh
225+
chmod a+x ${{ runner.temp }}/command.sh
226+
rsync --archive --delete ${{ github.workspace }}/ vagrantbox:${{ github.workspace }}/
227+
rsync --archive --delete ${{ runner.temp }}/ vagrantbox:${{ runner.temp }}/
228+
vagrant ssh --command "${{ runner.temp }}/command.sh"
229+
EXIT_STATUS=\$?
230+
rsync --archive --delete vagrantbox:${{ github.workspace }}/ ${{ github.workspace }}/
231+
rsync --archive --delete vagrantbox:${{ runner.temp }}/ ${{ runner.temp }}/
232+
exit \${EXIT_STATUS}
233+
EOF
234+
sudo mv bash /usr/local/bin/bash
221235
sudo chmod +x /usr/local/bin/bash
222236
shell: bash
223237

@@ -227,7 +241,7 @@ runs:
227241
with:
228242
post: >-
229243
if [ ! -f ${{ inputs.vagrant_box_descriptor }} ]; then
230-
vagrant ssh --command "${{ inputs.pre_package_commands }}";
231-
vagrant package --output ${{ inputs.vagrant_box_descriptor }};
244+
vagrant ssh --command "${{ inputs.pre_package_commands }}";
245+
vagrant package --output ${{ inputs.vagrant_box_descriptor }};
232246
fi
233247
post-shell: /bin/bash

0 commit comments

Comments
 (0)