Files
Kang 446e1a768c feat(web-release): enhance release metadata handling and testing
- Updated `release_metadata` function to support manual testing from the main branch without publishing.
- Added tests to verify behavior for manual main runs, tag releases, and restrictions on other branches.
- Modified workflow to conditionally publish images based on the event type and added logging for manual test results.
- Enhanced documentation to clarify manual testing procedures and workflow behavior.
2026-10-07 21:28:59 +08:00

250 lines
8.3 KiB
YAML

name: Build and Release Web
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: web-release-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
name: Validate Web release
runs-on: ubuntu-24.04
timeout-minutes: 10
outputs:
version: ${{ steps.metadata.outputs.version }}
image_tag: ${{ steps.metadata.outputs.image_tag }}
image: ${{ steps.metadata.outputs.image }}
stable: ${{ steps.metadata.outputs.stable }}
publish: ${{ steps.metadata.outputs.publish }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Test release policy
run: python3 -m unittest discover -s .github/scripts -p 'test_web_release.py'
- name: Resolve release or manual test mode
id: metadata
run: python3 .github/scripts/web-release.py metadata
- name: Verify selected commit belongs to main
shell: bash
run: |
set -euo pipefail
git fetch origin main:refs/remotes/origin/main
ref_commit=$(git rev-parse "${GITHUB_REF}^{commit}")
if [ "$ref_commit" != "$(git rev-parse HEAD)" ] || ! git merge-base --is-ancestor "$ref_commit" origin/main; then
echo "::error::The checked-out commit must belong to origin/main."
exit 1
fi
acceptance:
name: Web deployment acceptance
needs: prepare
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v5
with:
version: 11.10.0
- uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
- uses: docker/setup-buildx-action@v3
- run: pnpm install --frozen-lockfile
- run: pnpm exec playwright install --with-deps chromium
- run: pnpm test:web:e2e
- uses: actions/upload-artifact@v4
if: failure()
with:
name: web-release-acceptance-failure
path: artifacts/web-e2e/
retention-days: 7
build:
name: Build and smoke test ${{ matrix.arch }}
needs: [prepare, acceptance]
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- { arch: amd64, runner: ubuntu-24.04 }
- { arch: arm64, runner: ubuntu-24.04-arm }
env:
IMAGE: ${{ needs.prepare.outputs.image }}
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
- uses: docker/setup-buildx-action@v3
- name: Build local image
uses: docker/build-push-action@v6
with:
context: .
file: deploy/web/Dockerfile
platforms: linux/${{ matrix.arch }}
build-args: NYATERM_WEB_BASE_PATH=/
load: true
tags: nyaterm-web:smoke
provenance: false
sbom: false
labels: |
org.opencontainers.image.version=${{ env.VERSION }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha,scope=web-release-${{ matrix.arch }}
cache-to: type=gha,scope=web-release-${{ matrix.arch }},mode=max
- name: Smoke test the release image
env:
NYATERM_SMOKE_IMAGE: nyaterm-web:smoke
run: node .github/scripts/web-release-smoke.mjs
- name: Record manual test result
if: needs.prepare.outputs.publish != 'true'
env:
ARCH: ${{ matrix.arch }}
run: |
echo "Manual main test passed: linux/$ARCH, version $VERSION. No image was published." >> "$GITHUB_STEP_SUMMARY"
- uses: actions/setup-go@v6
if: needs.prepare.outputs.publish == 'true'
with:
go-version: stable
cache: false
- name: Install crane
if: needs.prepare.outputs.publish == 'true'
env:
GOBIN: ${{ runner.temp }}/web-tools
run: |
go install github.com/google/go-containerregistry/cmd/crane@v0.20.3
echo "$GOBIN" >> "$GITHUB_PATH"
- uses: docker/login-action@v3
if: needs.prepare.outputs.publish == 'true'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push tested image by digest
if: needs.prepare.outputs.publish == 'true'
env:
ARCH: ${{ matrix.arch }}
shell: bash
run: |
set -euo pipefail
archive="$RUNNER_TEMP/nyaterm-web.tar"
docker save nyaterm-web:smoke --output "$archive"
digest=$(crane digest --tarball "$archive")
crane push "$archive" "$IMAGE@$digest"
mkdir -p digests
printf '%s' "$digest" > "digests/$ARCH"
{
echo "### Web image: linux/$ARCH"
echo "Version: $VERSION"
echo "Image: $IMAGE@$digest"
} >> "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@v4
if: needs.prepare.outputs.publish == 'true'
with:
name: web-release-digest-${{ matrix.arch }}
path: digests/
if-no-files-found: error
retention-days: 7
- uses: actions/upload-artifact@v4
if: failure()
with:
name: web-release-smoke-failure-${{ matrix.arch }}
path: artifacts/web-release-smoke/
retention-days: 7
publish:
name: Publish multi-architecture version
needs: [prepare, build]
if: needs.prepare.outputs.publish == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.manifest.outputs.digest }}
env:
IMAGE: ${{ needs.prepare.outputs.image }}
IMAGE_TAG: ${{ needs.prepare.outputs.image_tag }}
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v6
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
with:
pattern: web-release-digest-*
path: digests
merge-multiple: true
- name: Create and verify the version manifest
id: manifest
shell: bash
run: |
set -euo pipefail
DIGEST_AMD64=$(cat digests/amd64)
DIGEST_ARM64=$(cat digests/arm64)
export DIGEST_AMD64 DIGEST_ARM64
docker buildx imagetools create --tag "$IMAGE:$IMAGE_TAG" \
"$IMAGE@$DIGEST_AMD64" "$IMAGE@$DIGEST_ARM64"
docker buildx imagetools inspect --raw "$IMAGE:$IMAGE_TAG" > manifest.json
python3 .github/scripts/web-release.py check-manifest
{
echo "### Published Web release $VERSION"
echo "Image: $IMAGE:$IMAGE_TAG"
echo "Platforms: linux/amd64, linux/arm64"
} >> "$GITHUB_STEP_SUMMARY"
- name: Record manifest digest
env:
DIGEST: ${{ steps.manifest.outputs.digest }}
run: |
echo "Manifest digest (pin for deployment): $IMAGE@$DIGEST" >> "$GITHUB_STEP_SUMMARY"
latest:
name: Promote newer stable version to latest
needs: [prepare, publish]
if: needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.stable == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
packages: write
concurrency:
group: web-release-latest-${{ github.repository }}
cancel-in-progress: false
env:
IMAGE: ${{ needs.prepare.outputs.image }}
VERSION: ${{ needs.prepare.outputs.version }}
DIGEST: ${{ needs.publish.outputs.digest }}
steps:
- uses: actions/checkout@v6
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compare registry version and promote latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python3 .github/scripts/web-release.py promote-latest