-
Notifications
You must be signed in to change notification settings - Fork 1
214 lines (194 loc) · 7.56 KB
/
test-and-build.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
name: Build extensions
on:
push:
branches: ["main"]
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
test:
name: Test modified extensions
env:
CARGO_COMPONENT_VERSION: "0.11.0"
SCCACHE_CACHE_SIZE: "2G"
SCCACHE_VERSION: "0.8.0"
RUSTC_WRAPPER: "/usr/local/bin/sccache"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore sccache cache
uses: actions/cache@v4
with:
path: ~/.cache/sccache
key: ${{ runner.os }}-sccache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-sccache-
- name: Restore cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
~/.cargo/bin
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install sccache
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
sccache_platform="x86_64-unknown-linux-musl"
elif [ "${{ runner.os }}" = "macOS" ]; then
sccache_platform="x86_64-apple-darwin"
elif [ "${{ runner.os }}" = "Windows" ]; then
sccache_platform="x86_64-pc-windows-msvc"
else
echo "Unsupported platform: ${{ runner.os }}"
exit 1
fi
sccache_file="sccache-v${SCCACHE_VERSION}-${sccache_platform}"
sccache_url="https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/${sccache_file}.tar.gz"
echo "URL=${sccache_url}"
curl -L "$sccache_url" | tar xz
mv -f "$sccache_file/sccache" "$RUSTC_WRAPPER"
chmod +x "$RUSTC_WRAPPER"
- name: Install wasm32-unknown-unknown target
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Install cargo-component
run: |
if ! command -v cargo-component || ! cargo-component --version | grep -q $CARGO_COMPONENT_VERSION; then
if [ "${{ runner.os }}" = "Linux" ]; then
cargo_component_platform="x86_64-unknown-linux-gnu"
elif [ "${{ runner.os }}" = "macOS" ]; then
cargo_component_platform="x86_64-apple-darwin"
elif [ "${{ runner.os }}" = "Windows" ]; then
cargo_component_platform="x86_64-pc-windows-gnu"
else
echo "Unsupported platform: ${{ runner.os }}"
exit 1
fi
cargo_component_file="cargo-component-${cargo_component_platform}"
cargo_component_url="https://github.com/bytecodealliance/cargo-component/releases/download/v${CARGO_COMPONENT_VERSION}/${cargo_component_file}"
echo "URL=${cargo_component_url}"
curl -L "$cargo_component_url" -o ~/.cargo/bin/cargo-component
chmod +x ~/.cargo/bin/cargo-component
fi
- name: Run tests only on modified packages
run: |
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
changed_packages_dir=$(echo "$changed_files" | grep -o '^src/[^/]*/[^/]*' | sort -u)
if [ -z "$changed_packages_dir" ]; then
echo "No packages to test"
exit 0
fi
while read -r package_dir; do
package_name=$(grep -oP -m 1 'name = "\K[^"]+' $package_dir/Cargo.toml)
echo "Running tests for $package_name"
cargo test --package $package_name
done <<< "$changed_packages_dir"
- name: Show sccache statistics
run: $RUSTC_WRAPPER --show-stats
rustfmt:
needs: test
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run `cargo fmt`
run: cargo fmt --all -- --check
build:
name: Build extensions
needs: rustfmt
env:
CARGO_COMPONENT_VERSION: "0.11.0"
SCCACHE_CACHE_SIZE: "2G"
SCCACHE_VERSION: "0.8.0"
RUSTC_WRAPPER: "/usr/local/bin/sccache"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore sccache cache
uses: actions/cache@v4
with:
path: ~/.cache/sccache
key: ${{ runner.os }}-sccache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-sccache-
- name: Restore cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
~/.cargo/bin
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install sccache
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
sccache_platform="x86_64-unknown-linux-musl"
elif [ "${{ runner.os }}" = "macOS" ]; then
sccache_platform="x86_64-apple-darwin"
elif [ "${{ runner.os }}" = "Windows" ]; then
sccache_platform="x86_64-pc-windows-msvc"
else
echo "Unsupported platform: ${{ runner.os }}"
exit 1
fi
sccache_file="sccache-v${SCCACHE_VERSION}-${sccache_platform}"
sccache_url="https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/${sccache_file}.tar.gz"
echo "URL=${sccache_url}"
curl -L "$sccache_url" | tar xz
mv -f "$sccache_file/sccache" "$RUSTC_WRAPPER"
chmod +x "$RUSTC_WRAPPER"
- name: Install wasm32-unknown-unknown target
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Install cargo-component
run: |
if ! command -v cargo-component || ! cargo-component --version | grep -q $CARGO_COMPONENT_VERSION; then
if [ "${{ runner.os }}" = "Linux" ]; then
cargo_component_platform="x86_64-unknown-linux-gnu"
elif [ "${{ runner.os }}" = "macOS" ]; then
cargo_component_platform="x86_64-apple-darwin"
elif [ "${{ runner.os }}" = "Windows" ]; then
cargo_component_platform="x86_64-pc-windows-gnu"
else
echo "Unsupported platform: ${{ runner.os }}"
exit 1
fi
cargo_component_file="cargo-component-${cargo_component_platform}"
cargo_component_url="https://github.com/bytecodealliance/cargo-component/releases/download/v${CARGO_COMPONENT_VERSION}/${cargo_component_file}"
echo "URL=${cargo_component_url}"
curl -L "$cargo_component_url" -o ~/.cargo/bin/cargo-component
chmod +x ~/.cargo/bin/cargo-component
fi
- name: Build extensions
run: cargo component build --release --target wasm32-unknown-unknown --workspace --locked
- name: Package extensions
run: .github/workflows/package.sh
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: gh-pages
commit-message: "Update extensions repository"
- name: Upload packaged extensions as artifact
uses: actions/upload-artifact@v4
with:
name: extensions
path: gh-pages/extensions/*.mix
if-no-files-found: ignore
- name: Show sccache statistics
run: $RUSTC_WRAPPER --show-stats