Skip to content

Commit 6f9ff24

Browse files
committed
ci(*): add build/test app scripts, workflow
Signed-off-by: Vaughn Dice <[email protected]>
1 parent 1260844 commit 6f9ff24

File tree

10 files changed

+151
-3
lines changed

10 files changed

+151
-3
lines changed

.github/workflows/build.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
generate-matrix:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
apps: ${{ steps.set-matrix.outputs.apps }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Find all apps
17+
id: set-matrix
18+
run: |
19+
echo "apps=$(make echo-apps-json)" >> "$GITHUB_OUTPUT"
20+
21+
build-app:
22+
needs: generate-matrix
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
app: ${{ fromJson(needs.generate-matrix.outputs.apps) }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Install Wasm Rust target
31+
run: |
32+
rustup target add wasm32-wasip1
33+
34+
- name: Install wizer
35+
env:
36+
WIZER_VERSION: v9.0.0
37+
run: |
38+
wget -O wizer-${{ env.WIZER_VERSION }}-x86_64-linux.tar.xz \
39+
https://github.com/bytecodealliance/wizer/releases/download/${{ env.WIZER_VERSION }}/wizer-${{ env.WIZER_VERSION }}-x86_64-linux.tar.xz
40+
tar -xf wizer-${{ env.WIZER_VERSION }}-x86_64-linux.tar.xz
41+
mv wizer-${{ env.WIZER_VERSION }}-x86_64-linux/wizer /usr/local/bin/wizer
42+
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version: '1.23'
46+
cache: false
47+
48+
- name: Setup TinyGo
49+
uses: acifani/setup-tinygo@v2
50+
with:
51+
tinygo-version: '0.35.0'
52+
53+
- name: Install pnpm
54+
run: |
55+
npm install -g pnpm
56+
57+
- name: Install Spin
58+
uses: fermyon/actions/spin/setup@v1
59+
with:
60+
github_token: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Build ${{ matrix.app }}
63+
env:
64+
APPS: ${{ matrix.app }}
65+
ENABLE_WASM_OPT: false
66+
run: make build-apps
67+
68+
# TODO: strategy for app-specific tests (see scripts/test.sh)
69+
# - name: Test ${{ matrix.app }}
70+
# env:
71+
# APPS: ${{ matrix.app }}
72+
# ENABLE_WASM_OPT: false
73+
# TIMEOUT: 2m
74+
# run: make test-apps

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
SHELL := /bin/bash
2+
MAKE_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
3+
APPS ?= $(shell find ./samples ./tutorials -mindepth 1 -maxdepth 1 -type d)
4+
5+
default: build-apps
6+
7+
# Run a command for an app
8+
.PHONY: $(APPS)
9+
$(APPS):
10+
@echo "Running '$(SCRIPT)' for app: $@"
11+
@cd $(MAKE_DIR)$@ && \
12+
$(MAKE_DIR)scripts/$(SCRIPT) || { \
13+
echo "❌ Error: '$(SCRIPT)' failed for app: $@"; \
14+
exit 1; \
15+
};
16+
17+
# Build the apps
18+
.PHONY: build-apps
19+
build-apps:
20+
@SCRIPT='build.sh' $(MAKE) $(APPS)
21+
22+
# Test the apps
23+
.PHONY: test-apps
24+
test-apps: build-apps
25+
@SCRIPT="test.sh" $(MAKE) $(APPS)
26+
27+
# Used by the GitHub test workflow
28+
.PHONY: echo-apps-json
29+
echo-apps-json:
30+
@jq -Rn --arg str "$(APPS)" '$$str | split(" ")' | tr -d '\n'

samples/geo-ip/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target/
22
.spin/
33
.spin-aka/
4+
geoip-static-db/geoip.mmdb

samples/geo-ip/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
build:
33
@test -f geoip-static-db/geoip.mmdb || (echo "Error: geoip-static-db/geoip.mmdb not found!" && exit 1)
44
cd geoip-static-db && ./build.sh geoip.mmdb
5-
cargo build --target wasm32-wasip1 --release
5+
cargo build --target wasm32-wasip1 --release
6+
7+
.PHONY: setup
8+
setup:
9+
cp ./etc/GeoIP2-City-Test.mmdb \
10+
./geoip-static-db/geoip.mmdb
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target/
22
.spin/
33
.spin-aka/
4+
output/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.PHONY: build-rules-manager
2+
build-rules-manager:
3+
cargo build --release -p rules-manager
4+
5+
.PHONY: setup
6+
setup: build-rules-manager
7+
./target/release/rules-manager \
8+
--add-rules example-redirects.txt \
9+
--output-dir output

samples/large-scale-redirects/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
ENABLE_WASM_OPT="${ENABLE_WASM_OPT:-true}"
5+
46
# Check if the correct number of arguments is provided
57
if [ "$#" -ne 4 ]; then
68
echo "Usage: $0 <sources.fst file> <targets.fcsd file> <default status code> <output wasm file>"
@@ -11,7 +13,7 @@ fi
1113
cargo build --target wasm32-wasip1 --release
1214
echo "$1 $2 $3" | wizer --allow-wasi --wasm-bulk-memory true --dir . -o "$4" target/wasm32-wasip1/release/redirects_rs.wasm
1315
# If wasm-opt is installed, run it to optimize the output
14-
if command -v wasm-opt &> /dev/null
16+
if [[ "${ENABLE_WASM_OPT}" == "true" ]] && command -v wasm-opt &> /dev/null
1517
then
1618
wasm-opt -O3 --enable-bulk-memory-opt -o "$4" "$4"
1719
fi

samples/large-scale-redirects/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ component = "redirects-rs"
1414
source = "target/redirect.wasm"
1515
allowed_outbound_hosts = []
1616
[component.redirects-rs.build]
17-
command = "./build.sh example-redirects.txt"
17+
command = "./build.sh output/sources.fst output/targets.fcsd 302 target/redirect.wasm"
1818
watch = ["src/**/*.rs", "Cargo.toml", "build.sh", "redirects.txt"]

scripts/build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Some apps require extra setup steps
5+
current_dir=$(basename "${PWD}")
6+
if [[ "${current_dir}" == "geo-ip" || \
7+
"${current_dir}" == "large-scale-redirects" ]]; then
8+
make setup
9+
fi
10+
11+
spin build

scripts/test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -beuo pipefail
3+
4+
# TODO: some apps have specific instructions for their requests, eg headers, paths, variables, etc.
5+
# Perhaps ensure each app dir has a Makefile or script with specific test steps, defaulting to something like below?
6+
7+
# find free port, to support concurrent invocations on the same host
8+
# (although 'spin up' has a '--find-free-port' option, we need to know it ahead of time for the subsequent curl request)
9+
port=$(python3 -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()")
10+
11+
spin up --listen "127.0.0.1:${port}" &
12+
13+
timeout ${TIMEOUT:-30s} bash -c 'until [ "$(curl -sL -o /dev/null -w "%{http_code}" 127.0.0.1:$0)" = "200" ]; do sleep 1; done' "${port}"
14+
15+
trap 'kill -s SIGTERM $(jobs -p)' EXIT

0 commit comments

Comments
 (0)