refactor: unify build/release workflows into a single parameterized workflow

Replace 4 separate workflows (docker-build-self, docker-build-origin,
release-self-binaries, release-origin-binaries) with one build-and-release.yml
that accepts repository, ref, docker_tag, and release_tag as inputs.

- origin/Dockerfile: now copies pre-built binary like self/Dockerfile
- origin/build.sh: clones tiann/hapi@main and builds before docker build

via HAPI

Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
i
2026-05-22 17:52:44 +08:00
co-authored by HAPI
parent f23b40f554
commit acd51fae08
7 changed files with 158 additions and 308 deletions
+134
View File
@@ -0,0 +1,134 @@
name: Build and Release HAPI
on:
workflow_dispatch:
inputs:
repository:
description: 'Source repository (e.g. tiann/hapi or arkylin/hapi)'
required: true
default: 'tiann/hapi'
ref:
description: 'Git ref (branch, tag, or commit SHA)'
required: true
default: 'main'
docker_tag:
description: 'Docker image tag (e.g. origin, self, custom)'
required: true
default: 'origin'
release_tag:
description: 'Release tag (leave empty to skip binary release)'
required: false
build_docker:
description: 'Build and push Docker image'
type: boolean
default: true
release_binaries:
description: 'Release binaries'
type: boolean
default: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- name: Checkout hapi source
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.repository }}
ref: ${{ github.event.inputs.ref }}
path: hapi-src
- name: Get version info
id: info
working-directory: hapi-src
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
VERSION=$(jq -r '.version' cli/package.json)
echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Building version $VERSION @ $SHORT_SHA"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.14
- name: Build all platform binaries
working-directory: hapi-src
run: |
bun install
bun run build:single-exe:all
- name: Copy binaries for Docker
if: ${{ github.event.inputs.build_docker == 'true' }}
run: |
mkdir -p self
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi self/hapi-amd64
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi self/hapi-arm64
- uses: docker/setup-qemu-action@v3
if: ${{ github.event.inputs.build_docker == 'true' }}
- uses: docker/setup-buildx-action@v3
if: ${{ github.event.inputs.build_docker == 'true' }}
- uses: docker/login-action@v3
if: ${{ github.event.inputs.build_docker == 'true' }}
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
if: ${{ github.event.inputs.build_docker == 'true' }}
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ github.event.inputs.docker_tag }}
- uses: docker/build-push-action@v6
if: ${{ github.event.inputs.build_docker == 'true' }}
with:
context: ./self
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Prepare release artifacts
if: ${{ github.event.inputs.release_binaries == 'true' && github.event.inputs.release_tag != '' }}
run: |
mkdir -p release
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi release/hapi-linux-x64
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi release/hapi-linux-arm64
cp hapi-src/cli/dist-exe/bun-darwin-x64/hapi release/hapi-darwin-x64
cp hapi-src/cli/dist-exe/bun-darwin-arm64/hapi release/hapi-darwin-arm64
cp hapi-src/cli/dist-exe/bun-windows-x64/hapi.exe release/hapi-windows-x64.exe
ls -la release/
- name: Create Release
if: ${{ github.event.inputs.release_binaries == 'true' && github.event.inputs.release_tag != '' }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.release_tag }}
name: ${{ github.event.inputs.release_tag }} (${{ steps.info.outputs.short_sha }})
body: |
HAPI binaries built from [${{ github.event.inputs.repository }}](https://github.com/${{ github.event.inputs.repository }}) `${{ github.event.inputs.ref }}`.
- Version: ${{ steps.info.outputs.version }}
- Commit: `${{ steps.info.outputs.short_sha }}`
files: release/*
fail_on_unmatched_files: true
-48
View File
@@ -1,48 +0,0 @@
name: Build and Push Origin Docker Image to GHCR
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=origin
- uses: docker/build-push-action@v6
with:
context: ./origin
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
-79
View File
@@ -1,79 +0,0 @@
name: Build and Push Self Docker Image to GHCR
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Checkout hapi self branch
uses: actions/checkout@v4
with:
repository: arkylin/hapi
ref: self
path: hapi-src
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.14
- name: Install dependencies
working-directory: hapi-src
run: bun install
- name: Build Linux binaries
working-directory: hapi-src
run: |
bun run download:tunwg
bun run build:web
cd hub && bun run generate:embedded-web-assets
cd ../cli && bun run build:exe:allinone --target bun-linux-x64-baseline
bun run build:exe:allinone --target bun-linux-arm64
- name: Copy binaries to Docker context
run: |
mkdir -p self
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi self/hapi-amd64
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi self/hapi-arm64
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=self
- uses: docker/build-push-action@v6
with:
context: ./self
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
@@ -1,76 +0,0 @@
name: Release Origin Binaries
on:
workflow_dispatch:
inputs:
commit:
description: 'Commit SHA to build (leave empty for latest main branch)'
required: false
tag:
description: 'Release tag (leave empty for auto-generated)'
required: false
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout hapi main branch
uses: actions/checkout@v4
with:
repository: tiann/hapi
ref: ${{ github.event.inputs.commit || 'main' }}
path: hapi-src
- name: Get version info
id: info
working-directory: hapi-src
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
VERSION=$(jq -r '.version' cli/package.json)
INPUT_TAG="${{ github.event.inputs.tag }}"
if [ -n "$INPUT_TAG" ]; then
TAG="$INPUT_TAG"
else
TAG="origin-${SHORT_SHA}"
fi
echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Building version $VERSION @ $SHORT_SHA, release tag=$TAG"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.14
- name: Build all platform binaries
working-directory: hapi-src
run: |
bun install
bun run build:single-exe:all
- name: Prepare release artifacts
run: |
mkdir -p release
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi release/hapi-linux-x64
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi release/hapi-linux-arm64
cp hapi-src/cli/dist-exe/bun-darwin-x64/hapi release/hapi-darwin-x64
cp hapi-src/cli/dist-exe/bun-darwin-arm64/hapi release/hapi-darwin-arm64
cp hapi-src/cli/dist-exe/bun-windows-x64/hapi.exe release/hapi-windows-x64.exe
ls -la release/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.tag || format('origin-{0}', steps.info.outputs.short_sha) }}
name: Origin Build ${{ steps.info.outputs.version }} (${{ steps.info.outputs.short_sha }})
body: |
Origin-built hapi binaries from [tiann/hapi](https://github.com/tiann/hapi) `main` branch.
- Version: ${{ steps.info.outputs.version }}
- Commit: `${{ steps.info.outputs.short_sha }}`
files: release/*
fail_on_unmatched_files: true
@@ -1,76 +0,0 @@
name: Release Self Binaries
on:
workflow_dispatch:
inputs:
commit:
description: 'Commit SHA to build (leave empty for latest self branch)'
required: false
tag:
description: 'Release tag (leave empty for auto-generated)'
required: false
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout hapi self branch
uses: actions/checkout@v4
with:
repository: arkylin/hapi
ref: ${{ github.event.inputs.commit || 'self' }}
path: hapi-src
- name: Get version info
id: info
working-directory: hapi-src
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
VERSION=$(jq -r '.version' cli/package.json)
INPUT_TAG="${{ github.event.inputs.tag }}"
if [ -n "$INPUT_TAG" ]; then
TAG="$INPUT_TAG"
else
TAG="self-${SHORT_SHA}"
fi
echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Building version $VERSION @ $SHORT_SHA, release tag=$TAG"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.14
- name: Build all platform binaries
working-directory: hapi-src
run: |
bun install
bun run build:single-exe:all
- name: Prepare release artifacts
run: |
mkdir -p release
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi release/hapi-linux-x64
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi release/hapi-linux-arm64
cp hapi-src/cli/dist-exe/bun-darwin-x64/hapi release/hapi-darwin-x64
cp hapi-src/cli/dist-exe/bun-darwin-arm64/hapi release/hapi-darwin-arm64
cp hapi-src/cli/dist-exe/bun-windows-x64/hapi.exe release/hapi-windows-x64.exe
ls -la release/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.tag || format('self-{0}', steps.info.outputs.short_sha) }}
name: Self Build ${{ steps.info.outputs.version }} (${{ steps.info.outputs.short_sha }})
body: |
Self-built hapi binaries from [arkylin/hapi](https://github.com/arkylin/hapi) `self` branch.
- Version: ${{ steps.info.outputs.version }}
- Commit: `${{ steps.info.outputs.short_sha }}`
files: release/*
fail_on_unmatched_files: true