Skip to content

Commit eb3fa0e

Browse files
committed
Add publishing oci images workflow
1 parent 04788c4 commit eb3fa0e

File tree

5 files changed

+113
-6
lines changed

5 files changed

+113
-6
lines changed

.github/workflows/publish.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build and publish a Wasm Component to GitHub Artifacts
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
workflow_dispatch:
8+
9+
env:
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
id-token: write
17+
packages: write
18+
contents: read
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '23'
28+
cache: 'npm'
29+
30+
- name: Set up just
31+
- uses: extractions/setup-just@v3
32+
33+
- name: Extract package information
34+
id: pkg
35+
run: |
36+
echo "COMPONENT_NAME=$(npm pkg get name | tr -d '"')" >> $GITHUB_ENV
37+
echo "COMPONENT_DESCRIPTION=$(npm pkg get description | tr -d '"')" >> $GITHUB_ENV
38+
echo "COMPONENT_SOURCE=$(npm pkg get repository.url | tr -d '"')" >> $GITHUB_ENV
39+
echo "COMPONENT_HOMEPAGE=$(npm pkg get homepage | tr -d '"')" >> $GITHUB_ENV
40+
echo "COMPONENT_LICENSES=$(npm pkg get license | tr -d '"')" >> $GITHUB_ENV
41+
42+
- name: Docker meta
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ghcr.io/${{ github.actor }}/${{ env.COMPONENT_NAME }}
47+
tags: |
48+
type=semver,pattern={{version}}
49+
50+
- name: Login to GitHub Container Registry
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Install cosign
58+
if: github.event_name != 'workflow_dispatch'
59+
uses: sigstore/[email protected]
60+
61+
- name: Build the component
62+
run: just build
63+
64+
- name: Normalize COMPONENT_NAME and Append .wasm
65+
run: echo "COMPONENT_NAME_UNDERSCORED=${COMPONENT_NAME//-/_}.wasm" >> $GITHUB_ENV
66+
67+
- name: Publish `:<version>` to GitHub Container Registry
68+
if: github.event_name != 'workflow_dispatch'
69+
id: publish_versioned
70+
uses: bytecodealliance/wkg-github-action@v5
71+
with:
72+
file: dist/${{ env.COMPONENT_NAME_UNDERSCORED }}
73+
oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}
74+
version: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
75+
description: ${{ env.COMPONENT_DESCRIPTION }}
76+
source: ${{ env.COMPONENT_SOURCE }}
77+
homepage: ${{ env.COMPONENT_HOMEPAGE }}
78+
licenses: ${{ env.COMPONENT_LICENSES }}
79+
80+
- name: Sign the versioned wasm component
81+
if: github.event_name != 'workflow_dispatch'
82+
run: cosign sign --yes ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}@${{ steps.publish_versioned.outputs.digest }}
83+
84+
- name: Publish `:latest` release to GitHub Container Registry
85+
if: github.event_name != 'workflow_dispatch'
86+
id: publish_latest
87+
uses: bytecodealliance/wkg-github-action@v5
88+
with:
89+
file: dist/${{ env.COMPONENT_NAME_UNDERSCORED }}
90+
oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}
91+
version: latest
92+
description: ${{ env.COMPONENT_DESCRIPTION }}
93+
source: ${{ env.COMPONENT_SOURCE }}
94+
homepage: ${{ env.COMPONENT_HOMEPAGE }}
95+
licenses: ${{ env.COMPONENT_LICENSES }}
96+
97+
- name: Sign the latest wasm component
98+
if: github.event_name != 'workflow_dispatch'
99+
run: cosign sign --yes ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}@${{ steps.publish_latest.outputs.digest }}

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ jobs:
1717
uses: actions/setup-node@v4
1818
with:
1919
node-version: '23'
20-
- name: Install dependencies
21-
run: npm install
20+
cache: 'npm'
21+
- name: Set up just
22+
- uses: extractions/setup-just@v3
2223
- name: Install Wasmtime
2324
run: |
2425
curl https://wasmtime.dev/install.sh -sSf | bash
2526
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
2627
- name: Build the project
27-
run: npm run build
28+
run: just build
2829
- name: Run tests
2930
run: npm test
3031
- name: Run format checks

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Alternatively, run:
5353
```bash
5454
$ npm install
5555
$ npm run build
56-
$ wasmtime serve -S common dist/server.component.wasm
56+
$ wasmtime serve -S common dist/sample-wasi-http-js.wasm
5757
```
5858

5959
## See Also

justfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package-name := trim_start_match(trim_end_match(`npm pkg get name`, "\""), "\"")
2+
13
alias b := build
24

35
# List all recipes
@@ -27,4 +29,4 @@ test: build
2729

2830
serve: build
2931
@echo 'Serving guest...'
30-
wasmtime serve -S common dist/server.component.wasm
32+
wasmtime serve -S common dist/{{package-name}}.wasm

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
"name": "sample-wasi-http-js",
33
"version": "0.1.0",
44
"description": "Sample project demonstratingu JS project targeting WASI http",
5+
"homepage": "https://github.com/bytecodealliance/sample-wasi-http-js",
56
"license": "(Apache-2.0 WITH LLVM-exception)",
67
"author": "Tomasz Andrzejak",
78
"type": "module",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/bytecodealliance/sample-wasi-http-js"
12+
},
813
"scripts": {
914
"bundle": "rollup -c",
10-
"build": "npm run bundle && componentize-js --aot --wit wit -o dist/server.component.wasm dist/bundle.js",
15+
"build": "npm run bundle && componentize-js --aot --wit wit -o dist/$npm_package_name.wasm dist/bundle.js",
1116
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
1217
"lint": "eslint src/**/*.js",
1318
"test": "vitest --run"

0 commit comments

Comments
 (0)