|
| 1 | +name: Publish Component |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'component-*-v[0-9]+.[0-9]+.[0-9]+-?**' |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + id-token: write |
| 13 | + packages: write |
| 14 | + contents: read |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v6 |
| 18 | + |
| 19 | + - name: Parse tag |
| 20 | + id: parse |
| 21 | + run: | |
| 22 | + tag="${GITHUB_REF#refs/tags/}" |
| 23 | + rest="${tag#component-}" |
| 24 | + name="${rest%-v*}" |
| 25 | + version="${rest##*-v}" |
| 26 | + echo "name=$name" >> "$GITHUB_OUTPUT" |
| 27 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 28 | +
|
| 29 | + - name: Read component metadata |
| 30 | + id: meta |
| 31 | + working-directory: components |
| 32 | + run: | |
| 33 | + name="${{ steps.parse.outputs.name }}" |
| 34 | + version="${{ steps.parse.outputs.version }}" |
| 35 | + json=$(cargo metadata --no-deps --format-version 1 \ |
| 36 | + | jq --arg n "$name" '.packages[] | select(.name == $n)') |
| 37 | + if [ -z "$json" ]; then |
| 38 | + echo "Component '$name' not found in cargo workspace" >&2 |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + manifest_version=$(echo "$json" | jq -r '.version') |
| 42 | + if [ "$manifest_version" != "$version" ]; then |
| 43 | + echo "Tag version ($version) does not match Cargo.toml version ($manifest_version) for $name" >&2 |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + description=$(echo "$json" | jq -r '.description // ""') |
| 47 | + homepage=$(echo "$json" | jq -r '.homepage // ""') |
| 48 | + repository=$(echo "$json" | jq -r '.repository // ""') |
| 49 | + license=$(echo "$json" | jq -r '.license // ""') |
| 50 | + for field in description homepage repository license; do |
| 51 | + if [ -z "${!field}" ]; then |
| 52 | + echo "Component '$name' is missing '$field' in Cargo.toml" >&2 |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + done |
| 56 | + echo "description=$description" >> "$GITHUB_OUTPUT" |
| 57 | + echo "homepage=$homepage" >> "$GITHUB_OUTPUT" |
| 58 | + echo "source=$repository" >> "$GITHUB_OUTPUT" |
| 59 | + echo "license=$license" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Add wasm32-unknown-unknown target |
| 62 | + run: rustup target add wasm32-unknown-unknown |
| 63 | + |
| 64 | + - name: Install cargo-binstall |
| 65 | + uses: cargo-bins/cargo-binstall@v1 |
| 66 | + |
| 67 | + - name: Install build tools |
| 68 | + run: | |
| 69 | + cargo binstall cargo-auditable --no-confirm |
| 70 | + cargo binstall auditable2cdx --no-confirm |
| 71 | + cargo binstall wasm-tools --no-confirm |
| 72 | +
|
| 73 | + - name: Build core wasm with cargo-auditable |
| 74 | + working-directory: components |
| 75 | + run: cargo auditable build -p ${{ steps.parse.outputs.name }} --target wasm32-unknown-unknown --release |
| 76 | + |
| 77 | + - name: Wrap as wasm component |
| 78 | + working-directory: components |
| 79 | + run: | |
| 80 | + name="${{ steps.parse.outputs.name }}" |
| 81 | + cargo_name="${name//-/_}" |
| 82 | + wasm-tools component new \ |
| 83 | + "target/wasm32-unknown-unknown/release/${cargo_name}.wasm" \ |
| 84 | + -o "/tmp/${name}.wasm" |
| 85 | +
|
| 86 | + - name: Extract SBOM |
| 87 | + run: | |
| 88 | + name="${{ steps.parse.outputs.name }}" |
| 89 | + auditable2cdx "/tmp/${name}.wasm" > "/tmp/${name}.cdx.json" |
| 90 | +
|
| 91 | + - name: Login to GitHub Container Registry |
| 92 | + uses: docker/login-action@v4 |
| 93 | + with: |
| 94 | + registry: ghcr.io |
| 95 | + username: ${{ github.actor }} |
| 96 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + |
| 98 | + - name: Publish component to GitHub Container Registry |
| 99 | + id: publish |
| 100 | + uses: bytecodealliance/wkg-github-action@v5 |
| 101 | + with: |
| 102 | + file: /tmp/${{ steps.parse.outputs.name }}.wasm |
| 103 | + oci-reference-without-tag: ghcr.io/modulewise/component/${{ steps.parse.outputs.name }} |
| 104 | + version: ${{ steps.parse.outputs.version }} |
| 105 | + description: ${{ steps.meta.outputs.description }} |
| 106 | + source: ${{ steps.meta.outputs.source }} |
| 107 | + homepage: ${{ steps.meta.outputs.homepage }} |
| 108 | + licenses: ${{ steps.meta.outputs.license }} |
| 109 | + |
| 110 | + - name: Install cosign |
| 111 | + uses: sigstore/cosign-installer@v4 |
| 112 | + |
| 113 | + - name: Sign component |
| 114 | + run: | |
| 115 | + cosign sign --yes \ |
| 116 | + ghcr.io/modulewise/component/${{ steps.parse.outputs.name }}@${{ steps.publish.outputs.digest }} |
| 117 | +
|
| 118 | + - name: Attest SBOM |
| 119 | + run: | |
| 120 | + name="${{ steps.parse.outputs.name }}" |
| 121 | + cosign attest --yes \ |
| 122 | + --type cyclonedx \ |
| 123 | + --predicate "/tmp/${name}.cdx.json" \ |
| 124 | + ghcr.io/modulewise/component/${name}@${{ steps.publish.outputs.digest }} |
0 commit comments