forked from pguyot/arm-runner-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
184 lines (184 loc) · 7.02 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
name: 'ARM runner'
description: 'Composite action to run commands within a qemu chrooted environment'
inputs:
base_image:
description: 'System base image'
required: true
default: 'raspios_lite:2021-05-07'
image_additional_mb:
description: 'Additional MB for image'
required: false
default: 0
cpu:
description: 'CPU architecture, arm1176 for arm6vl (Pi Zero)'
required: true
default: 'arm1176'
commands:
description: 'Commands to run in the image, executed with /bin/sh'
required: true
default: 'uname -a'
copy_artifact_path:
description: 'Paths of artifacts to copy from inside the image on completion'
required: false
copy_artifact_dest:
description: 'Where to copy artifacts on completion'
required: false
default: '.'
copy_repository_path:
description: 'Where to copy repository path before running commands'
required: false
default: ''
optimize_image:
description: 'Zero-fill unused filesystem blocks during final cleanup'
required: false
default: 'yes'
use_systemd_nspawn:
description: 'Use systemd-nspawn instead of chroot'
required: false
default: 'no'
shell:
description: 'Path to shell to run the commands with'
required: false
default: '/bin/sh'
shell_package:
description: 'The shell package to install, if different from shell'
required: false
default: ''
exit_on_fail:
description: 'Exit immediately if a command exits with a non-zero status'
required: false
default: 'yes'
debug:
description: 'Display commands as they are executed'
required: false
default: 'yes'
import_github_env:
description: 'Imports $GITHUB_ENV variables into the image environment'
required: false
default: 'no'
export_github_env:
description: 'Exports $GITHUB_ENV from the image environment to subsequent tasks'
required: false
default: 'no'
outputs:
image:
description: "Path to image"
value: ${{ steps.download_image.outputs.image }}
runs:
using: "composite"
steps:
- name: Install dependencies
run:
sudo apt-get update && sudo apt-get install -y qemu qemu-user-static binfmt-support parted wget dosfstools zip
shell: bash
- name: Install qemu wrapper
run: |
sudo mv /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static0
sudo gcc -static ${{ github.action_path }}/qemu-wrapper.c -DQEMU_CPU=${{ inputs.cpu }} -O3 -s -o /usr/bin/qemu-arm-static
sudo update-binfmts --disable qemu-arm
sudo update-binfmts --enable qemu-arm
shell: bash
- name: Download base image
run: |
bash ${{ github.action_path }}/download_image.sh ${{ inputs.base_image }}
shell: bash
id: download_image
- name: Mount and optionally resize image
run: |
sudo bash ${{ github.action_path }}/mount_image.sh ${{ steps.download_image.outputs.image }} ${{ inputs.image_additional_mb }}
shell: bash
id: mount_image
- name: Run commands
run: |
case "${{ inputs.debug }}" in
yes|true)
debug='x'
set -x
;;
no|false)
debug=''
;;
esac
repository_path=${{ inputs.copy_repository_path }}
if [ "${repository_path}x" = "x" ]; then
repository_name=`basename ${{ github.workspace }}`
repository_path=/${repository_name}
fi
case "${{ inputs.exit_on_fail }}" in
yes|true)
exit_on_fail='e'
;;
no|false)
exit_on_fail=''
;;
esac
shell=${{ inputs.shell }}
shell_package=${{ inputs.shell_package }}
[ -x ${{ steps.mount_image.outputs.mount }}/${shell} ] || \
shell_path=$(sudo chroot ${{ steps.mount_image.outputs.mount }} which ${shell}) || \
case ${shell} in
bash|sh)
:
;;
*)
sudo chroot ${{ steps.mount_image.outputs.mount }} sudo apt-get install -y ${shell_package:-${shell##*/}}
;;
esac
shell_path=${shell_path:-$(sudo chroot ${{ steps.mount_image.outputs.mount }} which ${shell})}
sudo mkdir -p $(dirname ${{ steps.mount_image.outputs.mount }}${repository_path})
sudo cp -Rp ${{ github.workspace }} ${{ steps.mount_image.outputs.mount }}${repository_path}
sudo touch ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
sudo chmod o+wx ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
echo "#!${shell_path}" > ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
echo "set -${debug}${exit_on_fail}" >> ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
case "${{ inputs.import_github_env }}" in
yes|true)
export | sed -e 's/^declare -x //g;s/^[^=]*$/\0=""/g;s/='\''\(.*\)'\''$/=\1/g' >> ${{ steps.mount_image.outputs.mount }}/tmp/environment.sh
echo '. ./tmp/environment.sh' >> ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
;;
esac
case "${{ inputs.export_github_env }}" in
yes|true)
echo "GITHUB_ENV=/tmp/github_env.sh" >> ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
;;
esac
echo "cd ${repository_path}" >> ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh
cat >> ${{ steps.mount_image.outputs.mount }}/tmp/commands.sh <<"ARM_RUNNER_INPUT_COMMANDS_EOF"
${{ inputs.commands }}
ARM_RUNNER_INPUT_COMMANDS_EOF
if [ "${{ inputs.use_systemd_nspawn }}x" != "x" -a "${{ inputs.use_systemd_nspawn }}x" != "nox" ]; then
sudo apt-get install -y systemd-container
sudo systemd-nspawn -D ${{ steps.mount_image.outputs.mount }} /tmp/commands.sh
else
sudo chroot ${{ steps.mount_image.outputs.mount }} /tmp/commands.sh
fi
rc=$?
[ -f ${{ steps.mount_image.outputs.mount }}/tmp/github_env.sh ] && \
cat ${{ steps.mount_image.outputs.mount }}/tmp/github_env.sh >> $GITHUB_ENV
exit $rc
shell: bash
- name: Copy artifacts within image
run: |
case "${{ inputs.debug }}" in
yes|true)
set -x
;;
esac
repository_path=${{ inputs.copy_repository_path }}
if [ "${repository_path}x" = "x" ]; then
repository_name=`basename ${{ github.workspace }}`
repository_path=/${repository_name}
fi
if [ "${{ inputs.copy_artifact_path }}x" != "x" ] && [ "${{ inputs.copy_artifact_dest }}x" != "x" ]; then
while read -d\; copy_artifact_path; do
[ -z "${copy_artifact_path}" ] || sudo cp -Rp ${{ steps.mount_image.outputs.mount }}${repository_path}/${copy_artifact_path} ${{ inputs.copy_artifact_dest }}
done <<< "${{ inputs.copy_artifact_path }};"
fi
shell: bash
- name: Cleanup image
run: |
sudo bash ${{ github.action_path }}/cleanup_image.sh ${{ steps.mount_image.outputs.loopdev }} ${{ steps.mount_image.outputs.mount }} "${{ inputs.optimize_image }}"
shell: bash
branding:
icon: 'cpu'
color: 'purple'