Skip to content

Commit 2c55ff0

Browse files
committed
feat(module-if): Add support for conditional modules
1 parent 1a810c2 commit 2c55ff0

12 files changed

Lines changed: 746 additions & 35 deletions

File tree

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.

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

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,79 @@ 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
2158
snippets:
22-
- '[ "$TEST_ARG" = "test" ]'
59+
- exit 1
2360

2461
- 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
2586
snippets:
26-
- '[ -z "$TEST_ARG" ]'
87+
- exit 1
2788

2889
- type: dnf
2990
repos:
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

recipe/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ blue-build-utils = { version = "=0.9.30", path = "../utils" }
1313

1414
cached.workspace = true
1515
colored.workspace = true
16+
comlexr.workspace = true
1617
log.workspace = true
1718
miette.workspace = true
1819
oci-client.workspace = true
@@ -23,5 +24,9 @@ serde_yaml.workspace = true
2324
serde_json.workspace = true
2425
bon.workspace = true
2526

27+
[dev-dependencies]
28+
rstest.workspace = true
29+
pretty_assertions.workspace = true
30+
2631
[lints]
2732
workspace = true

recipe/src/module.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ use serde_yaml::Value;
1313

1414
use crate::{AkmodsInfo, ModuleExt, base_recipe_path};
1515

16+
mod module_if;
1617
mod type_ver;
1718

19+
pub use module_if::*;
1820
pub use type_ver::*;
1921

2022
#[derive(Serialize, Deserialize, Debug, Clone, Builder)]
@@ -39,6 +41,10 @@ pub struct ModuleRequiredFields {
3941
#[serde(skip_serializing_if = "Vec::is_empty", default)]
4042
pub secrets: Vec<Secret>,
4143

44+
#[serde(rename = "if")]
45+
#[serde(skip_serializing_if = "Option::is_none")]
46+
pub if_check: Option<ModuleIf>,
47+
4248
#[serde(flatten)]
4349
#[builder(default, into)]
4450
pub config: IndexMap<String, Value>,

0 commit comments

Comments
 (0)