-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yml
More file actions
122 lines (107 loc) · 3.22 KB
/
Taskfile.yml
File metadata and controls
122 lines (107 loc) · 3.22 KB
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
# https://taskfile.dev
version: "3"
silent: true
dotenv: [".env"]
tasks:
default:
desc: Show available tasks
cmds:
- task --list-all
build:
desc: Build Docker image locally for testing
vars:
VERSION: '{{.VERSION | default "local"}}'
env:
DOCKER_BUILDKIT: 1
cmds:
- >
docker build
--tag {{.REGISTRY}}/{{.ORG}}/{{.IMAGE_NAME}}:{{.VERSION}}
--build-arg RUST_VERSION={{.RUST_VERSION}}
--build-arg WASM_TOOLS_VERSION={{.WASM_TOOLS_VERSION}}
-f {{.DOCKERFILE}} .
test:
desc: Test the built Docker image
vars:
VERSION: '{{.VERSION | default "local"}}'
TEST_DIR: /tmp/wasi-test
cmds:
- task: test:setup
vars:
TEST_DIR: "{{.TEST_DIR}}"
- task: test:run
vars:
TEST_DIR: "{{.TEST_DIR}}"
VERSION: "{{.VERSION}}"
- task: test:verify
vars:
TEST_DIR: "{{.TEST_DIR}}"
- defer: rm -rf "{{.TEST_DIR}}"
- echo "✅ Test completed successfully!"
test:setup:
desc: Setup test environment
requires:
vars: [TEST_DIR]
cmds:
- rm -rf {{.TEST_DIR}}
- mkdir -p {{.TEST_DIR}}/output
- mkdir -p {{.TEST_DIR}}/test-component/src
- mkdir -p {{.TEST_DIR}}/test-component/wit
- |
cat > {{.TEST_DIR}}/test-component/src/lib.rs << 'EOF'
wit_bindgen::generate!({
world: "hello",
path: "wit/world.wit",
});
struct Component;
impl Guest for Component {
fn greet() -> String {
"Hello from WASI component!".to_owned()
}
}
export!(Component);
EOF
- |
cat > {{.TEST_DIR}}/test-component/wit/world.wit << 'EOF'
package test:component;
world hello {
export greet: func() -> string;
}
EOF
- |
cat > {{.TEST_DIR}}/test-component/Cargo.toml << 'EOF'
[package]
name = "test-component"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
wit-bindgen = "0.24"
EOF
- cd {{.TEST_DIR}}/test-component && cargo generate-lockfile
test:run:
desc: Run the Docker container
requires:
vars: [TEST_DIR, VERSION]
cmds:
- >
docker run --rm --platform "linux/{{ARCH}}" -v {{.TEST_DIR}}:/docker
-v {{.TEST_DIR}}/output:/docker/output
-e HOST_UID=$(id -u) -e HOST_GID=$(id -g)
{{.REGISTRY}}/{{.ORG}}/{{.IMAGE_NAME}}:{{.VERSION}}
test:verify:
desc: Verify test results
requires:
vars: [TEST_DIR]
cmds:
- |
if [ -f "{{.TEST_DIR}}/output/test_component.wasm" ]; then
echo "✅ WASM file created successfully"
ls -lh {{.TEST_DIR}}/output/test_component.wasm
file {{.TEST_DIR}}/output/test_component.wasm | grep -q "WebAssembly" && echo "✅ WASM file is valid" || (echo "❌ WASM file is not valid" && exit 1)
else
echo "❌ Test FAILED: WASM file not found"
ls -la {{.TEST_DIR}}/output/
exit 1
fi