Skip to content

feat(examples): Adds a composition example with custom interface #464

feat(examples): Adds a composition example with custom interface

feat(examples): Adds a composition example with custom interface #464

name: example-components
on:
push:
branches:
- main
tags:
- component-blobby-v[0-9]+.[0-9]+.[0-9]+*
- component-echo-messaging-v[0-9]+.[0-9]+.[0-9]+*
- component-http-hello-world-v[0-9]+.[0-9]+.[0-9]+*
- component-http-keyvalue-counter-v[0-9]+.[0-9]+.[0-9]+*
- component-http-jsonify-v[0-9]+.[0-9]+.[0-9]+*
pull_request:
branches: [main]
paths:
- .github/workflows/examples.yml
- crates/wash-lib/**
- crates/wash-cli/**
- examples/rust/components/**
- examples/golang/components/**
- examples/python/components/**
- examples/typescript/components/**
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
build-wash-cli:
name: Build wash CLI
runs-on: ubuntu-22.04
strategy:
matrix:
wash-version:
- 0.27.0
- current
steps:
- uses: actions/checkout@v4
if: ${{ matrix.wash-version == 'current' }}
- uses: Swatinem/rust-cache@v2
with:
shared-key: "ubuntu-22.04-shared-cache"
- name: install wash (previous version)
if: ${{ matrix.wash-version != 'current' }}
uses: taiki-e/install-action@v2
with:
tool: wash-cli@${{ matrix.wash-version }}
- name: build wash (current)
if: ${{ matrix.wash-version == 'current' }}
run: cargo build -p wash-cli --release
- uses: actions/upload-artifact@v4
if: ${{ matrix.wash-version == 'current' }}
with:
name: wash-${{ matrix.wash-version }}
path: ./target/release/wash
- uses: actions/upload-artifact@v4
if: ${{ matrix.wash-version != 'current' }}
with:
name: wash-${{ matrix.wash-version }}
path: ~/.cargo/bin/wash
# Ensure that `wash build` works for all example projects below
wash-build:
name: build
runs-on: ubuntu-22.04
needs: [build-wash-cli]
strategy:
fail-fast: false
matrix:
wash-version:
- 0.27.0
- current
project:
# Golang example components
- lang: "golang"
lang_version: "1.20"
name: "http-echo-tinygo"
- lang: "golang"
lang_version: "1.20"
name: "http-hello-world"
# Rust example components
- lang: "rust"
name: "blobby"
wasm-bin: "blobby_s.wasm"
- lang: "rust"
name: "http-hello-world"
wasm-bin: "http_hello_world_s.wasm"
- lang: "rust"
name: "http-jsonify"
wasm-bin: "wasmcloud_component_http_jsonify_s.wasm"
- lang: "rust"
name: "http-keyvalue-counter"
wasm-bin: "http_keyvalue_counter_s.wasm"
- lang: "rust"
name: "echo-messaging"
wasm-bin: "echo_messaging_s.wasm"
# Python example components
- lang: "python"
lang_version: "3.10"
name: "http-hello-world"
# Typescript example components
- lang: "typescript"
lang_version: "20.x"
name: "http-hello-world"
steps:
- uses: actions/checkout@v4
# Download wash binary & install to path
- uses: actions/download-artifact@v4
with:
name: wash-${{ matrix.wash-version }}
path: artifacts
- name: install wash binary to PATH # Some build tools expect wash to be on the PATH
shell: bash
run: |
chmod +x ./artifacts/wash;
echo "$(realpath ./artifacts)" >> "$GITHUB_PATH";
# Language specific setup
- uses: actions/setup-go@v5
if: ${{ matrix.project.lang == 'golang' }}
with:
go-version: ${{ matrix.project.lang_version }}
- uses: acifani/setup-tinygo@v2
if: ${{ matrix.project.lang == 'golang' }}
with:
tinygo-version: "0.30.0"
install-binaryen: "false"
- uses: actions/setup-python@v5
if: ${{ matrix.project.lang == 'python' }}
with:
python-version: ${{ matrix.project.lang_version }}
- name: install python reqs
if: ${{ matrix.project.lang == 'python' }}
run: |
pip install componentize-py
- uses: actions/setup-node@v4
if: ${{ matrix.project.lang == 'typescript' }}
with:
node-version: ${{ matrix.project.lang_version }}
- name: install node reqs
if: ${{ matrix.project.lang == 'typescript' }}
run: |
npm install -g @bytecodealliance/jco
npm install -g @bytecodealliance/componentize-js
# Build example project(s)
- name: build project
run: wash build
working-directory: examples/${{ matrix.project.lang }}/components/${{ matrix.project.name }}
# Save example as an artifact for later step(s)
- uses: actions/upload-artifact@v4
if: ${{ startswith(github.ref, format('refs/tags/component-{0}-v', matrix.project.name)) }}
with:
name: wash-build-${{ matrix.wash-version }}-${{ matrix.project.lang }}-component-${{ matrix.project.name }}
path: examples/${{ matrix.project.lang }}/components/${{ matrix.project.name }}/build/${{ matrix.project.wasm-bin }}
# Publish components relevant components if they've been tagged
publish:
name: publish
runs-on: ubuntu-22.04
needs: [wash-build]
if: ${{ startswith(github.ref, 'refs/tags/component-') }}
strategy:
fail-fast: false
matrix:
wash-version:
- current
project:
# Rust example components (to publish)
- lang: "rust"
name: "blobby"
wasm-bin: "blobby_s.wasm"
- lang: "rust"
name: "http-keyvalue-counter"
wasm-bin: "http_keyvalue_counter_s.wasm"
- lang: "rust"
name: "http-hello-world"
wasm-bin: "http_hello_world_s.wasm"
- lang: "rust"
name: "http-jsonify"
wasm-bin: "wasmcloud_component_http_jsonify_s.wasm"
- lang: "rust"
name: "echo-messaging"
wasm-bin: "echo_messaging_s.wasm"
steps:
- uses: actions/checkout@v4
# Determine tag version (if this is a release tag), without the 'v'
- name: Determine version
id: meta
shell: bash
env:
REF: ${{ github.ref }}
REF_PREFIX: ${{ format('refs/tags/component-{0}-v', matrix.project.name) }}
run: |
export VERSION=${REF#$REF_PREFIX};
echo -e "version=${VERSION}" >> $GITHUB_OUTPUT;
echo "bin-name=wash-build-${{ matrix.wash-version }}-${{ matrix.project.lang }}-component-${{ matrix.project.name }}/${{ matrix.project.wasm-bin }}" >> $GITHUB_OUTPUT;
echo "ref-prefix=$REF_PREFIX" >> $GITHUB_OUTPUT;
echo "wasmcloud-toml-path=examples/${{ matrix.project.lang }}/components/${{ matrix.project.name }}/wasmcloud.toml" >> $GITHUB_OUTPUT;
# Download all artifacts (wash binary and example component binaries) to work dir
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: install wash binary to PATH # Some build tools expect wash to be on the PATH
shell: bash
run: |
chmod +x ./artifacts/wash-${{ matrix.wash-version }}/wash;
echo "$(realpath ./artifacts/wash-${{ matrix.wash-version }})" >> "$GITHUB_PATH";
# Push the project to GitHub Container Registry under various tags, if this is a release tag
- name: Push SHA-tagged WebAssembly binary to GHCR
if: ${{ startsWith(github.ref, steps.meta.outputs.ref-prefix) }}
env:
WASH_REG_USER: ${{ github.repository_owner }}
WASH_REG_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
wash push ghcr.io/${{ github.repository_owner }}/components/${{ matrix.project.name }}-${{ matrix.project.lang }}:${{ github.sha }} artifacts/${{ steps.meta.outputs.bin-name }}
- name: Push version-tagged WebAssembly binary to GHCR
if: ${{ startsWith(github.ref, steps.meta.outputs.ref-prefix) }}
env:
WASH_REG_USER: ${{ github.repository_owner }}
WASH_REG_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
wash push ghcr.io/${{ github.repository_owner }}/components/${{ matrix.project.name }}-${{ matrix.project.lang }}:${{ steps.meta.outputs.version }} artifacts/${{ steps.meta.outputs.bin-name }}
# (wasmCloud/wasmCloud repository only)
# Push the project to Azure Container Registry under various tags, if this is a release tag
- name: Push SHA-tagged WebAssembly binary to AzureCR
if: ${{ startsWith(github.ref, steps.meta.outputs.ref-prefix) && github.repository_owner == 'wasmCloud' }}
run: |
wash push wasmcloud.azurecr.io/${{ github.repository_owner }}/components/${{ matrix.project.name }}-${{ matrix.project.lang }}:${{ github.sha }} artifacts/${{ steps.meta.outputs.bin-name }}
env:
WASH_REG_USER: ${{ secrets.AZURECR_PUSH_USER }}
WASH_REG_PASSWORD: ${{ secrets.AZURECR_PUSH_PASSWORD }}
- name: Push version-tagged WebAssembly binary to AzureCR
if: ${{ startsWith(github.ref, steps.meta.outputs.ref-prefix) && github.repository_owner == 'wasmCloud' }}
run: |
wash push wasmcloud.azurecr.io/${{ github.repository_owner }}/components/${{ matrix.project.name }}-${{ matrix.project.lang }}:${{ steps.meta.outputs.version }} artifacts/${{ steps.meta.outputs.bin-name }}
env:
WASH_REG_USER: ${{ secrets.AZURECR_PUSH_USER }}
WASH_REG_PASSWORD: ${{ secrets.AZURECR_PUSH_PASSWORD }}