forked from bats-core/bats-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
291 lines (270 loc) · 10.9 KB
/
action.yaml
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
name: Setup Bats and Bats libraries
description: A GitHub Action for installing Bats and Bats-libs(support, assert, detik, file)
author: bats-core
branding:
color: yellow
icon: command
inputs:
# Bats binary
bats-install:
description: "Bats installation, default to true"
required: false
default: true
bats-version:
description: "Bats version, default to latest (1.11.0 atm)"
required: false
# support
support-install:
description: "Bats-support installation, default to true"
required: false
default: true
support-version:
description: "Bats-support version, default to latest"
required: false
default: "0.3.0"
support-path:
description: "Bats-support path, default to /usr/lib/bats-support"
required: false
default: "/usr/lib/bats-support"
support-clean:
description: "Bats-support: clean temp files"
required: false
default: true
# assert
assert-install:
description: "Bats-assert installation, default to true"
required: false
default: true
assert-version:
description: "Bats-assert version, default to latest"
required: false
default: "2.1.0"
assert-path:
description: "Bats-assert path, default to /usr/lib/bats-assert"
required: false
default: "/usr/lib/bats-assert"
assert-clean:
description: "Bats-assert: clean temp files"
required: false
default: true
# detik
detik-install:
description: "Bats-detik installation, default to true"
required: false
default: true
detik-version:
description: "Bats-detik version, default to latest"
required: false
default: "1.3.1"
detik-path:
description: "Bats-detik path, default to /usr/lib/bats-detik"
required: false
default: "/usr/lib/bats-detik"
detik-clean:
description: "Bats-detik: clean temp files"
required: false
default: true
# file
file-install:
description: "Bats-file installation, default to true"
required: false
default: true
file-version:
description: "Bats-file version, default to latest"
required: false
default: "0.4.0"
file-path:
description: "Bats-file path, default to /usr/lib/bats-file"
required: false
default: "/usr/lib/bats-file"
file-clean:
description: "Bats-file: clean temp files"
required: false
default: true
outputs:
bats-installed:
description: "True/False if bats has been installed"
value: ${{ (steps.bats-install.outputs.bats-installed != '') }}
support-installed:
description: "True/False if bats-support has been installed"
value: ${{ (steps.support-install.outputs.support-installed != '') }}
assert-installed:
description: "True/False if bats-assert has been installed"
value: ${{ (steps.assert-install.outputs.assert-installed != '') }}
detik-installed:
description: "True/False if bats-detik has been installed"
value: ${{ (steps.detik-install.outputs.detik-installed != '') }}
file-installed:
description: "True/False if bats-file has been installed"
value: ${{ (steps.file-install.outputs.file-installed != '') }}
runs:
using: composite
steps:
# This action would be much easier if only matrix steps will be supported in a composite action
- name: "Set cache for Bats"
uses: actions/cache@v4
if: inputs.bats-install == 'true'
id: bats-cache
with:
path: |
~/.local/share/bats
key: ${{ runner.os }}-bats-${{ inputs.bats-version }}
- name: "Set PATH in case of cache-hit"
if: inputs.bats-install == 'true' && steps.bats-cache.outputs.cache-hit == 'true'
id: bats-cache-path
shell: bash
run: |
DESTDIR="$HOME/.local/share/bats"
echo "${DESTDIR}/bin" >> "$GITHUB_PATH"
- name: "Download and install Bats"
if: inputs.bats-install == 'true' && steps.bats-cache.outputs.cache-hit != 'true'
id: bats-install
shell: bash
run: |
# In $HOME to avoid sudo requirements
VERSION=${{ inputs.bats-version }}
DESTDIR="$HOME/.local/share/bats"
TEMPDIR="/tmp/bats"
URL="https://github.com/bats-core/bats-core/"
# From https://github.com/fluxcd/flux2/blob/44d69d6fc0c353e79c1bad021a4aca135033bce8/action/action.yml#L35
if [[ -z "$VERSION" ]] || [[ "$VERSION" = "latest" ]]; then
VERSION=$(curl -fsSL --retry 2 --retry-all-errors https://api.github.com/repos/bats-core/bats-core/releases/latest | grep tag_name | cut -d '"' -f 4)
fi
[[ $VERSION = v* ]] && VERSION="${VERSION:1}"
mkdir -p ${TEMPDIR}
mkdir -p ${DESTDIR}
curl -sL --retry 2 --retry-all-errors ${URL}/archive/refs/tags/v${VERSION}.tar.gz | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR}
# Install
./install.sh ${DESTDIR}
echo "Bats v${VERSION} installed in ${DESTDIR}"
echo "${DESTDIR}/bin" >> "$GITHUB_PATH"
echo "bats-installed=true" >> $GITHUB_OUTPUT
rm -rf ${TEMPDIR} || exit 0
- name: "Set cache for Bats-support"
uses: actions/cache@v4
if: inputs.support-install == 'true'
id: support-cache
with:
path: ${{ inputs.support-path }}
key: ${{ runner.os }}-bats-support-${{ inputs.support-version }}
- name: "Download and install Bats-support"
if: inputs.support-install == 'true' && steps.support-cache.outputs.cache-hit != 'true'
id: support-install
shell: bash
run: |
VERSION=${{ inputs.support-version }}
DESTDIR=${{ inputs.support-path }}
TEMPDIR="/tmp/bats-support"
url="https://github.com/bats-core/bats-support/archive/refs/tags/v${VERSION}.tar.gz"
mkdir -p ${TEMPDIR}
[[ "${DESTDIR}" == "$HOME"* ]] && CMD="" || CMD="sudo"
${CMD} mkdir -p ${DESTDIR}/src/
curl -sL --retry 2 --retry-all-errors ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR}
# Archlinux style, except that we are not in a fakeroot env
${CMD} install -Dm755 load.bash ${DESTDIR}/load.bash
for fn in src/*.bash; do
${CMD} install -Dm755 $fn \
${DESTDIR}/src/$(basename $fn)
done
echo "Bats Support v$VERSION installed in $DESTDIR"
echo "support-installed=true" >> $GITHUB_OUTPUT
# Cleanup bats-support if required
[[ "${{ inputs.support-clean }}" = "true" ]] && rm -rf ${TEMPDIR} || exit 0
- name: "Set cache for Bats-assert"
uses: actions/cache@v4
if: inputs.assert-install == 'true'
id: assert-cache
with:
path: ${{ inputs.assert-path }}
key: ${{ runner.os }}-bats-assert-${{ inputs.assert-version }}
- name: "Download and install Bats-assert"
if: inputs.assert-install == 'true' && steps.assert-cache.outputs.cache-hit != 'true'
id: assert-install
shell: bash
run: |
VERSION=${{ inputs.assert-version }}
DESTDIR=${{ inputs.assert-path }}
TEMPDIR="/tmp/bats-assert"
url="https://github.com/bats-core/bats-assert/archive/refs/tags/v${VERSION}.tar.gz"
mkdir -p ${TEMPDIR}
[[ "${DESTDIR}" == "$HOME"* ]] && CMD="" || CMD="sudo"
${CMD} mkdir -p ${DESTDIR}/src/
curl -sL --retry 2 --retry-all-errors ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR}
# Archlinux style, except that we are not in a fakeroot env
${CMD} install -Dm755 load.bash ${DESTDIR}/load.bash
for fn in src/*.bash; do
${CMD} install -Dm755 $fn \
${DESTDIR}/src/$(basename $fn)
done
echo "Bats Assert v$VERSION installed in $DESTDIR"
echo "assert-installed=true" >> "$GITHUB_OUTPUT"
# Cleanup bats-support if required
[[ "${{ inputs.assert-clean }}" = "true" ]] && rm -rf ${TEMPDIR} || exit 0
- name: "Set cache for Bats-detik"
uses: actions/cache@v4
if: inputs.detik-install == 'true'
id: detik-cache
with:
path: ${{ inputs.detik-path }}
key: ${{ runner.os }}-bats-detik-${{ inputs.detik-version }}
- name: "Download and install Bats-detik"
if: inputs.detik-install == 'true' && steps.detik-cache.outputs.cache-hit != 'true'
id: detik-install
shell: bash
run: |
VERSION=${{ inputs.detik-version }}
DESTDIR=${{ inputs.detik-path }}
TEMPDIR="/tmp/bats-detik"
url="https://github.com/bats-core/bats-detik/archive/refs/tags/v${VERSION}.tar.gz"
mkdir -p ${TEMPDIR}
[[ "${DESTDIR}" == "$HOME"* ]] && CMD="" || CMD="sudo"
${CMD} mkdir -p ${DESTDIR}/src/
curl -sL --retry 2 --retry-all-errors ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR}
# Archlinux style, except that we are not in a fakeroot env so we need to use sudo
for fn in lib/*.bash; do
${CMD} install -Dm755 $fn \
${DESTDIR}/$(basename $fn)
done
echo "Bats Detik v$VERSION installed in $DESTDIR"
echo "detik-installed=true" >> "$GITHUB_OUTPUT"
# Cleanup bats-support if required
[[ "${{ inputs.detik-clean }}" = "true" ]] && rm -rf ${TEMPDIR} || exit 0
- name: "Set cache for Bats-file"
uses: actions/cache@v4
if: inputs.file-install == 'true'
id: file-cache
with:
path: ${{ inputs.file-path }}
key: ${{ runner.os }}-bats-file-${{ inputs.file-version }}
- name: "Download and install Bats-file"
if: inputs.file-install == 'true' && steps.file-cache.outputs.cache-hit != 'true'
id: file-install
shell: bash
run: |
VERSION=${{ inputs.file-version }}
DESTDIR=${{ inputs.file-path }}
TEMPDIR="/tmp/bats-file"
url="https://github.com/bats-core/bats-file/archive/refs/tags/v${VERSION}.tar.gz"
mkdir -p ${TEMPDIR}
[[ "${DESTDIR}" == "$HOME"* ]] && CMD="" || CMD="sudo"
${CMD} mkdir -p ${DESTDIR}/src/
curl -sL --retry 2 --retry-all-errors ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR}
# Archlinux style, except that we are not in a fakeroot env
${CMD} install -Dm755 load.bash ${DESTDIR}/load.bash
for fn in src/*.bash; do
${CMD} install -Dm755 $fn \
${DESTDIR}/src/$(basename $fn)
done
echo "Bats File v$VERSION installed in $DESTDIR"
echo "file-installed=true" >> "$GITHUB_OUTPUT"
# Cleanup bats-support if required
[[ "${{ inputs.file-clean }}" = "true" ]] && rm -rf ${TEMPDIR} || exit 0
- name: "Debug print if installed"
if: runner.debug == '1'
shell: bash
run: |
echo "Bats installed: ${{ (steps.bats-install.outputs.bats-installed != '') }}"
echo "Support installed: ${{ (steps.support-install.outputs.support-installed != '') }}"
echo "Assert installed: ${{ (steps.assert-install.outputs.assert-installed != '') }}"
echo "Detik installed: ${{ (steps.detik-install.outputs.detik-installed != '') }}"
echo "File installed: ${{ (steps.file-install.outputs.file-installed != '') }}"