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