Files
piik/.github/workflows/repository-hygiene.yml
T

494 lines
21 KiB
YAML

name: CI
on:
pull_request:
types: [opened, synchronize, reopened, edited]
push:
branches:
- main
workflow_dispatch:
inputs:
channel_native:
description: Build the experimental Rust Native and App against the macOS SDK only
required: false
default: false
type: boolean
app_checks:
description: Build and verify App and Server candidates
required: false
default: false
type: boolean
candidate_version:
description: Optional candidate version (vMAJOR.MINOR.PATCH); never publishes
required: false
type: string
network_lab:
description: Run the isolated Linux network laboratory (never publishes)
required: false
default: none
type: choice
options: [none, verify, smoke, full]
network_cases:
description: Optional comma-separated laboratory cases (empty runs the selected suite)
required: false
type: string
network_prediction:
description: NAT enhancement setting (compare runs paired on/off trials)
required: false
default: 'on'
type: choice
options: ['on', 'off', compare]
network_repeat:
description: Repetitions per laboratory case (1..20)
required: false
default: '1'
type: string
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: false
queue: max
jobs:
channel-native:
if: github.event_name == 'workflow_dispatch' && inputs.channel_native == true
runs-on: xcode-27
timeout-minutes: 40
defaults:
run:
shell: bash --noprofile --norc -e -o pipefail {0}
env:
MACOSX_DEPLOYMENT_TARGET: '13.0'
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Install Rust 1.91.0
run: |
rustup toolchain install 1.91.0 --profile minimal
echo "CARGO_TARGET_DIR=$RUNNER_TEMP/channel-native-target" >> "$GITHUB_ENV"
- name: Build Rust Server and App with capture
run: |
mkdir -p "$RUNNER_TEMP/channel-native-logs"
cargo +1.91.0 build --locked --manifest-path prototype/channel-server/Cargo.toml --features capture --bins 2>&1 | tee "$RUNNER_TEMP/channel-native-logs/server-app.log"
- name: Compile Native tests without running them
run: cargo +1.91.0 test --locked --manifest-path prototype/channel-native/Cargo.toml --features capture --tests --no-run 2>&1 | tee "$RUNNER_TEMP/channel-native-logs/native-tests.log"
- name: Save macOS SDK build logs
if: always()
uses: actions/upload-artifact@v7
with:
name: channel-native-macos-${{ github.sha }}
path: ${{ runner.temp }}/channel-native-logs/
if-no-files-found: warn
retention-days: 7
release-notes:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm
- run: npm ci --ignore-scripts
- name: Validate PR release notes
run: node scripts/release-notes.mjs --pull-request
validate:
if: github.event_name != 'pull_request' && !(github.event_name == 'workflow_dispatch' && inputs.channel_native == true)
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release.outputs.version }}
publish: ${{ steps.release.outputs.publish }}
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm
- name: Validate tracked project state
run: sh scripts/check-project-state.sh
env:
PIIK_BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
- name: Install dependencies
run: npm ci
- name: Determine release identity
id: release
env:
PIIK_BUILD_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.candidate_version || '' }}
run: >-
node scripts/release-version.mjs
${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.PIIK_RELEASES_ENABLED == 'true' && 'plan' || 'build' }}
--github-output
- name: Preview release notes
if: steps.release.outputs.publish == 'true'
run: node scripts/release-notes.mjs "$PIIK_RELEASE_VERSION" "$GITHUB_SHA" --github-summary
env:
PIIK_RELEASE_VERSION: ${{ steps.release.outputs.version }}
# The Go build embeds internal/server/webassets/dist, so Vite runs first.
- name: Build the Web UI
run: npm run build:web
env:
PIIK_BUILD_VERSION: ${{ steps.release.outputs.version }}
VITE_PIIK_VERSION: ${{ steps.release.outputs.version }}
VITE_PIIK_REVISION: ${{ github.sha }}
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Check Go core
run: npm run check:go-core
- name: Check reachable Go vulnerabilities
run: npm run check:go-vuln
- name: Check concurrent resource ownership with the race detector
run: npm run check:go-race
- name: Type-check and test
run: npm run typecheck && npm test
env:
PIIK_BUILD_VERSION: ${{ steps.release.outputs.version }}
VITE_PIIK_VERSION: ${{ steps.release.outputs.version }}
VITE_PIIK_REVISION: ${{ github.sha }}
- name: Prepare isolated network laboratory
if: github.event_name == 'workflow_dispatch' && inputs.network_lab != 'none' && inputs.network_lab != ''
run: |
sudo apt-get update
sudo apt-get install -y nftables iproute2 tcpdump conntrack bison flex libmnl-dev libcap-dev
mkdir -p build/network-lab/bin
CGO_ENABLED=0 go build -trimpath -o build/network-lab/bin/piik-server ./cmd/piik-server
CGO_ENABLED=0 go build -trimpath -o build/network-lab/bin/piik-app ./cmd/piik-app
CGO_ENABLED=0 go build -trimpath -o build/network-lab/bin/stun ./scripts/network-lab/stun
# The runner's iproute2 6.1 lacks netem's seed parameter. Keep this tool
# local to the opt-in lab; do not replace system networking utilities.
- name: Check out laboratory traffic-control tool
if: github.event_name == 'workflow_dispatch' && inputs.network_lab != 'none' && inputs.network_lab != ''
uses: actions/checkout@v6
with:
repository: iproute2/iproute2
ref: d2a8ffe85ac64f91ee2aa7679a5046f321b54127 # v6.17.0
path: build/network-lab/iproute2
persist-credentials: false
- name: Build laboratory traffic-control tool
if: github.event_name == 'workflow_dispatch' && inputs.network_lab != 'none' && inputs.network_lab != ''
run: |
make -C build/network-lab/iproute2 -j2 SUBDIRS='lib tc netem' TC_CONFIG_NO_XT=y
echo "$GITHUB_WORKSPACE/build/network-lab/iproute2/tc" >> "$GITHUB_PATH"
- name: Run isolated network laboratory
id: network_lab
if: github.event_name == 'workflow_dispatch' && inputs.network_lab != 'none' && inputs.network_lab != ''
# A paired full matrix includes 71 trials plus negative controls.
# Individual connection/recovery deadlines stay owned by the runner.
timeout-minutes: 60
env:
CHROME_PATH: /usr/bin/google-chrome
TC_LIB_DIR: ${{ github.workspace }}/build/network-lab/iproute2/netem
PIIK_NETWORK_LAB_SUITE: ${{ inputs.network_lab }}
PIIK_NETWORK_LAB_CASES: ${{ inputs.network_cases }}
PIIK_NETWORK_LAB_PREDICTION: ${{ inputs.network_prediction }}
PIIK_NETWORK_LAB_REPEAT: ${{ inputs.network_repeat }}
run: |
if [ "$PIIK_NETWORK_LAB_SUITE" = verify ] || [ "$PIIK_NETWORK_LAB_SUITE" = full ]; then
sudo --preserve-env=PATH,CHROME_PATH,TC_LIB_DIR "$(command -v node)" --import tsx scripts/network-lab.ts --verify
fi
if [ "$PIIK_NETWORK_LAB_SUITE" != verify ]; then
sudo --preserve-env=PATH,CHROME_PATH,TC_LIB_DIR "$(command -v node)" --import tsx scripts/network-lab.ts --suite "$PIIK_NETWORK_LAB_SUITE" --cases "$PIIK_NETWORK_LAB_CASES" --prediction "$PIIK_NETWORK_LAB_PREDICTION" --repeat "$PIIK_NETWORK_LAB_REPEAT"
fi
- name: Save network laboratory evidence
if: always() && steps.network_lab.outcome != 'skipped' && github.event_name == 'workflow_dispatch' && inputs.network_lab != 'none' && inputs.network_lab != ''
uses: actions/upload-artifact@v7
with:
name: network-lab-${{ github.sha }}
path: build/network-lab/results/
if-no-files-found: error
retention-days: 7
release-server:
needs: validate
if: >-
needs.validate.outputs.publish == 'true' ||
(github.event_name == 'workflow_dispatch' && inputs.app_checks == true)
strategy:
fail-fast: false
matrix:
include:
- os: linux
arch: amd64
runner: ubuntu-24.04
artifact: piik-server
- os: linux
arch: arm64
runner: ubuntu-24.04-arm
artifact: piik-server-linux-arm64
- os: windows
arch: amd64
runner: windows-latest
artifact: piik-server-windows-amd64
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
defaults:
run:
shell: bash
env:
PIIK_BUILD_VERSION: ${{ needs.validate.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm
- name: Install Rust packaging tools
run: |
rustup toolchain install 1.91.0 --profile minimal --target wasm32-unknown-unknown
cargo +1.91.0 install wasm-bindgen-cli --version 0.2.129 --locked
cargo +1.91.0 install cargo-about --version 0.9.3 --locked --features cli
- name: Install static Server toolchain
if: matrix.os == 'linux'
run: |
sudo apt-get update && sudo apt-get install -y musl-tools binutils
target="$(node --input-type=module -e 'import { SERVER_PACKAGE_TARGETS } from "./scripts/server-package-targets.mjs"; console.log(SERVER_PACKAGE_TARGETS.find(t => t.goos === process.argv[1] && t.goarch === process.argv[2]).rustTarget)' '${{ matrix.os }}' '${{ matrix.arch }}')"
rustup target add --toolchain 1.91.0 "$target"
- name: Install dependencies
run: npm ci
- name: Package Server release
if: matrix.os == 'linux'
run: >-
node scripts/package-server-release.mjs "$RUNNER_TEMP/server-release"
--os "${{ matrix.os }}" --arch "${{ matrix.arch }}"
--container-image "piik-candidate:$GITHUB_SHA-${{ matrix.arch }}"
- name: Package Windows Server release
if: matrix.os == 'windows'
run: >-
node scripts/package-server-release.mjs "$RUNNER_TEMP/server-release"
--os "${{ matrix.os }}" --arch "${{ matrix.arch }}"
- name: Check the container and deployment recipe
if: matrix.os == 'linux'
run: npm run check:container -- "piik-candidate:$GITHUB_SHA-${{ matrix.arch }}" "$GITHUB_SHA"
- name: Save the verified container
if: matrix.os == 'linux'
run: docker save "piik-candidate:$GITHUB_SHA-${{ matrix.arch }}" --output "$RUNNER_TEMP/piik-container-${{ matrix.arch }}.tar"
- name: Upload the verified container
if: matrix.os == 'linux'
uses: actions/upload-artifact@v7
with:
name: piik-container-${{ matrix.arch }}-${{ github.sha }}
path: ${{ runner.temp }}/piik-container-${{ matrix.arch }}.tar
if-no-files-found: error
retention-days: 14
- name: Upload Server release
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact }}-${{ github.sha }}
path: ${{ runner.temp }}/server-release/*
if-no-files-found: error
retention-days: 14
release-apps:
needs:
- validate
- release-server
if: >-
needs.validate.outputs.publish == 'true' ||
(github.event_name == 'workflow_dispatch' && inputs.app_checks == true)
strategy:
fail-fast: false
matrix:
include:
- target: windows-amd64
runner: windows-latest
# Native Linux capture links system libraries; keep both architectures
# on the same explicit build baseline instead of following latest.
- target: linux-amd64
runner: ubuntu-24.04
- target: linux-arm64
runner: ubuntu-24.04-arm
- target: darwin-arm64
runner: macos-15
- target: darwin-amd64
runner: macos-15-intel
- target: android-universal
runner: ubuntu-24.04
runs-on: ${{ matrix.runner }}
timeout-minutes: ${{ matrix.target == 'android-universal' && 45 || 35 }}
env:
PIIK_BUILD_VERSION: ${{ needs.validate.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm
- name: Set up Go
if: matrix.target == 'android-universal'
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Install dependencies
run: npm ci
- name: Install Rust packaging tools
run: |
rustup toolchain install 1.91.0 --profile minimal --target wasm32-unknown-unknown
cargo +1.91.0 install wasm-bindgen-cli --version 0.2.129 --locked
cargo +1.91.0 install cargo-about --version 0.9.3 --locked --features cli
- name: Install Linux packaging and native capture dependencies
if: startsWith(matrix.target, 'linux-')
run: >-
sudo apt-get update && sudo apt-get install -y
zip
unzip
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
gstreamer1.0-pipewire
gstreamer1.0-plugins-bad
gstreamer1.0-pulseaudio
- name: Build and verify App candidate
if: matrix.target != 'android-universal'
run: >-
node scripts/package-app-candidate.mjs
"${{ matrix.target }}"
"${{ runner.temp }}/app-release"
- name: Set up Android Java
if: matrix.target == 'android-universal'
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '17'
- name: Set up Android Gradle
if: matrix.target == 'android-universal'
uses: gradle/actions/setup-gradle@v6
with:
gradle-version: '8.11.1'
cache-provider: basic
- name: Install pinned Android build tools
if: matrix.target == 'android-universal'
run: |
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" 'platforms;android-35' 'build-tools;35.0.0' 'ndk;30.0.16248370'
echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/30.0.16248370" >> "$GITHUB_ENV"
echo "GRADLE_HOME=$(dirname "$(dirname "$(readlink -f "$(command -v gradle)")")")" >> "$GITHUB_ENV"
rustup target add --toolchain 1.91.0 aarch64-linux-android x86_64-linux-android
- name: Prepare Android signing
if: matrix.target == 'android-universal'
env:
PIIK_PUBLISH: ${{ needs.validate.outputs.publish }}
PIIK_ANDROID_KEYSTORE_BASE64: ${{ secrets.PIIK_ANDROID_KEYSTORE_BASE64 }}
PIIK_ANDROID_STORE_PASSWORD: ${{ secrets.PIIK_ANDROID_STORE_PASSWORD }}
PIIK_ANDROID_KEY_ALIAS: ${{ secrets.PIIK_ANDROID_KEY_ALIAS }}
PIIK_ANDROID_KEY_PASSWORD: ${{ secrets.PIIK_ANDROID_KEY_PASSWORD }}
run: |
if [ "$PIIK_PUBLISH" = true ]; then
for name in PIIK_ANDROID_KEYSTORE_BASE64 PIIK_ANDROID_STORE_PASSWORD PIIK_ANDROID_KEY_ALIAS PIIK_ANDROID_KEY_PASSWORD; do
if [ -z "${!name}" ]; then echo "Android publication requires $name" >&2; exit 1; fi
done
umask 077
printf '%s' "$PIIK_ANDROID_KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/piik-android.keystore"
else
# Manual candidates exercise the same release variant with a disposable key.
keytool -genkeypair -keystore "$RUNNER_TEMP/piik-android.keystore" -storetype PKCS12 \
-storepass candidate-password -keypass candidate-password -alias piik-candidate \
-keyalg RSA -keysize 3072 -validity 2 -dname 'CN=Piik CI candidate' -noprompt
fi
- name: Build and verify Android release APK
if: matrix.target == 'android-universal'
env:
PIIK_ANDROID_KEYSTORE: ${{ runner.temp }}/piik-android.keystore
PIIK_ANDROID_STORE_PASSWORD: ${{ needs.validate.outputs.publish == 'true' && secrets.PIIK_ANDROID_STORE_PASSWORD || 'candidate-password' }}
PIIK_ANDROID_KEY_ALIAS: ${{ needs.validate.outputs.publish == 'true' && secrets.PIIK_ANDROID_KEY_ALIAS || 'piik-candidate' }}
PIIK_ANDROID_KEY_PASSWORD: ${{ needs.validate.outputs.publish == 'true' && secrets.PIIK_ANDROID_KEY_PASSWORD || 'candidate-password' }}
run: node scripts/build-android.mjs --release --output "$RUNNER_TEMP/app-release"
- name: Remove temporary Android signing material
if: always() && matrix.target == 'android-universal'
run: rm -f -- "$RUNNER_TEMP/piik-android.keystore"
- name: Upload App release candidate
uses: actions/upload-artifact@v7
with:
name: piik-app-${{ matrix.target }}-${{ github.sha }}
path: ${{ runner.temp }}/app-release/*
if-no-files-found: error
compression-level: 0
retention-days: 14
publish:
needs:
- validate
- release-server
- release-apps
if: needs.validate.outputs.publish == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
packages: write
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Download Server release
uses: actions/download-artifact@v8
with:
pattern: piik-server*-${{ github.sha }}
path: ${{ runner.temp }}/publish-release
merge-multiple: true
- name: Download App release candidates
uses: actions/download-artifact@v8
with:
pattern: piik-app-*-${{ github.sha }}
path: ${{ runner.temp }}/publish-release
merge-multiple: true
- name: Download the verified container
uses: actions/download-artifact@v8
with:
pattern: piik-container-*-${{ github.sha }}
path: ${{ runner.temp }}/container
merge-multiple: true
- name: Load the verified container
run: |
for arch in amd64 arm64; do
docker load --input "$RUNNER_TEMP/container/piik-container-$arch.tar"
done
- name: Log in to GitHub Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
# Local descriptors/manifests/checksums are validated before publishing.
# Release assets contain packages only; checksums appear in the release body.
- name: Publish packages with release notes and checksums
run: >-
node scripts/publish-release.mjs
"$RUNNER_TEMP/publish-release" "$PIIK_RELEASE_VERSION" "$GITHUB_SHA"
env:
GH_TOKEN: ${{ github.token }}
PIIK_RELEASE_VERSION: ${{ needs.validate.outputs.version }}
- name: Publish the matching Server container
run: >-
node scripts/publish-container.mjs "piik-candidate:$GITHUB_SHA"
"$RUNNER_TEMP/publish-release" "$PIIK_RELEASE_VERSION" "$GITHUB_SHA"
env:
GH_TOKEN: ${{ github.token }}
PIIK_RELEASE_VERSION: ${{ needs.validate.outputs.version }}