1name: CI
2on:
3  # Run CI for PRs to `main` and to release branches.
4  #
5  # Note that PRs to `main` will run a subset of tests and PRs to the
6  # `release-*` branches will run full CI.
7  pull_request:
8    branches:
9    - main
10    - 'release-*'
11
12  # This is the CI that runs for PRs-to-merge.
13  merge_group:
14
15  push:
16    branches:
17    # Right now merge queues can't be used with wildcards in branch protections
18    # so full CI runs both on PRs to release branches as well as merges to
19    # release branches. Note that the merge to a release branch may produce a
20    # tag at the end of CI if successful and the tag will trigger the artifact
21    # uploads as well as publication to crates.io.
22    - 'release-*'
23
24  # Allow manually triggering this request via a button or another workflow.
25  workflow_dispatch:
26
27defaults:
28  run:
29    shell: bash
30
31# Cancel any in-flight jobs for the same PR/branch so there's only one active
32# at a time
33concurrency:
34  group: ${{ github.workflow }}-${{ github.ref }}
35  cancel-in-progress: true
36
37jobs:
38  # Check Code style quickly by running `rustfmt` over all code
39  rustfmt:
40    name: Rustfmt
41    runs-on: ubuntu-latest
42    steps:
43    - uses: actions/checkout@v4
44      with:
45        submodules: true
46    - uses: ./.github/actions/install-rust
47    - run: rustup component add rustfmt
48    - run: cargo fmt --all -- --check
49
50  # Quick JS formatting/linting checks for the little bits of JS we have for the
51  # `wasmtime explore` UI.
52  check_js:
53    name: Check JS
54    runs-on: ubuntu-latest
55    steps:
56    - uses: actions/checkout@v4
57    - run: npm install
58      working-directory: ./crates/explorer
59    - run: npm run lint
60      working-directory: ./crates/explorer
61    - run: npm run fmt-check
62      working-directory: ./crates/explorer
63
64  # Check Code style quickly by running `clang-format` over all the C/C++ code
65  #
66  # Note that `wasmtime-platform.h` is excluded here as it's auto-generated.
67  clangformat:
68    name: Clang format
69    runs-on: ubuntu-24.04
70    steps:
71    - uses: actions/checkout@v4
72      with:
73        submodules: true
74    - run: |
75        git ls-files '*.h' '*.c' '*.cpp' '*.hh' '*.cc' | \
76          grep -v wasmtime-platform.h | \
77          grep -v wasm.h | \
78          xargs clang-format-18 --dry-run --Werror --verbose
79
80  # Lint dependency graph for security advisories, duplicate versions, and
81  # incompatible licences
82  cargo_deny:
83    name: Cargo deny
84    needs: determine
85    if: needs.determine.outputs.audit
86    runs-on: ubuntu-latest
87    steps:
88    - uses: actions/checkout@v4
89      with:
90        submodules: true
91    - uses: ./.github/actions/install-rust
92    - run: |
93        set -e
94        curl -L https://github.com/EmbarkStudios/cargo-deny/releases/download/0.18.2/cargo-deny-0.18.2-x86_64-unknown-linux-musl.tar.gz | tar xzf -
95        mv cargo-deny-*-x86_64-unknown-linux-musl/cargo-deny cargo-deny
96        echo `pwd` >> $GITHUB_PATH
97    - run: cargo deny check bans licenses
98
99  # Ensure dependencies are vetted. See https://mozilla.github.io/cargo-vet/
100  #
101  # Note that this step, on PRs only, is allowed to fail. This is then followed
102  # up with the `cargo_vet_failure_for_prs` step below. The intention is to
103  # avoid causing this check to fail PRs while still enabling it to fail the
104  # merge queue checks. That way PRs can enter the merge queue when this step is
105  # failing if `main` has picked up `cargo vet` entries in the meantime for the
106  # failures.
107  cargo_vet:
108    name: Cargo vet
109    needs: determine
110    if: github.repository == 'bytecodealliance/wasmtime' && needs.determine.outputs.audit
111    runs-on: ubuntu-latest
112    outputs:
113      outcome: ${{ steps.vet.outcome }}
114    steps:
115    - uses: actions/checkout@v4
116      with:
117        submodules: true
118    - uses: ./.github/actions/install-rust
119    - uses: ./.github/actions/install-cargo-vet
120    - id: vet
121      run: cargo vet --locked
122      continue-on-error: ${{ github.event_name == 'pull_request' }}
123
124    # Double-check that if versions are bumped that `cargo vet` still works.
125    # This is intended to weed out mistakes such as #9115 from happening again.
126    - run: rustc scripts/publish.rs && ./publish bump-patch && cargo vet
127      name: Ensure `cargo vet` works if versions are bumped
128
129  cargo_vet_failure_for_prs:
130    name: Cargo vet failed on a Pull Request
131    needs:
132    - determine
133    - cargo_vet
134    if: |
135      needs.determine.outputs.audit
136      && github.event_name == 'pull_request'
137      && needs.cargo_vet.outputs.outcome == 'failure'
138    runs-on: ubuntu-latest
139    steps:
140    # NB: this message ideally would link back to the previous step, but I'm not
141    # sure how to easily do that.
142    - run: |
143        echo 'failed to run "cargo vet", see previous `Cargo vet` step'
144        echo 'exiting with a nonzero status now to alert PR authors'
145        echo 'note, though, that this PR can still enter the merge queue'
146        echo ''
147        echo 'See https://docs.wasmtime.dev/contributing-coding-guidelines.html#cargo-vet-for-contributors'
148        echo 'for more information about the vetting process for Wasmtime'
149        exit 1
150
151  # This job is a dependency of many of the jobs below. This calculates what's
152  # actually being run for this workflow. For example:
153  #
154  # * Pushes to branches, which is currently both pushes to merge queue branches
155  #   as well as release branches, perform full CI.
156  # * PRs to release branches (not `main`) run full CI.
157  # * PRs to `main` will only run a few smoke tests above plus some elements of
158  #   the test matrix. The test matrix here is determined dynamically by the
159  #   `./ci/build-test-matrix.js` script given the commits that happened and
160  #   the files modified.
161  determine:
162    name: Determine CI jobs to run
163    runs-on: ubuntu-latest
164    outputs:
165      run-full: ${{ steps.calculate.outputs.run-full }}
166      test-matrix: ${{ steps.calculate.outputs.test-matrix }}
167      build-matrix: ${{ steps.calculate.outputs.build-matrix }}
168      test-capi: ${{ steps.calculate.outputs.test-capi }}
169      test-nightly: ${{ steps.calculate.outputs.test-nightly }}
170      test-miri: ${{ steps.calculate.outputs.test-miri }}
171      audit: ${{ steps.calculate.outputs.audit }}
172      preview1-adapter: ${{ steps.calculate.outputs.preview1-adapter }}
173      run-dwarf: ${{ steps.calculate.outputs.run-dwarf }}
174      platform-checks: ${{ steps.calculate.outputs.platform-checks }}
175    steps:
176    - uses: actions/checkout@v4
177    - id: calculate
178      env:
179        GH_TOKEN: ${{ github.token }}
180      run: |
181        touch commits.log names.log
182        # Note that CI doesn't run on pushes to `main`, only pushes to merge
183        # queue branches and release branches, so this only runs full CI in
184        # those locations.
185        if [ "${{ github.event_name }}" != "pull_request" ]; then
186          run_full=true
187        else
188          pr=${{ github.event.number }}
189          gh pr view $pr --json commits | tee commits.log
190          gh pr diff $pr --name-only | tee names.log || echo "failed to get files"
191          if [ "${{ github.base_ref }}" != "main" ]; then
192            run_full=true
193          elif grep -q 'prtest:full' commits.log; then
194            run_full=true
195          elif grep -q 'prtest:debug' commits.log; then
196            echo run-dwarf=true >> $GITHUB_OUTPUT
197          elif grep -q 'prtest:platform-checks' commits.log; then
198            echo platform-checks=true >> $GITHUB_OUTPUT
199          elif grep -q 'prtest:miri' commits.log; then
200            echo test-miri=true >> $GITHUB_OUTPUT
201          fi
202          if grep -q crates.c-api names.log; then
203            echo test-capi=true >> $GITHUB_OUTPUT
204          fi
205          if grep -q fuzz names.log; then
206            echo test-nightly=true >> $GITHUB_OUTPUT
207          fi
208          if grep -q sys.custom names.log; then
209            echo test-nightly=true >> $GITHUB_OUTPUT
210          fi
211          if grep -q Cargo.lock names.log; then
212            echo audit=true >> $GITHUB_OUTPUT
213          fi
214          if grep -q supply-chain names.log; then
215            echo audit=true >> $GITHUB_OUTPUT
216          fi
217          if grep -q component-adapter names.log; then
218            echo preview1-adapter=true >> $GITHUB_OUTPUT
219          fi
220          if grep -q debug names.log; then
221            echo run-dwarf=true >> $GITHUB_OUTPUT
222          fi
223          if grep -q pulley names.log; then
224            echo test-nightly=true >> $GITHUB_OUTPUT
225          fi
226        fi
227        matrix="$(node ./ci/build-test-matrix.js ./commits.log ./names.log $run_full)"
228        echo "test-matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
229        echo "$matrix"
230
231        matrix="$(node ./ci/build-build-matrix.js)"
232        echo "build-matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
233
234        if [ "$run_full" = "true" ]; then
235            echo run-full=true >> $GITHUB_OUTPUT
236            echo test-capi=true >> $GITHUB_OUTPUT
237            echo test-nightly=true >> $GITHUB_OUTPUT
238            echo test-miri=true >> $GITHUB_OUTPUT
239            echo audit=true >> $GITHUB_OUTPUT
240            echo preview1-adapter=true >> $GITHUB_OUTPUT
241            echo run-dwarf=true >> $GITHUB_OUTPUT
242            echo platform-checks=true >> $GITHUB_OUTPUT
243        fi
244
245  # Build all documentation of Wasmtime, including the C API documentation,
246  # mdbook documentation, etc. This produces a `gh-pages` artifact which is what
247  # gets uploaded to the `gh-pages` branch later on.
248  doc:
249    needs: determine
250    if: needs.determine.outputs.run-full
251    name: Doc build
252    runs-on: ubuntu-latest
253    env:
254      CARGO_MDBOOK_VERSION: 0.4.37
255      RUSTDOCFLAGS: -Dbroken_intra_doc_links --cfg docsrs
256      OPENVINO_SKIP_LINKING: 1
257    steps:
258    - uses: actions/checkout@v4
259      with:
260        submodules: true
261    - uses: ./.github/actions/install-rust
262      with:
263        toolchain: wasmtime-ci-pinned-nightly
264
265    # Build C API documentation
266    - run: curl -L https://github.com/doxygen/doxygen/releases/download/Release_1_9_3/doxygen-1.9.3.linux.bin.tar.gz | tar xzf -
267    - run: echo "`pwd`/doxygen-1.9.3/bin" >> $GITHUB_PATH
268    - run: cmake -S crates/c-api -B target/c-api
269    - run: cmake --build target/c-api --target doc
270
271    # install mdbook, build the docs, and test the docs
272    - uses: actions/cache@v4
273      with:
274        path: ${{ runner.tool_cache }}/mdbook
275        key: cargo-mdbook-bin-${{ env.CARGO_MDBOOK_VERSION }}
276    - run: |
277        echo "${{ runner.tool_cache }}/mdbook/bin" >> $GITHUB_PATH
278        cargo install --root ${{ runner.tool_cache }}/mdbook --version ${{ env.CARGO_MDBOOK_VERSION }} mdbook --locked
279    - run: (cd docs && mdbook build)
280    - run: cargo build -p wasi-common --features wasmtime/wat,wasmtime/cranelift
281    - run: (cd docs && mdbook test -L ../target/debug/deps)
282
283    # Build Rust API documentation.
284    #
285    # Enable extra features in crates as well to ensure they're documented
286    - run: |
287        cargo doc --no-deps --workspace \
288          --exclude wasmtime-cli \
289          --exclude test-programs \
290          --exclude cranelift-codegen-meta \
291          --features call-hook
292      env:
293        RUSTDOCFLAGS: --cfg=docsrs
294    - run: cargo doc --package cranelift-codegen-meta --document-private-items
295      env:
296        RUSTDOCFLAGS: --cfg=docsrs
297
298    # Assemble the documentation, and always upload it as an artifact for
299    # inspection on PRs and such.
300    - run: |
301        mv docs/book gh-pages
302        mv crates/c-api/html gh-pages/c-api
303        mv target/doc gh-pages/api
304        tar czf gh-pages.tar.gz gh-pages
305    - uses: actions/upload-artifact@v4
306      with:
307        name: gh-pages
308        path: gh-pages.tar.gz
309
310  # Checks of various feature combinations and whether things compile. The goal
311  # here isn't to run tests, mostly just serve as a double-check that Rust code
312  # compiles and is likely to work everywhere else.
313  micro_checks:
314    name: Check ${{matrix.name}}
315    strategy:
316      fail-fast: true
317      matrix:
318        include:
319          - name: wasmtime
320            checks: |
321              -p wasmtime --no-default-features
322              -p wasmtime --no-default-features --features wat
323              -p wasmtime --no-default-features --features profiling
324              -p wasmtime --no-default-features --features cache
325              -p wasmtime --no-default-features --features async
326              -p wasmtime --no-default-features --features std
327              -p wasmtime --no-default-features --features pooling-allocator
328              -p wasmtime --no-default-features --features cranelift
329              -p wasmtime --no-default-features --features component-model
330              -p wasmtime --no-default-features --features component-model-async
331              -p wasmtime --no-default-features --features runtime,component-model
332              -p wasmtime --no-default-features --features cranelift,wat,async,std,cache
333              -p wasmtime --no-default-features --features winch
334              -p wasmtime --no-default-features --features wmemcheck
335              -p wasmtime --no-default-features --features wmemcheck,cranelift,runtime
336              -p wasmtime --no-default-features --features demangle
337              -p wasmtime --no-default-features --features addr2line
338              -p wasmtime --no-default-features --features gc
339              -p wasmtime --no-default-features --features runtime,gc
340              -p wasmtime --no-default-features --features cranelift,gc
341              -p wasmtime --no-default-features --features gc-drc
342              -p wasmtime --no-default-features --features runtime,gc-drc
343              -p wasmtime --no-default-features --features cranelift,gc-drc
344              -p wasmtime --no-default-features --features gc-null
345              -p wasmtime --no-default-features --features runtime,gc-null
346              -p wasmtime --no-default-features --features cranelift,gc-null
347              -p wasmtime --no-default-features --features runtime
348              -p wasmtime --no-default-features --features threads
349              -p wasmtime --no-default-features --features runtime,threads
350              -p wasmtime --no-default-features --features cranelift,threads
351              -p wasmtime --no-default-features --features stack-switching
352              -p wasmtime --no-default-features --features cranelift,stack-switching
353              -p wasmtime --no-default-features --features runtime,stack-switching
354              -p wasmtime --features incremental-cache
355              -p wasmtime --features profile-pulley
356              -p wasmtime --all-features
357
358          - name: wasmtime-fiber
359            checks: |
360              -p wasmtime-internal-fiber --no-default-features
361              -p wasmtime-internal-fiber --no-default-features --features std
362              -p wasmtime-internal-fiber --all-features
363
364          - name: wasmtime-cli
365            checks: |
366              -p wasmtime-cli --no-default-features
367              -p wasmtime-cli --no-default-features --features pooling-allocator
368              -p wasmtime-cli --no-default-features --features run
369              -p wasmtime-cli --no-default-features --features run,component-model
370              -p wasmtime-cli --no-default-features --features run,pooling-allocator
371              -p wasmtime-cli --no-default-features --features compile
372              -p wasmtime-cli --no-default-features --features compile,cranelift
373              -p wasmtime-cli --no-default-features --features compile,cranelift,component-model
374              -p wasmtime-cli --no-default-features --features objdump
375              -p wasmtime-cli --all-features
376              -p wasmtime-cli --features component-model
377
378          - name: cranelift-codegen
379            checks: |
380              -p cranelift-codegen --benches
381              -p cranelift-codegen --no-default-features --features std,unwind,pulley
382
383          - name: cranelift-entity
384            checks: |
385              -p cranelift-entity --no-default-features
386              -p cranelift-entity --no-default-features --features enable-serde
387
388          - name: wasmtime-bench-api
389            checks: |
390              -p wasmtime-bench-api
391
392          - name: wasmtime-c-api
393            checks: |
394              -p wasmtime-c-api --no-default-features
395              -p wasmtime-c-api --no-default-features --features wat
396              -p wasmtime-c-api --no-default-features --features wasi
397    runs-on: ubuntu-latest
398    steps:
399    - uses: actions/checkout@v4
400      with:
401        submodules: true
402    - uses: ./.github/actions/install-rust
403
404    # Run the check.
405    - run: |
406        checks=$(cat <<END
407        ${{ matrix.checks }}
408        END
409        )
410        echo "$checks" | xargs -I CHECK sh -c 'echo "=== cargo check CHECK ==="; cargo check CHECK'
411
412  special_tests:
413    name: One-off special tests
414    runs-on: ubuntu-latest
415    needs: determine
416    if: needs.determine.outputs.run-full
417    steps:
418    - uses: actions/checkout@v4
419      with:
420        submodules: true
421    - uses: ./.github/actions/install-rust
422    - run: cargo test -p wasmtime-internal-fiber --no-default-features
423    - run: cargo test -p cranelift-tools --test logged-filetests
424
425  # Check that Clippy lints are passing.
426  clippy:
427    name: Clippy
428    runs-on: ubuntu-latest
429    env:
430      CARGO_NDK_VERSION: 2.12.2
431    steps:
432    - uses: actions/checkout@v4
433      with:
434        submodules: true
435    - uses: ./.github/actions/install-rust
436
437    - run: rustup component add clippy
438    - run: cargo clippy --workspace --all-targets
439
440  # Similar to `micro_checks` but where we need to install some more state
441  # (e.g. Android NDK) and we haven't factored support for those things out into
442  # a parallel jobs yet.
443  monolith_checks:
444    name: Monolith Checks
445    runs-on: ubuntu-latest
446    env:
447      CARGO_NDK_VERSION: 2.12.2
448    steps:
449    - uses: actions/checkout@v4
450      with:
451        submodules: true
452    - uses: ./.github/actions/install-rust
453
454    # Check that wasmtime compiles with panic=abort since there's some `#[cfg]`
455    # for specifically panic=abort there.
456    - run: cargo check -p wasmtime
457      env:
458        RUSTFLAGS: -Cpanic=abort
459
460    # Check a few builds of the cranelift backend
461    # - only x86 backend support,
462    # - only arm64 backend support,
463    # - no debug_assertions.
464    - run: cargo check --manifest-path=./cranelift/Cargo.toml --bin clif-util --no-default-features --features=cranelift-codegen/arm64
465    - run: cargo check --manifest-path=./cranelift/Cargo.toml --bin clif-util --no-default-features --features=cranelift-codegen/x86
466    - run: cargo check --manifest-path=./cranelift/Cargo.toml --bin clif-util
467      env:
468        CARGO_PROFILE_DEV_DEBUG_ASSERTIONS: false
469
470    # Re-vendor all WIT files and ensure that they're all up-to-date by ensuring
471    # that there's no git changes.
472    - name: Re-vendor WIT
473      run: ./ci/vendor-wit.sh
474    - run: git diff --exit-code
475
476    # Re-vendor the C API and make sure it's up-to-date.
477    - name: Re-vendor C API
478      run: ./ci/vendor-c-api-headers.sh
479    - run: git diff --exit-code
480
481  # Various checks that Wasmtime builds for a variety of platforms. Each
482  # platform may not include the entire dependency tree and maybe just a few
483  # features here and there, see the `include` matrix for more details.
484  platform_checks:
485    needs: determine
486    if: needs.determine.outputs.platform-checks
487    name: "Platform: ${{ matrix.target }}"
488    runs-on: ${{ matrix.os }}
489    strategy:
490      fail-fast: true
491      matrix:
492        include:
493        - target: x86_64-unknown-freebsd
494          os: ubuntu-latest
495          test: cargo check
496        - target: aarch64-pc-windows-msvc
497          os: windows-latest
498          test: cargo check
499        # While we're here testing a windows target also test a feature'd build
500        # on Windows. Note that this isn't covered by `micro_checks` above since
501        # that's for unix platforms, not Windows, so include a small check here
502        # which isn't the full `micro_checks` matrix but hopefully enough bang
503        # for our buck.
504        - target: i686-pc-windows-msvc
505          os: windows-latest
506          test: cargo check && cargo build -p wasmtime --no-default-features --features runtime
507        # This is used for general compatibility with `#![no_std]` targets and a
508        # variety of crates are tested here.
509        - target: x86_64-unknown-none
510          os: ubuntu-latest
511          test: >
512            cargo check -p wasmtime --no-default-features --features runtime,component-model &&
513            cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async &&
514            cargo check -p cranelift-control --no-default-features &&
515            cargo check -p pulley-interpreter --features encode,decode,disas,interp &&
516            cargo check -p wasmtime-wasi-io --no-default-features
517        # Use `cross` for illumos to have a C compiler/linker available.
518        - target: x86_64-unknown-illumos
519          os: ubuntu-latest
520          cross: true
521          test: cross build
522        - target: wasm32-wasip1
523          os: ubuntu-latest
524          test: cargo build --no-default-features --features compile,cranelift,all-arch
525        - target: aarch64-apple-ios
526          os: macos-latest
527          test: cargo build
528          env:
529            IPHONEOS_DEPLOYMENT_TARGET: 13.0
530        # Test that when Cranelift has no support for an architecture, even a
531        # 64-bit one, that Wasmtime still compiles. Note that this is also
532        # intended to test various fallbacks in the codebase where we have no
533        # support at all for a particular architecture. In theory if someone
534        # adds powerpc64 support to Wasmtime this should get switched to some
535        # other architecture.
536        - target: powerpc64le-unknown-linux-gnu
537          os: ubuntu-latest
538          test: cargo build
539          apt_packages: gcc-powerpc64le-linux-gnu
540          env:
541            CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_LINKER: powerpc64le-linux-gnu-gcc
542        # A no_std target without 64-bit atomics
543        - target: riscv32imac-unknown-none-elf
544          os: ubuntu-latest
545          test: cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async
546    env: ${{ matrix.env || fromJSON('{}') }}
547    steps:
548    - uses: actions/checkout@v4
549      with:
550        submodules: true
551    - uses: ./.github/actions/install-rust
552    - run: rustup target add ${{ matrix.target }}
553    - name: Install cross
554      run: |
555        curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
556        cargo binstall --no-confirm cross
557      if: ${{ matrix.cross }}
558    - name: Install apt packages
559      if: ${{ matrix.apt_packages }}
560      run: sudo apt-get update && sudo apt-get install -y ${{ matrix.apt_packages }}
561    - run: ${{ matrix.test }}
562      env:
563        CARGO_BUILD_TARGET: ${{ matrix.target }}
564
565  # Run tests that require a nightly compiler, such as building fuzz targets.
566  test_nightly:
567    needs: determine
568    if: needs.determine.outputs.test-nightly
569    name: Nightly tests
570    runs-on: ubuntu-latest
571    steps:
572    - uses: actions/checkout@v4
573      with:
574        submodules: true
575    # Note that nightly is pinned here to insulate us from breakage that might
576    # happen upstream. This is periodically updated through a PR.
577    - uses: ./.github/actions/install-rust
578      with:
579        toolchain: wasmtime-ci-pinned-nightly
580
581    # Check that `pulley-interpreter` compiles with tail calls enabled.  Don't
582    # actually run the tests with tail calls enabled, because they are not yet
583    # implemented in rustc and cause an ICE.
584    - run: cargo check -p pulley-interpreter --all-features
585      env:
586        RUSTFLAGS: "--cfg pulley_tail_calls"
587    - run: cargo check -p pulley-interpreter --all-features
588      env:
589        RUSTFLAGS: "--cfg pulley_disable_interp_simd"
590    - run: cargo test -p pulley-interpreter --all-features --release
591      env:
592        RUSTFLAGS: "--cfg pulley_assume_llvm_makes_tail_calls"
593
594    # Ensure that fuzzers still build.
595    #
596    # Install the OCaml packages necessary for fuzz targets that use the
597    # `wasm-spec-interpreter`.
598    - run: cargo install cargo-fuzz --vers "^0.11" --locked
599    - run: sudo apt-get update && sudo apt install -y ocaml-nox ocamlbuild ocaml-findlib libzarith-ocaml-dev
600    - run: cargo fetch
601      working-directory: ./fuzz
602    - run: cargo fuzz build --dev
603    - run: cargo fuzz build --dev --fuzz-dir ./cranelift/isle/fuzz
604    - run: cargo fuzz build --dev --fuzz-dir ./crates/environ/fuzz --features component-model
605    - run: cargo fuzz build --dev --fuzz-dir ./cranelift/assembler-x64/fuzz
606
607  # Perform all tests of the c-api
608  test_capi:
609    needs: determine
610    name: Test C-API ${{ matrix.os }}
611    runs-on: ${{ matrix.os }}
612    if: needs.determine.outputs.test-capi
613
614    strategy:
615      fail-fast: true
616      matrix:
617        os: [ubuntu-24.04, macos-15, windows-2025]
618
619    steps:
620    - uses: actions/checkout@v4
621      with:
622        submodules: true
623    - uses: ./.github/actions/install-rust
624
625    # Build and test the C API with example C programs along with the example
626    # Rust programs. Note that this only executes if the `determine` step told
627    # us to test the capi which is off-by-default for PRs.
628    - run: rustup target add wasm32-wasip2 # wasip2 target needed by example programs
629    - run: cmake -Sexamples -Bexamples/build -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=ON
630    - run: cmake --build examples/build --config Debug
631    - run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target RUN_TESTS
632      if: runner.os == 'Windows'
633    - run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target test
634      if: runner.os != 'Windows'
635
636  # Perform all tests (debug mode) for `wasmtime`.
637  #
638  # Note that the full matrix for what may run here is defined within
639  # `./ci/build-test-matrix.js` and the execution of the `determine` step will
640  # calculate whether the tests are actually run as part of PRs and such.
641  test:
642    needs: determine
643    name: ${{ matrix.name }}
644    runs-on: ${{ matrix.os }}
645    env:
646      QEMU_BUILD_VERSION: 9.1.2
647    strategy:
648      fail-fast: ${{ github.event_name != 'pull_request' }}
649      matrix: ${{ fromJson(needs.determine.outputs.test-matrix) }}
650    steps:
651    - uses: actions/checkout@v4
652      with:
653        submodules: true
654    - uses: ./.github/actions/install-rust
655      with:
656        toolchain: ${{ matrix.rust }}
657
658    # Install targets in order to build various tests throughout the repo
659    - run: rustup target add wasm32-wasip1 wasm32-unknown-unknown ${{ matrix.target }}
660    - run: echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
661      if: matrix.target != ''
662
663    # Fix an ICE for now in gcc when compiling zstd with debuginfo (??)
664    - run: echo CFLAGS=-g0 >> $GITHUB_ENV
665      if: matrix.target == 'x86_64-pc-windows-gnu'
666
667    # Update binutils if MinGW due to https://github.com/rust-lang/rust/issues/112368
668    - run: C:/msys64/usr/bin/pacman.exe -S --needed mingw-w64-x86_64-gcc --noconfirm
669      if: matrix.target == 'x86_64-pc-windows-gnu'
670    - shell: pwsh
671      run: echo "C:\msys64\mingw64\bin" >> $Env:GITHUB_PATH
672      if: matrix.target == 'x86_64-pc-windows-gnu'
673
674    - run: cargo fetch --locked
675
676    - name: Install cross-compilation tools
677      run: |
678        set -ex
679
680        sudo apt-get update
681        sudo apt-get install -y ${{ matrix.gcc_package }}
682
683        # Configure Cargo for cross compilation and tell it how it can run
684        # cross executables
685        upcase=$(echo ${{ matrix.target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
686        echo CARGO_TARGET_${upcase}_LINKER=${{ matrix.gcc }} >> $GITHUB_ENV
687      if: matrix.gcc != ''
688
689    - uses: actions/cache@v4
690      with:
691        path: ${{ runner.tool_cache }}/qemu
692        key: qemu-${{ matrix.target }}-${{ env.QEMU_BUILD_VERSION }}-patchcpuinfo
693      if: matrix.qemu != ''
694    - name: Install qemu
695      run: |
696        set -ex
697
698        upcase=$(echo ${{ matrix.target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
699        echo CARGO_TARGET_${upcase}_RUNNER=${{ runner.tool_cache }}/qemu/bin/${{ matrix.qemu }} >> $GITHUB_ENV
700
701        # QEMU emulation is not always the speediest, so total testing time
702        # goes down if we build the libs in release mode when running tests.
703        echo CARGO_PROFILE_DEV_OPT_LEVEL=2 >> $GITHUB_ENV
704
705        # See comments in the source for why we enable this during QEMU
706        # emulation.
707        echo WASMTIME_TEST_NO_HOG_MEMORY=1 >> $GITHUB_ENV
708
709        # See if qemu is already in the cache
710        if [ -f ${{ runner.tool_cache }}/qemu/built ]; then
711          exit 0
712        fi
713
714        # Install build dependencies of QEMU itself.
715        sudo apt-get install -y libglib2.0-dev ninja-build
716
717        # Download and build qemu from source since the most recent release is
718        # way faster at arm emulation than the current version github actions'
719        # ubuntu image uses. Disable as much as we can to get it to build
720        # quickly.
721        curl https://download.qemu.org/qemu-$QEMU_BUILD_VERSION.tar.xz | tar xJf -
722        cd qemu-$QEMU_BUILD_VERSION
723        ./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache}}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
724        ninja -C build install
725        touch ${{ runner.tool_cache }}/qemu/built
726      if: matrix.qemu != ''
727
728    - name: Configure ASAN
729      run: |
730        echo CARGO_PROFILE_DEV_OPT_LEVEL=2 >> $GITHUB_ENV
731        echo CARGO_PROFILE_TEST_OPT_LEVEL=2 >> $GITHUB_ENV
732        echo RUSTFLAGS=-Zsanitizer=address >> $GITHUB_ENV
733        echo RUSTDOCFLAGS="-Zsanitizer=address -Copt-level=2 -Ccodegen-units=16" >> $GITHUB_ENV
734      if: ${{ contains(matrix.name, 'ASAN') }}
735
736    # Record some CPU details; this is helpful information if tests fail due
737    # to CPU-specific features.
738    - name: CPU information
739      run: lscpu
740      if: runner.os == 'Linux'
741    - name: CPU information
742      run: sysctl hw
743      if: runner.os == 'macOS'
744    - name: CPU information
745      run: Get-WmiObject Win32_Processor
746      shell: pwsh
747      if: runner.os == 'Windows'
748
749    # Since MPK (PKU) is not present on some GitHub runners, we check if it is
750    # available before force-enabling it. This occasional testing is better than
751    # none at all; ideally we would test in a system-mode QEMU VM.
752    - name: Force-run with MPK enabled, if available
753      if: ${{ contains(matrix.name, 'MPK') }}
754      run: |
755        if cargo run --example mpk-available; then
756          echo "::notice::This CI run will force-enable MPK; this ensures tests conditioned with the \`WASMTIME_TEST_FORCE_MPK\` environment variable will run with MPK-protected memory pool stripes."
757          echo WASMTIME_TEST_FORCE_MPK=1 >> $GITHUB_ENV
758        else
759          echo "::warning::This CI run will not test MPK; it has been detected as not available on this machine (\`cargo run --example mpk-available\`)."
760        fi
761
762    # Install VTune, see `cli_tests::profile_with_vtune`.
763    - name: Install VTune
764      if: matrix.filter == 'linux-x64' && contains(matrix.bucket, 'wasmtime-cli')
765      uses: abrown/install-vtune-action@v1
766
767    # Build and test all features.
768    #
769    # Note that this uses a different shell, notably not `bash` on Windows. In
770    # the past `bash` would add more items to `PATH` on Windows which would
771    # interfere and cause the `gcc.exe` executable to fail and exit with 1 and
772    # no output. It's believed that `bash` adds things like `/usr/bin` to PATH
773    # which is the wrong DLL or something like that.
774    - run: python3 ./ci/run-tests.py --locked ${{ matrix.bucket }}
775      shell: pwsh
776
777  # Test `wasmtime-wasi-nn` in its own job, as not all of its backends are
778  # compatible with all targets, and each must be tested separately anyways.
779  test_wasi_nn:
780    strategy:
781      matrix:
782        feature: ["openvino", "onnx-download"]
783        os: ["ubuntu-24.04", "windows-2025"]
784        include:
785          - os: windows-2025
786            feature: winml
787    name: Test wasi-nn (${{ matrix.feature }}, ${{ matrix.os }})
788    runs-on: ${{ matrix.os }}
789    needs: determine
790    if: needs.determine.outputs.run-full
791    steps:
792    - uses: actions/checkout@v4
793      with:
794        submodules: true
795    - uses: ./.github/actions/install-rust
796
797    # Install OpenVINO
798    - uses: abrown/install-openvino-action@v10
799      if: runner.arch == 'X64'
800
801    # Install WinML for testing wasi-nn WinML backend. WinML is only available
802    # on Windows clients and Windows Server with desktop experience enabled.
803    # GitHub Actions Window Server image doesn't have desktop experience
804    # enabled, so we download the standalone library from ONNX Runtime project.
805    - uses: nuget/setup-nuget@v2
806      if: (runner.os == 'Windows') && (matrix.feature == 'winml')
807    - run: nuget install Microsoft.AI.MachineLearning
808      if: (runner.os == 'Windows') && (matrix.feature == 'winml')
809
810    # Install Rust targets.
811    - run: rustup target add wasm32-wasip1
812
813    # Run the tests!
814    - run: cargo test -p wasmtime-wasi-nn --features ${{ matrix.feature }}
815
816  # Test `wasmtime-wasi-tls-nativetls` in its own job. This is because it
817  # depends on OpenSSL, which is not easily available on all platforms.
818  test_wasi_tls_nativetls:
819    name: Test wasi-tls using native-tls provider
820    needs: determine
821    if: needs.determine.outputs.run-full
822    runs-on: ${{ matrix.os }}
823    strategy:
824      matrix:
825        os: [ubuntu-latest, windows-latest, macos-latest]
826    steps:
827    - uses: actions/checkout@v4
828      with:
829        submodules: true
830    - uses: ./.github/actions/install-rust
831    - run: cargo test -p wasmtime-wasi-tls-nativetls
832
833  # Test the `wasmtime-fuzzing` crate. Split out from the main tests because
834  # `--all-features` brings in OCaml, which is a pain to get setup for all
835  # targets.
836  test_fuzzing:
837    needs: determine
838    if: needs.determine.outputs.run-full
839    name: Test wasmtime-fuzzing
840    runs-on: 'ubuntu-latest'
841    steps:
842    - uses: actions/checkout@v4
843      with:
844        submodules: true
845    - uses: ./.github/actions/install-rust
846
847    # Run the tests
848    - run: |
849        cargo test -p wasmtime-fuzzing -p wasm-spec-interpreter
850
851  # Test debug (DWARF) related functionality.
852  test_debug_dwarf:
853    needs: determine
854    if: needs.determine.outputs.run-dwarf
855    name: Test DWARF debugging
856    runs-on: ubuntu-24.04
857    steps:
858    - uses: actions/checkout@v4
859      with:
860        submodules: true
861    - uses: ./.github/actions/install-rust
862    - run: |
863        rustup target add wasm32-wasip1 wasm32-unknown-unknown
864        cd /tmp
865        curl -OL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz
866        tar -xzf wasi-sdk-25.0-x86_64-linux.tar.gz
867        mv wasi-sdk-25.0-x86_64-linux wasi-sdk
868    - run: |
869        sudo apt-get update && sudo apt-get install -y gdb lldb-18 llvm
870        # workaround for https://bugs.launchpad.net/ubuntu/+source/llvm-defaults/+bug/1972855
871        sudo mkdir -p /usr/lib/local/lib/python3.10/dist-packages/lldb
872        sudo ln -s /usr/lib/llvm-15/lib/python3.10/dist-packages/lldb/* /usr/lib/python3/dist-packages/lldb/
873        # Only testing release since it is more likely to expose issues with our low-level symbol handling.
874        cargo test --release --test all -- --ignored --test-threads 1 debug::
875      env:
876        LLDB: lldb-18
877        WASI_SDK_PATH: /tmp/wasi-sdk
878
879  build-preview1-component-adapter:
880    name: Build wasi-preview1-component-adapter
881    needs: determine
882    if: needs.determine.outputs.preview1-adapter
883    runs-on: ubuntu-latest
884    permissions:
885      deployments: write
886      contents: write
887    steps:
888    - uses: actions/checkout@v4
889      with:
890        submodules: true
891    - uses: ./.github/actions/install-rust
892    - run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
893
894    - name: Install wasm-tools
895      run: |
896        curl -L https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-1.0.27/wasm-tools-1.0.27-x86_64-linux.tar.gz | tar xfz -
897        echo `pwd`/wasm-tools-1.0.27-x86_64-linux >> $GITHUB_PATH
898
899    - run: ./ci/build-wasi-preview1-component-adapter.sh
900      env:
901        VERSION: ${{ github.sha }}
902
903    - uses: actions/upload-artifact@v4
904      with:
905        name: bins-wasi-preview1-component-adapter
906        path: target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.*.wasm
907
908  build-preview1-component-adapter-provider:
909    name: Build wasi-preview1-component-adapter-provider
910    needs: build-preview1-component-adapter
911    runs-on: ubuntu-latest
912    steps:
913    - uses: actions/checkout@v4
914      with:
915        submodules: true
916    - uses: ./.github/actions/install-rust
917    - uses: ./.github/actions/build-adapter-provider
918      with:
919        run-id: ${{ github.run_id }}
920
921  # Verify the "min platform" example still works.
922  test-min-platform-example:
923    name: Test the min-platform example
924    needs: determine
925    if: needs.determine.outputs.run-full
926    runs-on: ubuntu-latest
927    steps:
928    - uses: actions/checkout@v4
929      with:
930        submodules: true
931    - uses: ./.github/actions/install-rust
932    - run: cargo install cbindgen --vers "^0.28" --locked
933    - run: rustup target add x86_64-unknown-none
934    - run: rustup target add wasm32-wasip2
935    - run: ./build.sh x86_64-unknown-none
936      working-directory: ./examples/min-platform
937
938    # Afterwards make sure the generated header file is up to date by ensuring
939    # that the regeneration process didn't change anything in-tree.
940    - run: git diff --exit-code
941
942    # Test some other feature combinations
943    - run: ./build.sh x86_64-unknown-none
944      working-directory: ./examples/min-platform
945      env:
946        WASMTIME_SIGNALS_BASED_TRAPS: 1
947
948    - run: ./build.sh x86_64-unknown-none
949      working-directory: ./examples/min-platform
950      env:
951        WASMTIME_SIGNALS_BASED_TRAPS: 1
952        MIN_PLATFORM_TEST_DISABLE_WASI: 1
953
954    # Add the `wasmtime-platform.h` file as a release artifact
955    - uses: actions/upload-artifact@v4
956      with:
957        name: wasmtime-platform-header
958        path: examples/min-platform/embedding/wasmtime-platform.h
959
960  bench:
961    needs: determine
962    if: needs.determine.outputs.run-full
963    name: Run benchmarks
964    runs-on: ubuntu-latest
965    steps:
966    - uses: actions/checkout@v4
967      with:
968        submodules: true
969    - uses: ./.github/actions/install-rust
970    - run: rustup target add wasm32-wasip1
971    - run: cargo test --benches --release
972
973  # Verify that cranelift's code generation is deterministic
974  meta_deterministic_check:
975    needs: determine
976    if: needs.determine.outputs.run-full
977    name: Meta deterministic check
978    runs-on: ubuntu-latest
979    steps:
980    - uses: actions/checkout@v4
981      with:
982        submodules: true
983    - uses: ./.github/actions/install-rust
984    - run: cd cranelift/codegen && cargo build --features all-arch
985    - run: ci/ensure_deterministic_build.sh
986
987  verify-publish:
988    needs: determine
989    if: github.repository == 'bytecodealliance/wasmtime' && needs.determine.outputs.run-full
990    runs-on: ubuntu-latest
991    steps:
992    - uses: actions/checkout@v4
993      with:
994        submodules: true
995    - uses: ./.github/actions/install-rust
996    - run: |
997        cd ${{ runner.tool_cache }}
998        curl -L https://github.com/mozilla/sccache/releases/download/0.2.13/sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz | tar xzf -
999        echo "`pwd`/sccache-0.2.13-x86_64-unknown-linux-musl" >> $GITHUB_PATH
1000        echo RUSTC_WRAPPER=sccache >> $GITHUB_ENV
1001    - run: rustc scripts/publish.rs
1002    # Make sure the tree is publish-able as-is
1003    - run: ./publish verify
1004    # Make sure we can bump version numbers for the next release
1005    - run: ./publish bump
1006
1007  # Run a subset of tests under MIRI on CI to help check the `unsafe` code in
1008  # Wasmtime to make sure it's at least not obviously incorrect for basic usage.
1009  # Note that this doesn't run the full test suite since MIRI can't actually run
1010  # WebAssembly itself at this time (aka it doesn't support a JIT). There are a
1011  # number of annotations throughout the code which gates some tests on MIRI not
1012  # being run.
1013  #
1014  # Note that `cargo nextest` is used here additionally to get parallel test
1015  # execution by default to help cut down on the time in CI.
1016  miri:
1017    strategy:
1018      matrix:
1019        include:
1020          - crate: "wasmtime"
1021          - crate: "wasmtime-cli"
1022          - crate: "wasmtime-environ --all-features"
1023          - crate: "pulley-interpreter --all-features"
1024          - script: ./ci/miri-provenance-test.sh
1025    needs: determine
1026    if: needs.determine.outputs.test-miri && github.repository == 'bytecodealliance/wasmtime'
1027    name: Miri
1028    runs-on: ubuntu-latest
1029    env:
1030      CARGO_NEXTEST_VERSION: 0.9.88
1031      MIRIFLAGS: -Zmiri-permissive-provenance
1032    steps:
1033    - uses: actions/checkout@v4
1034      with:
1035        submodules: true
1036    - uses: ./.github/actions/install-rust
1037      with:
1038        toolchain: wasmtime-ci-pinned-nightly
1039    - run: rustup component add rust-src miri
1040    - uses: actions/cache@v4
1041      with:
1042        path: ${{ runner.tool_cache }}/cargo-nextest
1043        key: cargo-nextest-bin-${{ env.CARGO_NEXTEST_VERSION }}
1044    - run: echo "${{ runner.tool_cache }}/cargo-nextest/bin" >> $GITHUB_PATH
1045    - run: cargo install --root ${{ runner.tool_cache }}/cargo-nextest --version ${{ env.CARGO_NEXTEST_VERSION }} cargo-nextest --locked
1046    - run: |
1047        cargo miri nextest run -j4 --no-fail-fast -p ${{ matrix.crate }}
1048      if: ${{ matrix.crate }}
1049    - run: ${{ matrix.script }}
1050      if: ${{ matrix.script }}
1051
1052  # Perform release builds of `wasmtime` and `libwasmtime.so`. Builds a variety
1053  # of platforms and architectures and then uploads the release artifacts to
1054  # this workflow run's list of artifacts.
1055  #
1056  # Note that the full matrix is computed by `ci/build-build-matrix.js`.
1057  build:
1058    needs: determine
1059    if: needs.determine.outputs.run-full
1060    name: Release build for ${{ matrix.build }}
1061    runs-on: ${{ matrix.os }}
1062    strategy:
1063      fail-fast: ${{ github.event_name != 'pull_request' }}
1064      matrix: ${{ fromJson(needs.determine.outputs.build-matrix) }}
1065    env: ${{ matrix.env || fromJSON('{}') }}
1066    steps:
1067    - uses: actions/checkout@v4
1068      with:
1069        submodules: true
1070
1071    - uses: ./.github/actions/install-ninja
1072    - uses: ./.github/actions/install-rust
1073      with:
1074        toolchain: ${{ matrix.rust }}
1075    - run: |
1076        rustup component add rust-src
1077        rustup target add ${{ matrix.target }}
1078
1079    # On one builder produce the source tarball since there's no need to produce
1080    # it everywhere
1081    - run: ./ci/build-src-tarball.sh
1082      if: matrix.build == 'x86_64-linux'
1083
1084    - uses: ./.github/actions/android-ndk
1085      if: contains(matrix.target, 'android')
1086      with:
1087        target: ${{ matrix.target }}
1088
1089    - run: ./ci/build-release-artifacts.sh "${{ matrix.build }}" "${{ matrix.target }}"
1090
1091    # Assemble release artifacts appropriate for this platform, then upload them
1092    # unconditionally to this workflow's files so we have a copy of them.
1093    - run: ./ci/build-tarballs.sh "${{ matrix.build }}" "${{ matrix.target }}"
1094
1095    - uses: actions/upload-artifact@v4
1096      with:
1097        name: bins-${{ matrix.build }}
1098        path: dist
1099
1100  # This is a "join node" which depends on all prior workflows. The merge queue,
1101  # for example, gates on this to ensure that everything has executed
1102  # successfully.
1103  #
1104  # Note that this is required currently for odd reasons with github. Notably
1105  # the set of checks to enter the merge queue and leave the merge queue must
1106  # be the same which means that the "build" step for example shows as skipped
1107  # for PRs but expands to many different steps for merge-queue-based PRs. That
1108  # means that for that step there's no single name to gate on, so it's required
1109  # to have a "join" node here which joins everything.
1110  #
1111  # Note that this currently always runs to always report a status, even on
1112  # cancellation and even if dependency steps fail. Each dependency tries to
1113  # cancel the whole run if it fails, so if a test matrix entry fails, for
1114  # example, it cancels the build matrix entries too. This step then tries to
1115  # fail on cancellation to ensure that the dependency failures are propagated
1116  # correctly.
1117  ci-status:
1118    name: Record the result of testing and building steps
1119    runs-on: ubuntu-latest
1120    needs:
1121      - test
1122      - test_capi
1123      - test_debug_dwarf
1124      - test_fuzzing
1125      - test_wasi_nn
1126      - test_nightly
1127      - build
1128      - rustfmt
1129      - clangformat
1130      - cargo_deny
1131      - cargo_vet
1132      - doc
1133      - micro_checks
1134      - special_tests
1135      - test_wasi_tls_nativetls
1136      - clippy
1137      - monolith_checks
1138      - platform_checks
1139      - bench
1140      - meta_deterministic_check
1141      - verify-publish
1142      - determine
1143      - miri
1144      - build-preview1-component-adapter
1145      - build-preview1-component-adapter-provider
1146      - test-min-platform-example
1147      - check_js
1148    if: always()
1149    steps:
1150    - name: Successful test and build
1151      if: ${{ !(contains(needs.*.result, 'failure')) }}
1152      run: exit 0
1153    - name: Failing test and build
1154      if: ${{ contains(needs.*.result, 'failure') }}
1155      run: exit 1
1156    - name: Report failure on cancellation
1157      if: ${{ contains(needs.*.result, 'cancelled') || cancelled() }}
1158      run: exit 1
1159
1160  # The purpose of this jobs is to watch for changes on the `release-*`
1161  # branches of this repository and look for the term
1162  # "automatically-tag-and-release-this-commit" within merged PRs/commits. Once
1163  # that term is found the current version of `Cargo.toml`, the `wasmtime-cli`
1164  # Cargo.toml, is created as a tag and the tag is pushed to the repo.
1165  # Currently the tag is created through the GitHub API with an access token to
1166  # ensure that CI is further triggered for the tag itself which performs the
1167  # full release process.
1168  #
1169  # Note that this depends on the `ci-status` step above which is the "join"
1170  # point of this workflow for when everything succeeds. the purpose of that is
1171  # so that the tag is only created after the aftifacts have been uploaded for
1172  # this workflow as the `publish-artifacts.yml` workflow will download these
1173  # artifacts and then publish them to the tag.
1174  push-tag:
1175    runs-on: ubuntu-latest
1176    needs: ci-status
1177    if: |
1178      always()
1179      && needs.ci-status.result == 'success'
1180      && github.event_name == 'push'
1181      && startsWith(github.ref, 'refs/heads/release-')
1182      && github.repository == 'bytecodealliance/wasmtime'
1183    steps:
1184    - uses: actions/checkout@v4
1185      with:
1186        submodules: true
1187        fetch-depth: 0
1188    - name: Test if tag is needed
1189      run: |
1190        git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
1191        version=$(grep '^version =' Cargo.toml | head -n 1 | sed 's/.*"\(.*\)"/\1/')
1192        echo "version: $version"
1193        echo "version=$version" >> $GITHUB_OUTPUT
1194        echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
1195        if grep -q "automatically-tag-and-release-this-commit" main.log; then
1196          echo push-tag
1197          echo "push_tag=yes" >> $GITHUB_OUTPUT
1198        else
1199          echo no-push-tag
1200          echo "push_tag=no" >> $GITHUB_OUTPUT
1201        fi
1202      id: tag
1203    - name: Push the tag
1204      run: |
1205        git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
1206        curl -iX POST $git_refs_url \
1207          -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
1208          -d @- << EOF
1209        {
1210          "ref": "refs/tags/v${{ steps.tag.outputs.version }}",
1211          "sha": "${{ steps.tag.outputs.sha }}"
1212        }
1213        EOF
1214      if: steps.tag.outputs.push_tag == 'yes'
1215
1216  # File an issue on the repo if this run failed and was triggered via
1217  # `workflow_dispatch`, which mostly means that
1218  # `.github/workflows/trigger-release-branch-ci.yml` will file issues on
1219  # failure so we get to see a notification when a build fails for a historical
1220  # release branch.
1221  file-issue-on-error:
1222    name: File an issue if this build failed and was cron-triggered
1223    runs-on: ubuntu-latest
1224    needs: ci-status
1225    if: |
1226      always()
1227      && needs.ci-status.result != 'success'
1228      && github.event_name == 'workflow_dispatch'
1229    permissions:
1230      issues: write
1231    steps:
1232    - uses: actions/github-script@v7
1233      with:
1234        script: |
1235          github.rest.issues.create({
1236            owner: context.repo.owner,
1237            repo: context.repo.repo,
1238            title: `Failed CI build for ${context.ref}`,
1239            body: `See https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
1240          })
1241