-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
233 lines (214 loc) · 7.94 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
---
name: Start Vagrant Box
description: Allow running command-line programs via bash shell of VMs provisioned with Vagrant using the run keyword.
inputs:
box:
default: generic/arch
description: Vagrant Box
type: string
boot_timeout:
default: 1800
description: VM Boot Timeout
type: string
connect_timeout:
default: 30
description: VM SSH Connect Timeout
type: string
cpus:
default: 2
description: VM CPUs
options:
- 2
- 4
- 8
type: choice
memory:
default: 2048
description: VM Memory
options:
- 1024
- 2048
- 4096
- 8192
type: choice
pre_package_commands:
default: >-
find ${{ github.workspace }} -mindepth 1 -delete;
find ${{ runner.temp }} -mindepth 1 -delete;
description: Command(s) to run before packaging Vagrant Box (double quotation marks are not allowed)
type: string
provider:
description: Vagrant provider to use, defaults to libvirt on Linux and virtualbox on macOS
options:
- libvirt
- virtualbox
type: string
provision_commands:
default: >-
echo 'AcceptEnv *' >> /etc/ssh/sshd_config;
mkdir -p ${{ github.workspace }};
chown vagrant:vagrant ${{ github.workspace }};
mkdir -p ${{ runner.temp }};
chown vagrant:vagrant ${{ runner.temp }};
description: Command(s) to run for provisioning (double quotation marks are not allowed)
type: string
save_box_to_cache:
description: Save Vagrant Box to GitHub Actions Cache
type: boolean
use_cached_box:
description: Use Vagrant Box from GitHub Actions Cache
type: boolean
vagrant_box_descriptor:
default: /tmp/packaged.box
description: Vagrant Box Descriptor <name, url, or path>
type: string
vagrant_ssh_username:
default: vagrant
description: SSH Username for `vagrant ssh`
type: string
runs:
using: composite
steps:
- name: Set `PROVIDER` (Linux)
run: |
echo "PROVIDER=${{ inputs.provider || 'libvirt' }}" >> ${GITHUB_ENV}
shell: bash
if: runner.os == 'Linux'
- name: Set `PROVIDER` (macOS)
run: |
echo "PROVIDER=${{ inputs.provider || 'virtualbox' }}" >> ${GITHUB_ENV}
shell: bash
if: runner.os == 'macOS'
- name: Install/Upgrade Vagrant (Linux)
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt-get --yes install \
vagrant
shell: bash
if: runner.os == 'Linux'
- name: Install/Configure Provider Dependencies (Linux) (libvirt)
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get --yes install \
libvirt-daemon-system \
qemu
sudo setfacl -m user:$USER:rw /var/run/libvirt/libvirt-sock
shell: bash
if: runner.os == 'Linux' && env.PROVIDER == 'libvirt'
- name: Install/Configure Provider Dependencies (Linux) (virtualbox)
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get --yes install \
virtualbox
shell: bash
if: runner.os == 'Linux' && env.PROVIDER == 'virtualbox'
- name: Install/Upgrade Vagrant (macOS)
run: |
brew install --cask --force --quiet \
vagrant
shell: bash
if: runner.os == 'macOS'
- name: Install/Configure Provider Dependencies (macOS) (libvirt)
run: |
brew install --force --quiet \
libvirt \
iproute2mac \
qemu
brew services start libvirt
echo "LIBVIRT_DEFAULT_URI=qemu:///session?socket=${HOME}/.cache/libvirt/libvirt-sock" >> ${GITHUB_ENV}
shell: bash
if: runner.os == 'macOS' && env.PROVIDER == 'libvirt'
- name: Install/Configure Provider Dependencies (macOS) (virtualbox)
run: |
brew install --cask --force --quiet \
virtualbox
# Fix for Vagrant 2.4.1 with VirtualBox 7.1
sudo sed -i.bak 's/"7.0" => Version_7_0,/"7.0" => Version_7_0,"7.1" => Version_7_0,/g' $(find /opt/vagrant -name meta.rb | grep virtualbox)
shell: bash
if: runner.os == 'macOS' && env.PROVIDER == 'virtualbox'
- name: Cache Vagrant Box
if: inputs.save_box_to_cache
uses: actions/cache@v4
with:
path: ${{ inputs.vagrant_box_descriptor }}
key: ${{ inputs.box }}-${{ runner.os }}.box
- name: Add Vagrant Box
if: inputs.use_cached_box
run: |
if [ -f ${{ inputs.vagrant_box_descriptor }} ]; then
vagrant box add --name ${{ inputs.box }} ${{ inputs.vagrant_box_descriptor }}
fi
shell: bash
- name: Install Vagrant libvirt Plugin (libvirt)
run: |
vagrant plugin install vagrant-libvirt
shell: bash
if: env.PROVIDER == 'libvirt'
- name: Generate Vagrantfile
run: |
cat > Vagrantfile <<EOF
Vagrant.configure("2") do |config|
config.ssh.compression = false
config.ssh.connect_timeout = ${{ inputs.connect_timeout }}
config.ssh.forward_env = ["*"]
config.ssh.shell = "bash"
config.ssh.username = "${{ inputs.vagrant_ssh_username }}"
config.vm.boot_timeout = ${{ inputs.boot_timeout }}
config.vm.box = "${{ inputs.box }}"
config.vm.box_check_update = false
config.vm.provider :${{ env.PROVIDER }} do |v|
v.cpus = ${{ inputs.cpus }}
${{ (runner.os == 'Linux' && env.PROVIDER == 'libvirt') && 'v.driver = "kvm"' || '' }}
v.memory = ${{ inputs.memory }}
end
config.vm.provision "shell", inline: "${{ inputs.provision_commands }}"
config.vm.synced_folder ".", "/vagrant", disabled: true
end
EOF
shell: bash
- name: Show Vagrant Status
run: |
vagrant status
shell: bash
- name: Start Vagrant Environment
run: |
vagrant up --provider ${{ env.PROVIDER }}
shell: bash
- name: Save OpenSSH configuration to ~/.ssh/config
run: |
mkdir -p ~/.ssh
vagrant ssh-config --host vagrantbox >> ~/.ssh/config
shell: bash
- name: Generate /bin/bash override script
run: |
echo "#!/bin/bash" | sudo tee /usr/local/bin/bash
echo "SCRIPT=\$(mktemp)" | sudo tee -a /usr/local/bin/bash
echo "echo \"#!/usr/bin/env bash\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
echo "echo \"cd \${PWD}\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
echo "echo \"set -euxo pipefail\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
echo "echo \"bash \$@\" >> \${SCRIPT}" | sudo tee -a /usr/local/bin/bash
echo "mv \${SCRIPT} ${{ runner.temp }}/command.sh" | sudo tee -a /usr/local/bin/bash
echo "chmod a+x ${{ runner.temp }}/command.sh" | sudo tee -a /usr/local/bin/bash
echo "rsync --archive --delete ${{ github.workspace }}/ vagrantbox:${{ github.workspace }}/" | sudo tee -a /usr/local/bin/bash
echo "rsync --archive --delete ${{ runner.temp }}/ vagrantbox:${{ runner.temp }}/" | sudo tee -a /usr/local/bin/bash
echo "vagrant ssh --command \"${{ runner.temp }}/command.sh\"" | sudo tee -a /usr/local/bin/bash
echo "EXIT_STATUS=\$?" | sudo tee -a /usr/local/bin/bash
echo "rsync --archive --delete vagrantbox:${{ github.workspace }}/ ${{ github.workspace }}/" | sudo tee -a /usr/local/bin/bash
echo "rsync --archive --delete vagrantbox:${{ runner.temp }}/ ${{ runner.temp }}/" | sudo tee -a /usr/local/bin/bash
echo "exit \${EXIT_STATUS}" | sudo tee -a /usr/local/bin/bash
sudo chmod +x /usr/local/bin/bash
shell: bash
- name: Package Vagrant Box
if: inputs.save_box_to_cache
uses: gacts/run-and-post-run@v1
with:
post: >-
if [ ! -f ${{ inputs.vagrant_box_descriptor }} ]; then
vagrant ssh --command "${{ inputs.pre_package_commands }}";
vagrant package --output ${{ inputs.vagrant_box_descriptor }};
fi
post-shell: /bin/bash