This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
127 lines (127 loc) · 5.13 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
name: Kernel Builds VM
description: Bootstraps a Lima instance with the selected Linux kernel version
for building and testing kernel modules.
author: Antoine Cotten (@antoineco)
branding:
icon: terminal
color: blue
inputs:
kernel:
description: Desired kernel version, in semantic format.
required: true
os:
description: Version code of the Fedora Linux release.
default: f38
outputs:
kernel:
description: Full version string of the running kernel.
value: ${{ steps.kernel-current.outputs.version }}
kernel-short:
description: Short, SemVer compatible version string of the running kernel.
value: ${{ steps.kernel-current.outputs.version-short }}
logs:
description: Location on the runner of the exported cloud-init logs.
value: ${{ steps.export-logs.outputs.path }}
runs:
using: composite
steps:
- id: validate-input
shell: bash
run: |
echo '::group::Validate input parameters'
declare err
declare -i failed=0
if [[ ! ${{ inputs.kernel }} =~ ^[0-9]\.[0-9]+$ ]]; then
(( failed ++ ))
err="The provided 'kernel' parameter '${{ inputs.kernel }}' doesn't match the expected format"
echo "::error title=Invalid input::${err}"
fi
declare os=${{ inputs.os }}
if [[ -n "$os" && ! "$os" =~ ^f[0-9]{2}$ ]]; then
(( failed ++ ))
err="The provided 'os' parameter '${{ inputs.os }}' doesn't match the expected format"
echo "::error title=Invalid input::${err}"
fi
if (( failed )); then
exit 1
fi
echo 'Input OK'
echo '::endgroup::'
- id: image
uses: antoineco/fedora-qemu-img-info-action@v1
with:
os: ${{ !inputs.os && 'f38' || inputs.os }}
- id: gen-vm-name
shell: bash
run: |
echo '::group::Generate Lima instance name'
declare name="${GITHUB_ACTION#__}-${RANDOM}"
echo "Exporting Lima instance name '${name}'"
echo "LIMA_INSTANCE=${name}" >>"$GITHUB_ENV"
echo '::endgroup::'
- id: bootstrap
uses: pyTooling/Actions/with-post-step@v0.4.5
with:
# with-post-step executes the given commands using child_process.spawn() with shell=true.
# On macOS 12, /bin/sh defaults to Bash 3.2, which is too old to run these scripts. We use 'exec' to replace the
# /bin/sh process with the shell defined by the script's shebang.
# Ref. https://nodejs.org/docs/latest-v16.x/api/child_process.html#child_processspawncommand-args-options
main: >-
exec ${{ github.action_path }}/scripts/pytooling-bootstrap-main.sh
${{ steps.image.outputs.url }}
${{ steps.image.outputs.sha256sum }}
${{ inputs.kernel }}
${{ github.workspace }}
post: |-
exec ${{ github.action_path }}/scripts/pytooling-bootstrap-post.sh
- id: kernel-current
shell: bash
run: |
echo '::group::Read version of running Linux kernel'
source ${{ github.action_path }}/scripts/lib/host/kernel.sh
source ${{ github.action_path }}/scripts/lib/host/util.sh
declare arch kernel_current kernel_short
arch="$(util::linux_arch)"
kernel_current="$(kernel::current)"
echo "version=${kernel_current}" >>"$GITHUB_OUTPUT"
if [[ "$kernel_current" =~ ^([0-9]+\.[0-9]+(\.[0-9]+)?) ]]; then
kernel_short="${BASH_REMATCH[1]}"
echo "version-short=${kernel_short}" >>"$GITHUB_OUTPUT"
else
declare err="Unable to parse short version of running kernel ${kernel_current}"
echo "::error title=Invalid kernel version::${err}"
exit 1
fi
echo "Lima instance is running kernel '${kernel_current}' (${kernel_short})"
echo '::endgroup::'
- id: kernel-semver
uses: madhead/semver-utils@v3
with:
version: ${{ steps.kernel-current.outputs.version-short }}
satisfies: ${{ inputs.kernel }}.x
lenient: false
- id: kernel-check
shell: bash
run: |
echo '::group::Verify kernel version constraint'
if [[ ${{ steps.kernel-semver.outputs.satisfies }} != 'true' ]]; then
declare err='Running kernel ${{ steps.kernel-current.outputs.version-short }} does not satisfy constraint ${{ inputs.kernel }}.x'
echo "::error title=Wrong kernel version::${err}"
exit 1
fi
echo 'Running kernel ${{ steps.kernel-current.outputs.version-short }} satisfies constraint ${{ inputs.kernel }}.x'
echo '::endgroup::'
- id: export-logs
if: always() && steps.gen-vm-name.outcome == 'success' && steps.bootstrap.outcome != 'skipped'
shell: bash
run: |
echo '::group::Export cloud-init logs'
declare logs_path=/tmp/lima/${{ env.LIMA_INSTANCE }}
mkdir -p "$logs_path"
declare unit
for unit in cloud-init cloud-final; do
echo "Exporting messages for unit '${unit}.service' to ${logs_path}/${unit}.log"
lima sudo sh -c "journalctl -u ${unit}.service >${logs_path}/${unit}.log"
done
echo "path=${logs_path}" >>"$GITHUB_OUTPUT"
echo '::endgroup::'