Skip to content

Commit a4877b3

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

File tree

8 files changed

+131
-19
lines changed

8 files changed

+131
-19
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
"dockerfile": "Dockerfile",
55
"context": ".."
66
},
7-
"settings": {
8-
},
9-
"extensions": [
10-
],
7+
"settings": {},
8+
"extensions": [],
119
"forwardPorts": [8080],
1210
"remoteUser": "node"
1311
}

.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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ 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
31-
run: npm run format -- --check
32+
run: npm run format-ci
3233
- name: Run ESLint
3334
run: npm run lint

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

eslint.config.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import { defineConfig } from "eslint/config";
22
import js from "@eslint/js";
33
import globals from "globals";
44

5-
65
export default defineConfig([
7-
{ files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"] },
8-
{ files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: globals.browser } },
9-
]);
6+
{
7+
files: ["**/*.{js,mjs,cjs}"],
8+
plugins: { js },
9+
extends: ["js/recommended"],
10+
},
11+
{
12+
files: ["**/*.{js,mjs,cjs}"],
13+
languageOptions: { globals: globals.browser },
14+
},
15+
]);

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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
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",
11-
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
15+
"build": "npm run bundle && componentize-js --aot --wit wit -o dist/$npm_package_name.wasm dist/bundle.js",
16+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css}\"",
17+
"format-ci": "prettier --check \"**/*.{js,jsx,ts,tsx,json,css}\"",
1218
"lint": "eslint src/**/*.js",
1319
"test": "vitest --run"
1420
},

src/server.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, beforeAll, afterAll, expect } from "vitest";
22
import { spawn } from "child_process";
33

4-
import waitOn from 'wait-on';
4+
import waitOn from "wait-on";
55

66
const PORT = 8080;
77
const timeout = 30000;
@@ -13,7 +13,7 @@ describe("Integration tests for the WASI HTTP server endpoints", () => {
1313
beforeAll(async () => {
1414
serverProcess = spawn(
1515
"wasmtime",
16-
["serve", "-S", "common", "dist/server.component.wasm"],
16+
["serve", "-S", "common", "dist/sample-wasi-http-js.wasm"],
1717
{ stdio: "inherit" },
1818
);
1919

@@ -22,7 +22,7 @@ describe("Integration tests for the WASI HTTP server endpoints", () => {
2222
resources: [`tcp:localhost:${PORT}`],
2323
timeout,
2424
delay: 1000,
25-
interval: 500
25+
interval: 500,
2626
});
2727
}, timeout);
2828

0 commit comments

Comments
 (0)