Skip to content

Commit 53636a8

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

File tree

8 files changed

+133
-19
lines changed

8 files changed

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