|
| 1 | +name: Publish runtime Wasm |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + COMPONENT_NAME: componentize-qjs-runtime |
| 13 | + COMPONENT_DESCRIPTION: QuickJS runtime for componentize-qjs |
| 14 | + COMPONENT_SOURCE: https://github.com/${{ github.repository }} |
| 15 | + COMPONENT_HOMEPAGE: https://github.com/${{ github.repository }} |
| 16 | + COMPONENT_LICENSES: Apache-2.0 |
| 17 | + WASM_FILE: dist/componentize_qjs_runtime.wasm |
| 18 | + SBOM_FILE: dist/componentize_qjs_runtime.wasm.cdx.json |
| 19 | + |
| 20 | +jobs: |
| 21 | + publish: |
| 22 | + name: Publish runtime Wasm |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + id-token: write |
| 26 | + packages: write |
| 27 | + contents: read |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install Rust |
| 34 | + uses: dtolnay/rust-toolchain@stable |
| 35 | + with: |
| 36 | + targets: wasm32-wasip2 |
| 37 | + |
| 38 | + - name: Install cargo-binstall |
| 39 | + uses: cargo-bins/cargo-binstall@v1.10.15 |
| 40 | + |
| 41 | + - name: Cache cargo |
| 42 | + uses: Swatinem/rust-cache@v2 |
| 43 | + |
| 44 | + - name: Docker meta |
| 45 | + id: meta |
| 46 | + uses: docker/metadata-action@v5 |
| 47 | + with: |
| 48 | + images: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }} |
| 49 | + tags: | |
| 50 | + type=semver,pattern={{version}} |
| 51 | +
|
| 52 | + - name: Login to GitHub Container Registry |
| 53 | + if: github.event_name != 'workflow_dispatch' |
| 54 | + uses: docker/login-action@v3 |
| 55 | + with: |
| 56 | + registry: ghcr.io |
| 57 | + username: ${{ github.actor }} |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + - name: Install cosign |
| 61 | + if: github.event_name != 'workflow_dispatch' |
| 62 | + uses: sigstore/cosign-installer@v3.7.0 |
| 63 | + |
| 64 | + - name: Install publish tools |
| 65 | + run: | |
| 66 | + cargo binstall wkg --force |
| 67 | + cargo binstall cargo-auditable --force |
| 68 | + cargo binstall auditable2cdx --force |
| 69 | +
|
| 70 | + - name: Build auditable runtime |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + rm -rf crates/core/prebuilt dist target/runtime-publish |
| 74 | + COMPONENTIZE_QJS_RUNTIME_AUDITABLE=1 cargo build --release -p componentize-qjs --target-dir target/runtime-publish |
| 75 | + mkdir -p dist |
| 76 | + mapfile -t runtimes < <(find target/runtime-publish -path '*/out/runtime.wasm' -type f | sort) |
| 77 | + test "${#runtimes[@]}" -eq 1 || { printf 'ERROR: expected exactly one runtime.wasm, found %s\n' "${#runtimes[@]}"; printf '%s\n' "${runtimes[@]}"; exit 1; } |
| 78 | + cp "${runtimes[0]}" "${WASM_FILE}" |
| 79 | + sha256sum "${WASM_FILE}" > "${WASM_FILE}.sha256" |
| 80 | + auditable2cdx "${WASM_FILE}" > "${SBOM_FILE}" |
| 81 | + test -s "${SBOM_FILE}" || { echo "ERROR: runtime SBOM is empty"; exit 1; } |
| 82 | + echo "Runtime ready at ${WASM_FILE} ($(wc -c < "${WASM_FILE}") bytes)" |
| 83 | +
|
| 84 | + - name: Upload runtime artifacts |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: componentize-qjs-runtime |
| 88 | + path: | |
| 89 | + ${{ env.WASM_FILE }} |
| 90 | + ${{ env.WASM_FILE }}.sha256 |
| 91 | + ${{ env.SBOM_FILE }} |
| 92 | + if-no-files-found: error |
| 93 | + |
| 94 | + - name: Publish `:<version>` to GitHub Container Registry |
| 95 | + if: github.event_name != 'workflow_dispatch' |
| 96 | + id: publish_versioned |
| 97 | + uses: bytecodealliance/wkg-github-action@v5 |
| 98 | + with: |
| 99 | + file: ${{ env.WASM_FILE }} |
| 100 | + oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }} |
| 101 | + version: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} |
| 102 | + description: ${{ env.COMPONENT_DESCRIPTION }} |
| 103 | + source: ${{ env.COMPONENT_SOURCE }} |
| 104 | + homepage: ${{ env.COMPONENT_HOMEPAGE }} |
| 105 | + licenses: ${{ env.COMPONENT_LICENSES }} |
| 106 | + |
| 107 | + - name: Sign the versioned runtime |
| 108 | + if: github.event_name != 'workflow_dispatch' |
| 109 | + run: cosign sign --yes ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}@${{ steps.publish_versioned.outputs.digest }} |
| 110 | + |
| 111 | + - name: Attest the versioned runtime SBOM |
| 112 | + if: github.event_name != 'workflow_dispatch' |
| 113 | + run: cosign attest --yes --type cyclonedx --predicate "${SBOM_FILE}" ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}@${{ steps.publish_versioned.outputs.digest }} |
| 114 | + |
| 115 | + - name: Publish `:latest` to GitHub Container Registry |
| 116 | + if: github.event_name != 'workflow_dispatch' |
| 117 | + id: publish_latest |
| 118 | + uses: bytecodealliance/wkg-github-action@v5 |
| 119 | + with: |
| 120 | + file: ${{ env.WASM_FILE }} |
| 121 | + oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }} |
| 122 | + version: latest |
| 123 | + description: ${{ env.COMPONENT_DESCRIPTION }} |
| 124 | + source: ${{ env.COMPONENT_SOURCE }} |
| 125 | + homepage: ${{ env.COMPONENT_HOMEPAGE }} |
| 126 | + licenses: ${{ env.COMPONENT_LICENSES }} |
| 127 | + |
| 128 | + - name: Sign the latest runtime |
| 129 | + if: github.event_name != 'workflow_dispatch' |
| 130 | + run: cosign sign --yes ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}@${{ steps.publish_latest.outputs.digest }} |
| 131 | + |
| 132 | + - name: Attest the latest runtime SBOM |
| 133 | + if: github.event_name != 'workflow_dispatch' |
| 134 | + run: cosign attest --yes --type cyclonedx --predicate "${SBOM_FILE}" ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}@${{ steps.publish_latest.outputs.digest }} |
0 commit comments