Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 84 additions & 79 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,100 +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
- name: Build test components
run: make test
- 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: Sync 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: Test
run: make test
- 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/')
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/')
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 }}
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ resolver = "2"
members = [
"components/*",
]
exclude = [
"components/wit",
]

[workspace.dependencies]
wit-bindgen = "0.62.0"
37 changes: 23 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ test:
@echo "TODO add tests"

.PHONY: components
components: $(foreach component,$(COMPONENTS),lib/$(component).wasm $(foreach component,$(COMPONENTS),lib/$(component).debug.wasm))
components: lib/interface.wasm $(foreach component,$(COMPONENTS),lib/$(component).wasm lib/$(component).debug.wasm)

define BUILD_COMPONENT

.PHONY: components/$1
components/$1: lib/$1.wasm lib/$1.debug.wasm

lib/$1.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
lib/$1.wasm: Cargo.toml Cargo.lock components/wit/deps $(shell find components/$1 -type f)
cargo build -p $1 --target wasm32-unknown-unknown --release
wasm-tools component new target/wasm32-unknown-unknown/release/$(subst -,_,$1).wasm -o lib/$1.wasm
cp components/$1/README.md lib/$1.wasm.md

lib/$1.debug.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
lib/$1.debug.wasm: Cargo.toml Cargo.lock components/wit/deps $(shell find components/$1 -type f)
cargo build -p $1 --target wasm32-unknown-unknown
wasm-tools component new target/wasm32-unknown-unknown/debug/$(subst -,_,$1).wasm -o lib/$1.debug.wasm
cp components/$1/README.md lib/$1.debug.wasm.md
Expand All @@ -40,15 +40,21 @@ endef

$(foreach component,$(COMPONENTS),$(eval $(call BUILD_COMPONENT,$(component))))

lib/interface.wasm: wit/deps README.md
wkg build -o lib/interface.wasm
cp README.md lib/interface.wasm.md

.PHONY: wit
wit: wit/deps
wit: wit/deps components/wit/deps

wit/deps: wkg.toml $(shell find wit -type f -name "*.wit" -not -path "deps")
wkg wit fetch
wkg fetch

.PHONY: publish
publish: $(shell find lib -type f -name "*.wasm" | sed -e 's:^lib/:publish-:g')
components/wit/deps: wit/deps components/wkg.toml $(shell find components/wit -type f -name "*.wit" -not -path "deps")
( cd components && wkg fetch )

.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-%:
Expand All @@ -59,25 +65,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::"
2 changes: 1 addition & 1 deletion components/stderr-to-stdout/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Guest for StderrToStdout {
}

wit_bindgen::generate!({
path: "../../wit",
path: "../wit",
world: "stderr-to-stdout",
merge_structurally_equal_types: true,
generate_all
Expand Down
2 changes: 1 addition & 1 deletion components/stdout-to-stderr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Guest for StdoutToStderr {
}

wit_bindgen::generate!({
path: "../../wit",
path: "../wit",
world: "stdout-to-stderr",
merge_structurally_equal_types: true,
generate_all
Expand Down
7 changes: 7 additions & 0 deletions components/wit/deps/componentized-cli-0.2.0-dev/package.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package componentized:cli@0.2.0-dev;

world imports {
import wasi:cli/types@0.3.0;
import wasi:cli/stdout@0.3.0;
import wasi:cli/stderr@0.3.0;
}
Loading
Loading