-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (177 loc) · 7.64 KB
/
Copy pathplugin-ci.yml
File metadata and controls
204 lines (177 loc) · 7.64 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
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
name: Reusable Plugin Verification
on:
workflow_call:
permissions: {}
concurrency:
group: plugin-ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: "1"
jobs:
build-and-test:
name: Build, test, and package
runs-on: ubuntu-24.04
timeout-minutes: 45
permissions:
contents: read
steps:
- name: Check out plugin repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Activate repository Rust toolchain
shell: bash
run: |
test -f rust-toolchain.toml
rustc --version --verbose
cargo --version
rustup component list --installed | grep -q '^clippy-'
rustup component list --installed | grep -q '^rustfmt-'
rustup target list --installed | grep -qx 'wasm32-wasip1'
- name: Cache Cargo build data
uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- name: Verify plugin manifests
shell: bash
run: |
python3 - <<'PY'
import os
import re
import tomllib
numeric = r"(?:0|[1-9][0-9]*)"
prerelease = (
r"(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)"
r"(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*"
)
build = r"[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*"
semver = re.compile(
rf"{numeric}\.{numeric}\.{numeric}"
rf"(?:-{prerelease})?(?:\+{build})?"
)
with open("Cargo.toml", "rb") as file:
cargo = tomllib.load(file)
with open("plugin.toml", "rb") as file:
manifest = tomllib.load(file)["plugin"]
package = cargo["package"]
if package["name"] != manifest["name"]:
raise SystemExit("Cargo.toml and plugin.toml names differ")
if package["version"] != manifest["version"]:
raise SystemExit("Cargo.toml and plugin.toml versions differ")
for field, version in (
("version", manifest["version"]),
("min_vortex_version", manifest["min_vortex_version"]),
):
if not isinstance(version, str) or semver.fullmatch(version) is None:
raise SystemExit(f"plugin.{field} is not valid SemVer 2.0.0")
package_name = package["name"]
crate_name = cargo.get("lib", {}).get("name", package_name.replace("-", "_"))
if re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", crate_name) is None:
raise SystemExit("library name cannot be mapped to a WASM artifact")
artifact_name = f"{crate_name}.wasm"
wasm_path = f"target/wasm32-wasip1/release/{artifact_name}"
plugin_wasm_asset = f"{package_name.replace('-', '_')}.wasm"
if re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*\.wasm", plugin_wasm_asset) is None:
raise SystemExit("plugin name cannot be mapped to a release WASM asset")
with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as env:
env.write(f"PACKAGE_NAME={package_name}\n")
env.write(f"PLUGIN_WASM_ASSET={plugin_wasm_asset}\n")
env.write(f"WASM_PATH={wasm_path}\n")
PY
- name: Check formatting
run: cargo fmt --all -- --check
- name: Lint native targets
run: cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings
- name: Lint WASM library
run: cargo clippy --locked --lib --target wasm32-wasip1 -- -D warnings
- name: Build release WASM
run: cargo build --locked --lib --target wasm32-wasip1 --release
- name: Verify WASM artifact and ABI exports
shell: bash
run: |
test -s "${WASM_PATH}"
case "${PACKAGE_NAME}" in
vortex-mod-captcha-anticaptcha)
required="can_solve solve get_balance"
;;
vortex-mod-captcha-browser|vortex-mod-captcha-ocr)
required="can_solve solve"
;;
vortex-mod-containers)
required="can_decrypt detect decrypt"
;;
vortex-mod-gallery)
required="can_handle supports_playlist extract_links extract_generic is_http_url"
;;
vortex-mod-soundcloud)
required="can_handle supports_playlist extract_links extract_playlist extract_track resolve_stream_url download_to_file"
;;
vortex-mod-vimeo)
required="can_handle supports_playlist extract_links get_media_variants resolve_stream_url download_to_file extract_playlist"
;;
vortex-mod-youtube)
required="can_handle supports_playlist extract_links get_media_variants extract_playlist resolve_stream_url download_to_file"
;;
*)
required="can_handle supports_playlist extract_links resolve_stream_url"
;;
esac
REQUIRED_EXPORTS="${required}" node <<'JS'
const fs = require("node:fs");
let compiled;
try {
compiled = new WebAssembly.Module(fs.readFileSync(process.env.WASM_PATH));
} catch (error) {
console.error(`invalid WASM artifact: ${error.message}`);
process.exit(1);
}
const functionExports = new Set(
WebAssembly.Module.exports(compiled)
.filter(({ kind }) => kind === "function")
.map(({ name }) => name),
);
for (const required of process.env.REQUIRED_EXPORTS.split(/\s+/)) {
if (!functionExports.has(required)) {
console.error(`missing required WASM export: ${required}`);
process.exit(1);
}
}
JS
- name: Run native tests including ABI smoke
run: cargo test --locked --all-targets --target x86_64-unknown-linux-gnu
- name: Build verified release bundle
id: bundle
shell: bash
run: |
bundle_dir="$(mktemp -d "${RUNNER_TEMP}/plugin-release.XXXXXX")"
printf 'bundle_dir=%s\n' "${bundle_dir}" >> "${GITHUB_OUTPUT}"
cp "${WASM_PATH}" "${bundle_dir}/plugin.wasm"
if [[ "${PLUGIN_WASM_ASSET}" != "plugin.wasm" ]]; then
cp "${WASM_PATH}" "${bundle_dir}/${PLUGIN_WASM_ASSET}"
fi
cp plugin.toml "${bundle_dir}/plugin.toml"
(
cd "${bundle_dir}"
sha256sum plugin.wasm plugin.toml > SHA256SUMS
sha256sum --check SHA256SUMS
)
expected_asset_names=(plugin.wasm plugin.toml SHA256SUMS)
if [[ "${PLUGIN_WASM_ASSET}" != "plugin.wasm" ]]; then
expected_asset_names+=("${PLUGIN_WASM_ASSET}")
fi
expected_assets="$(printf '%s\n' "${expected_asset_names[@]}" | LC_ALL=C sort)"
actual_assets="$(
find "${bundle_dir}" -mindepth 1 -printf '%P\n' | LC_ALL=C sort
)"
if [[ "${actual_assets}" != "${expected_assets}" ]]; then
echo "verified bundle asset set is not canonical" >&2
diff -u <(printf '%s\n' "${expected_assets}") \
<(printf '%s\n' "${actual_assets}") || true
exit 1
fi
- name: Upload verified release bundle
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: plugin-release-${{ github.sha }}
path: ${{ steps.bundle.outputs.bundle_dir }}/
if-no-files-found: error
retention-days: 14