diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 631198f..2062d7c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,98 +1,105 @@ name: CI on: - push: + push: branches: - - '**' - - '!dependabot/**' + - "**" + - "!dependabot/**" tags: - - 'v[0-9]+\.[0-9]+\.[0-9]+-?**' + - 'v[0-9]+\.[0-9]+\.[0-9]+-?**' pull_request: {} jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 - - uses: actions-rust-lang/setup-rust-toolchain@v2 - - name: Install cargo binstall - uses: cargo-bins/cargo-binstall@main - - name: Install wkg - run: cargo binstall --force wkg - - name: Install wasm-tools - run: cargo binstall --force wasm-tools - - name: Install wac-cli - run: cargo binstall --force wac-cli - - name: Fetch wit - run: make wit - - name: Check for drift in generated wit - run: git diff --exit-code . - - name: Build components - run: make components - - name: Collect components.tar - run: tar -cvf ../components.tar *.wasm* - working-directory: ./lib - - name: Upload components.tar - uses: actions/upload-artifact@v7 - with: - name: components.tar - path: components.tar - retention-days: 7 - - name: Capture WIT - working-directory: ./lib - run: | - for component in *.wasm ; do - echo "::group::${component} ($(du -h ${component} | cut -f1 ))" - wasm-tools component wit "${component}" - echo "::endgroup::" - done + - uses: actions/checkout@v7 + - uses: actions-rust-lang/setup-rust-toolchain@v2 + - name: Install cargo binstall + uses: cargo-bins/cargo-binstall@main + - name: Install wkg + run: cargo binstall --force wkg + - name: Install wasm-tools + run: cargo binstall --force wasm-tools + - name: Install wac-cli + run: cargo binstall --force wac-cli + - name: Fetch wit + run: make wit + - name: Check for drift in generated wit + run: git diff --exit-code . + - name: Build components + run: make components + - name: Collect components.tar + run: tar -cvf ../components.tar *.wasm* + working-directory: ./lib + - name: Upload components.tar + uses: actions/upload-artifact@v7 + with: + name: components.tar + path: components.tar + retention-days: 7 + - name: Capture WIT + working-directory: ./lib + run: | + for component in *.wasm ; do + echo "::group::${component} ($(du -h ${component} | cut -f1 ))" + wasm-tools component wit "${component}" + echo "::endgroup::" + done publish: if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' ) needs: - - build + - build permissions: contents: write packages: write id-token: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 - - uses: actions-rust-lang/setup-rust-toolchain@v2 - - name: Install cargo binstall - uses: cargo-bins/cargo-binstall@main - - name: Install wkg - run: cargo binstall --force wkg - - name: Install cosign - uses: sigstore/cosign-installer@v4.1.2 - - name: Get tag version - if: startsWith(github.ref, 'refs/tags/v') - id: get_version - run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - - name: Download components.tar - uses: actions/download-artifact@v8 - with: - name: components.tar - - name: Extract components - run: tar -xvf components.tar -C lib - - name: Login to GitHub Container Registry - uses: docker/login-action@v4 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Publish components to gchr.io - run: make publish - env: - REPOSITORY: "ghcr.io/${{ github.repository }}" - VERSION: "${{ case(github.ref == 'refs/heads/main', 'dev', steps.get_version.outputs.VERSION) }}" - - name: Draft GitHub Release - if: startsWith(github.ref, 'refs/tags/v') - uses: softprops/action-gh-release@v3 - with: - draft: true - files: | - lib/*.wasm - components.tar - fail_on_unmatched_files: true - token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v7 + - uses: actions-rust-lang/setup-rust-toolchain@v2 + - name: Install cargo binstall + uses: cargo-bins/cargo-binstall@main + - name: Install wkg + run: cargo binstall --force wkg + - name: Install wasm-tools + run: cargo binstall --force wasm-tools + - name: Install cosign + uses: sigstore/cosign-installer@v4.1.2 + - name: Download components.tar + uses: actions/download-artifact@v8 + with: + name: components.tar + - name: Extract components + run: tar -xvf components.tar -C lib + - name: Get interface version + id: interface_version + run: echo "VERSION=$( wasm-tools component wit lib/interface.wasm --json | jq -r "[.packages[] | select(.name | contains(\"${GITHUB_REPOSITORY/\//:}@\"))][0].name" | cut -d'@' -f2 )" >> $GITHUB_OUTPUT + - name: Get tag version + if: startsWith(github.ref, 'refs/tags/') + id: tag_version + run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT + - name: Login to GitHub Container Registry + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Publish components to gchr.io + # only publish tags and pre-releases from main + if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && contains(steps.interface_version.outputs.VERSION, '-')) + run: make publish + env: + REPOSITORY: "ghcr.io/${{ github.repository }}" + VERSION: "${{ case(github.ref == 'refs/heads/main', steps.interface_version.outputs.VERSION, steps.tag_version.outputs.VERSION) }}" + - name: Draft GitHub Release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v3 + with: + draft: true + files: | + lib/*.wasm + components.tar + fail_on_unmatched_files: true + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 9aac79d..f0465ff 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,8 @@ wit: wit/deps wit/deps: wkg.toml $(shell find wit -type f -name "*.wit" -not -path "deps") wkg wit fetch -.PHONY: publish -publish: $(shell find lib -type f -name "*.wasm" | sed -e 's:^lib/:publish-:g') +.PHONY: publish ## Publish each component in the lib directory +publish: $(shell find lib -maxdepth 1 -type f -name "*.wasm" | sed -e 's:^lib/:publish-:g') .PHONY: publish-% publish-%: @@ -52,26 +52,28 @@ ifndef REPOSITORY $(error REPOSITORY is undefined) endif @$(eval FILE := $(@:publish-%=%)) - @$(eval COMPONENT := $(FILE:%.wasm=%)) + @$(eval COMPONENT := $(if $(filter %.debug.wasm,$(FILE)),$(FILE:%.debug.wasm=%),$(FILE:%.wasm=%))) + @$(eval TITLE := $(if $(filter %.debug.wasm,$(FILE)),$(COMPONENT) (debug),$(COMPONENT))) @$(eval DESCRIPTION := $(shell head -n 3 "lib/${FILE}.md" | tail -n 1)) @$(eval REVISION := $(shell git rev-parse HEAD)$(shell git diff --quiet HEAD && echo "+dirty")) - @$(eval TAG := $(patsubst v%,%,$(subst +,_,$(VERSION)))) + @$(eval COMPONENT_VERSION := $(if $(filter %.debug.wasm,$(FILE)),${VERSION}+debug,${VERSION})) + @$(eval TAG := $(patsubst v%,%,$(subst +,_,$(COMPONENT_VERSION)))) + @$(eval IMAGE := $(if $(filter interface.wasm,$(FILE)),${REPOSITORY}:${TAG},${REPOSITORY}/${COMPONENT}:${TAG})) - - @echo "::group::${FILE} -> ${REPOSITORY}/${COMPONENT}:${TAG}" + @echo "::group::${FILE} -> ${IMAGE}" @DIGEST=$$( \ wkg oci push \ - --annotation "org.opencontainers.image.title=${COMPONENT}" \ + --annotation "org.opencontainers.image.title=${TITLE}" \ --annotation "org.opencontainers.image.description=${DESCRIPTION}" \ - --annotation "org.opencontainers.image.version=${VERSION}" \ + --annotation "org.opencontainers.image.version=${COMPONENT_VERSION}" \ --annotation "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}.git" \ --annotation "org.opencontainers.image.revision=${REVISION}" \ --annotation "org.opencontainers.image.licenses=Apache-2.0" \ - "${REPOSITORY}/${COMPONENT}:${TAG}" \ + "${IMAGE}" \ "lib/${FILE}" \ 2>&1 \ | tee /dev/stderr \ | grep -o 'sha256:[a-f0-9]\{64\}' \ ) ; \ - cosign sign --yes "${REPOSITORY}/${COMPONENT}:${TAG}@$${DIGEST}" + cosign sign --yes "${IMAGE}@$${DIGEST}" @echo "::endgroup::"