Don't fail on Node.js #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Coverage & Documentation | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref_name }} | |
cancel-in-progress: true | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
coverage: | |
name: Test Coverage ${{ matrix.mt.description }} | |
runs-on: ubuntu-24.04 | |
timeout-minutes: 10 | |
strategy: | |
matrix: | |
mt: | |
- { id: 0 } | |
- { | |
id: 1, | |
description: with Atomics, | |
component: --component rust-src, | |
cflags: -matomics -mbulk-memory, | |
flags: "-Ctarget-feature=+atomics,+bulk-memory", | |
args: "-Zbuild-std=panic_abort,std", | |
} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install `wasm-bindgen-cli` | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: wasm-bindgen-cli | |
- name: Install Clang v18 | |
run: sudo apt-get install clang-18 | |
- name: Install Rust nightly | |
run: | | |
rustup toolchain install nightly --profile minimal --target wasm32-unknown-unknown ${{ matrix.mt.component }} | |
rustup default nightly | |
- name: Test | |
env: | |
CHROMEDRIVER: chromedriver | |
CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }} | |
CARGO_HOST_RUSTFLAGS: --cfg=wasm_bindgen_unstable_test_coverage | |
RUSTFLAGS: | |
-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir | |
--cfg=wasm_bindgen_unstable_test_coverage --cfg=web_sys_unstable_apis | |
--cfg=unsupported_spawn_then_block ${{ matrix.mt.flags }} | |
WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT: coverage-output | |
run: | | |
mkdir coverage-output | |
cargo test --all-features --target wasm32-unknown-unknown -Ztarget-applies-to-host -Zhost-config ${{ matrix.mt.args }} --tests -- --skip corrupt | |
- name: Prepare Object Files | |
env: | |
CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }} | |
CARGO_HOST_RUSTFLAGS: --cfg=wasm_bindgen_unstable_test_coverage | |
RUSTFLAGS: | |
-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir | |
--cfg=wasm_bindgen_unstable_test_coverage --cfg=web_sys_unstable_apis | |
--cfg=unsupported_spawn_then_block ${{ matrix.mt.flags }} | |
run: | | |
mkdir coverage-input | |
crate_name=web_thread | |
IFS=$'\n' | |
for file in $( | |
cargo test --all-features --target wasm32-unknown-unknown -Ztarget-applies-to-host -Zhost-config ${{ matrix.mt.args }} --tests --no-run --message-format=json | \ | |
jq -r "select(.reason == \"compiler-artifact\") | (select(.target.kind == [\"test\"]) // select(.target.name == \"$crate_name\")) | .filenames[0]" | |
) | |
do | |
if [[ ${file##*.} == "rlib" ]]; then | |
base=$(basename $file .rlib) | |
file=$(dirname $file)/${base#"lib"}.ll | |
else | |
file=$(dirname $file)/$(basename $file .wasm).ll | |
fi | |
input=coverage-input/$(basename $file) | |
cp $file $input | |
perl -i -p0e 's/(^define.*?$).*?^}/$1\nstart:\n unreachable\n}/gms' $input | |
counter=1 | |
while (( counter != 0 )); do | |
counter=$(perl -i -p0e '$c+= s/(^(define|declare)(,? [^\n ]+)*),? range\(.*?\)/$1/gm; END{print "$c"}' $input) | |
done | |
clang-18 $input -Wno-override-module -c -o coverage-output/$(basename $input .ll).o | |
done | |
- name: Upload Test Coverage Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-coverage-${{ matrix.mt.id }} | |
path: coverage-output | |
retention-days: 1 | |
if-no-files-found: error | |
collect-coverage: | |
name: Collect Test Coverage | |
needs: coverage | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install LLVM v18 | |
run: sudo apt-get install llvm-18 | |
- name: Download Test Coverage | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: test-coverage-* | |
path: coverage-input | |
- name: Merge Profile Data | |
run: | |
llvm-profdata-18 merge -sparse coverage-input/*/*.profraw -o | |
coverage-input/coverage.profdata | |
- name: Export Code Coverage Report | |
run: | | |
mkdir coverage-output | |
objects=() | |
for file in $(ls coverage-input/*/*.o) | |
do | |
objects+=(-object $file) | |
done | |
llvm-cov-18 show -show-instantiations=false -output-dir coverage-output -format=html -instr-profile=coverage-input/coverage.profdata ${objects[@]} -sources src | |
llvm-cov-18 export -format=text -summary-only -instr-profile=coverage-input/coverage.profdata ${objects[@]} -sources src | \ | |
printf '{ "coverage": "%.2f%%" }' $(jq '.data[0].totals.functions.percent') > coverage-output/coverage.json | |
sed 's/<!doctype html>//' coverage-output/index.html | perl -p0e 's/<a[^>]*>((?!here).*?)<\/a>/$1/g' >> $GITHUB_STEP_SUMMARY | |
- name: Upload Test Coverage Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-coverage | |
path: coverage-output | |
retention-days: 1 | |
if-no-files-found: error | |
document: | |
name: Document | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Rust nightly | |
run: | | |
rustup toolchain install nightly --profile minimal --target wasm32-unknown-unknown | |
rustup default nightly | |
- name: Run Rustdoc | |
env: | |
RUSTDOCFLAGS: --crate-version main --cfg=docsrs | |
run: | |
cargo doc --all-features --target wasm32-unknown-unknown --no-deps -Zrustdoc-map | |
-Zrustdoc-scrape-examples | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Fix permissions | |
run: | | |
chmod -c -R +rX "target/wasm32-unknown-unknown/doc" | while read line; do | |
echo "::warning title=Invalid file permissions automatically fixed::$line" | |
done | |
- name: Upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: documentation | |
path: target/wasm32-unknown-unknown/doc | |
retention-days: 1 | |
if-no-files-found: error | |
deploy: | |
name: Deploy | |
needs: [collect-coverage, document] | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }}doc/web_thread | |
runs-on: ubuntu-latest | |
if: | |
github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.ref_name == | |
'main') | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download Test Coverage | |
uses: actions/download-artifact@v4 | |
with: | |
name: test-coverage | |
path: page/coverage | |
- name: Download Documentation | |
uses: actions/download-artifact@v4 | |
with: | |
name: documentation | |
path: page/doc | |
- name: Upload Page Artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: page | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |