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
+2 -29
View File
@@ -1,38 +1,11 @@
FROM oven/bun:1.3.14-slim AS builder
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates unzip \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
RUN git clone --depth 1 --branch main https://github.com/tiann/hapi.git .
RUN bun install
RUN bun run download:tunwg
RUN bun run build:web
RUN cd hub && bun run generate:embedded-web-assets
ARG TARGETARCH
RUN case "$TARGETARCH" in \
amd64) \
cd /build/cli && bun run build:exe:allinone --target bun-linux-x64-baseline && \
cp dist-exe/bun-linux-x64-baseline/hapi /tmp/hapi \
;; \
arm64) \
cd /build/cli && bun run build:exe:allinone --target bun-linux-arm64 && \
cp dist-exe/bun-linux-arm64/hapi /tmp/hapi \
;; \
*) \
echo "Unsupported architecture: $TARGETARCH" && exit 1 \
;; \
esac
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /tmp/hapi /usr/local/bin/hapi
ARG TARGETARCH
COPY hapi-${TARGETARCH} /usr/local/bin/hapi
RUN chmod +x /usr/local/bin/hapi
RUN mkdir -p /root/.hapi
+22
View File
@@ -7,9 +7,11 @@ ARCH=$(uname -m)
case "$ARCH" in
x86_64)
HAPI_ARCH="amd64"
BINARY_DIR="bun-linux-x64-baseline"
;;
aarch64|arm64)
HAPI_ARCH="arm64"
BINARY_DIR="bun-linux-arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
@@ -17,10 +19,30 @@ case "$ARCH" in
;;
esac
BUILD_DIR=$(mktemp -d)
trap 'rm -rf "$BUILD_DIR"' EXIT
echo "Cloning tiann/hapi@main into $BUILD_DIR ..."
git clone --depth 1 --branch main https://github.com/tiann/hapi.git "$BUILD_DIR"
cd "$BUILD_DIR"
bun install
bun run build:single-exe
BINARY_PATH="$BUILD_DIR/cli/dist-exe/$BINARY_DIR/hapi"
if [ ! -f "$BINARY_PATH" ]; then
echo "Binary not found: $BINARY_PATH"
exit 1
fi
cp "$BINARY_PATH" "$SCRIPT_DIR/hapi-${HAPI_ARCH}"
docker build \
--build-arg "TARGETARCH=${HAPI_ARCH}" \
-t "hapi:origin" \
-f "$SCRIPT_DIR/Dockerfile" \
"$SCRIPT_DIR/"
rm -f "$SCRIPT_DIR/hapi-${HAPI_ARCH}"
echo "Built hapi:origin for ${HAPI_ARCH}"