Skip to content

Commit 72deed1

Browse files
committed
feat(module-if): Add support for conditional modules
1 parent f81c590 commit 72deed1

32 files changed

Lines changed: 1441 additions & 168 deletions

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
exit $1

integration-tests/test-repo/recipes/common.yml

Lines changed: 158 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,155 @@ modules:
1212
- example.sh
1313

1414
- type: script
15+
env:
16+
TEST_ARG_2: "another"
17+
if:
18+
env:
19+
exists:
20+
- TEST_ARG
21+
- TEST_ARG_2
22+
snippets:
23+
- exit 1
24+
25+
- type: script
26+
env:
27+
TEST_ARG: "test"
28+
TEST_ARG_2: "another"
29+
if:
30+
env:
31+
not-exists:
32+
- TEST_ARG
33+
- TEST_ARG_2
34+
snippets:
35+
- exit 1
36+
37+
- type: script
38+
env:
39+
TEST_ARG: "test"
40+
if:
41+
env:
42+
equals:
43+
TEST_ARG:
44+
- no-test
45+
- some-test
1546
snippets:
16-
- '[ -z "$TEST_ARG" ]'
47+
- exit 1
1748

1849
- type: script
1950
env:
2051
TEST_ARG: "test"
52+
if:
53+
env:
54+
not-equals:
55+
TEST_ARG:
56+
- test
57+
- some-test
58+
snippets:
59+
- exit 1
60+
61+
- type: script
62+
env:
63+
TEST_ARG: "test"
64+
TEST_ARG_2: "another"
65+
if: '[ "$TEST_ARG" = "$TEST_ARG_2" ]'
66+
snippets:
67+
- exit 1
68+
69+
- type: script
70+
env:
71+
TEST_ARG: "test"
72+
TEST_ARG_2: "another"
73+
if:
74+
eval: '[ "$TEST_ARG" = "$TEST_ARG_2" ]'
75+
env:
76+
exists:
77+
- TEST_ARG_2
78+
- TEST_ARG_3
79+
not-exists: TEST_ARG
80+
equals:
81+
TEST_ARG:
82+
- no-test
83+
- some-test
84+
not-equals:
85+
TEST_ARG_2: another
86+
snippets:
87+
- exit 1
88+
89+
- type: script
90+
if:
91+
host-file:
92+
exists:
93+
- ./non-existant-file.txt
94+
- ./another-non-existant-file.txt
95+
snippets:
96+
- exit 1
97+
98+
- type: script
99+
if:
100+
host-file:
101+
not-exists:
102+
- ./test_secret_file.txt
103+
- ./secrets/test-secret
104+
snippets:
105+
- exit 1
106+
107+
- type: script
108+
if:
109+
host-env:
110+
exists:
111+
- NON_EXISTANT_VAR
112+
- ANOTHER_NON_EXISTANT_VAR
113+
snippets:
114+
- exit 1
115+
116+
- type: script
117+
if:
118+
host-env:
119+
not-exists:
120+
- TEST_SECRET
121+
- SOME_TEST_VAR
122+
snippets:
123+
- exit 1
124+
125+
- type: script
126+
if:
127+
host-env:
128+
equals:
129+
TEST_SECRET: test321
130+
SOME_TEST_VAR:
131+
- some_value
132+
- another_possible_value
133+
snippets:
134+
- exit 1
135+
136+
- type: script
137+
if:
138+
host-env:
139+
not-equals:
140+
TEST_SECRET: test123
141+
SOME_TEST_VAR:
142+
- something
143+
- another_possible_value
144+
snippets:
145+
- exit 1
146+
147+
- type: script
148+
if:
149+
host-exec:
150+
cmd: ./host_exec.sh
151+
args:
152+
- '1'
21153
snippets:
22-
- '[ "$TEST_ARG" = "test" ]'
154+
- exit 1
23155

24156
- type: script
157+
if:
158+
not-host-exec:
159+
cmd: ./host_exec.sh
160+
args:
161+
- '0'
25162
snippets:
26-
- '[ -z "$TEST_ARG" ]'
163+
- exit 1
27164

28165
- type: dnf
29166
repos:
@@ -84,6 +221,9 @@ modules:
84221

85222
# Testing secrets
86223
- type: script
224+
if:
225+
host-env:
226+
exists: TEST_SECRET
87227
secrets:
88228
- type: env
89229
name: TEST_SECRET
@@ -94,6 +234,9 @@ modules:
94234
- '[ "$TEST_SECRET" == "test123" ]'
95235

96236
- type: script
237+
if:
238+
host-env:
239+
exists: TEST_SECRET
97240
secrets:
98241
- type: env
99242
name: TEST_SECRET
@@ -104,6 +247,9 @@ modules:
104247
- '[ "$(cat /tmp/test-secret)" == "test123" ]'
105248

106249
- type: script
250+
if:
251+
host-file:
252+
exists: ./secrets/test-secret
107253
secrets:
108254
- type: file
109255
source: ./secrets/test-secret
@@ -114,6 +260,9 @@ modules:
114260
- '[ "$(cat /tmp/test-secret)" == "321tset" ]'
115261

116262
- type: script
263+
if:
264+
host-file:
265+
exists: ./secrets/test-secret
117266
secrets:
118267
- type: file
119268
source: ./secrets/test-secret
@@ -124,6 +273,9 @@ modules:
124273
- '[ "$TEST_SECRET" == "321tset" ]'
125274

126275
- type: script
276+
if:
277+
host-file:
278+
exists: ./test_secret_file.txt
127279
secrets:
128280
- type: exec
129281
command: cat
@@ -136,6 +288,9 @@ modules:
136288
- '[ "$TEST_SECRET" == "TEST_PASS" ]'
137289

138290
- type: script
291+
if:
292+
host-file:
293+
exists: ./test_secret_file.txt
139294
secrets:
140295
- type: exec
141296
command: cat
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# yaml-language-server: $schema=https://schema.blue-build.org/module-list-v1.json
3+
modules:
4+
- type: apt
5+
if:
6+
os-release:
7+
ID:
8+
- ubuntu
9+
- debian
10+
install:
11+
packages:
12+
- git
13+
- type: dnf
14+
if:
15+
os-release:
16+
ID:
17+
- fedora
18+
- centos
19+
- rhel
20+
install:
21+
packages:
22+
- git
23+
- type: apk
24+
if:
25+
os-release:
26+
ID: alpine
27+
install:
28+
packages:
29+
- git
30+
- type: pacman
31+
if:
32+
os-release:
33+
ID: archlinux
34+
install:
35+
packages:
36+
- git
37+
- type: zypper
38+
if:
39+
os-release:
40+
ID: opensuse-tumbleweed
41+
install:
42+
packages:
43+
- git

integration-tests/test-repo/recipes/stages.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,27 @@ stages:
55
from: docker.io/library/ubuntu
66
modules:
77
- from-file: stages.yml
8-
- type: apt
9-
install:
10-
packages:
11-
- git
128
- name: debian-test
139
from: docker.io/library/debian
1410
modules:
1511
- from-file: stages.yml
16-
- type: apt
17-
install:
18-
packages:
19-
- git
2012
- name: fedora-test
2113
from: docker.io/library/fedora
2214
modules:
2315
- from-file: stages.yml
24-
- type: dnf
25-
install:
26-
packages:
27-
- git
2816
- name: alpine-test
2917
from: docker.io/library/alpine
3018
modules:
3119
- from-file: stages.yml
32-
- type: apk
33-
install:
34-
packages:
35-
- git
3620
- name: arch-test
3721
from: docker.io/archlinux/archlinux
3822
platform: linux/amd64
3923
modules:
4024
- from-file: stages.yml
41-
- type: pacman
42-
install:
43-
packages:
44-
- git
4525
- name: suse-test
4626
from: docker.io/opensuse/tumbleweed
4727
modules:
4828
- from-file: stages.yml
49-
- type: zypper
50-
install:
51-
packages:
52-
- git
5329
modules:
5430
- type: files
5531
files:
@@ -74,3 +50,4 @@ modules:
7450
- is
7551
- a
7652
- test
53+
- from-file: git.yml

justfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export RUST_BACKTRACE := "1"
22
export BB_CACHE_LAYERS := "true"
33
export TEST_SECRET := "test123"
4-
export BB_SKIP_VALIDATION := "true"
4+
export SOME_TEST_VAR := "something"
5+
export BB_ALLOW_HOST_EXEC := "true"
6+
# export BB_SKIP_VALIDATION := "true"
57

68
set dotenv-load := true
79
set positional-arguments := true
@@ -331,6 +333,8 @@ exec-cli-container +args: build-local-cli-image
331333
docker run -i{{ tty_arg }} --privileged --rm \
332334
-v ./integration-tests/test-repo:/bluebuild \
333335
-e TEST_SECRET="$TEST_SECRET" \
336+
-e SOME_TEST_VAR="$SOME_TEST_VAR" \
337+
-e BB_ALLOW_HOST_EXEC="$BB_ALLOW_HOST_EXEC" \
334338
ghcr.io/blue-build/cli:{{ git_sha }} \
335339
{{ args }}
336340

0 commit comments

Comments
 (0)