mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 08:01:10 +00:00
182 lines
5.1 KiB
YAML
182 lines
5.1 KiB
YAML
name: Build Release Binaries
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'Version string used when manually triggered'
|
|
required: false
|
|
default: 'dev'
|
|
enable_upx:
|
|
description: 'Enable UPX compression (true/false)'
|
|
required: false
|
|
default: 'false'
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
concurrency:
|
|
group: binary-release-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
frontend:
|
|
name: Build frontend assets
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm'
|
|
cache-dependency-path: web/package-lock.json
|
|
|
|
- name: Build frontend assets
|
|
shell: bash
|
|
run: |
|
|
npm ci --prefix web
|
|
npm run build --prefix web
|
|
|
|
- name: Upload frontend dist
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: web-dist
|
|
path: web/dist
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
build:
|
|
name: Build ${{ matrix.artifact_arch }}
|
|
runs-on: ubuntu-latest
|
|
needs: frontend
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- goarch: amd64
|
|
goarm: ''
|
|
artifact_arch: amd64
|
|
- goarch: arm64
|
|
goarm: ''
|
|
artifact_arch: arm64
|
|
- goarch: arm
|
|
goarm: '7'
|
|
artifact_arch: armv7
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: Prepare build vars
|
|
id: vars
|
|
shell: bash
|
|
run: |
|
|
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
|
VERSION="${GITHUB_REF_NAME}"
|
|
else
|
|
VERSION="${{ github.event.inputs.version || 'dev' }}"
|
|
fi
|
|
BUILDTIME="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
|
|
ENABLE_UPX_RAW="${{ github.event.inputs.enable_upx || 'false' }}"
|
|
case "${ENABLE_UPX_RAW}" in
|
|
true|1|yes|on) ENABLE_UPX=1 ;;
|
|
*) ENABLE_UPX=0 ;;
|
|
esac
|
|
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
|
|
echo "buildtime=${BUILDTIME}" >> "${GITHUB_OUTPUT}"
|
|
echo "enable_upx=${ENABLE_UPX}" >> "${GITHUB_OUTPUT}"
|
|
|
|
- name: Download frontend dist
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: web-dist
|
|
path: web/dist
|
|
|
|
- name: Sync frontend dist for embed
|
|
shell: bash
|
|
run: |
|
|
rm -rf internal/web/dist
|
|
mkdir -p internal/web
|
|
cp -R web/dist internal/web/dist
|
|
|
|
- name: Build binary
|
|
shell: bash
|
|
run: |
|
|
mkdir -p dist
|
|
GOWORK=off CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.goarch }} GOARM=${{ matrix.goarm }} \
|
|
go build -trimpath -buildvcs=false -tags "with_utls nomsgpack" \
|
|
-ldflags "-s -w -X 'github.com/iniwex5/vohive/internal/global.Version=${{ steps.vars.outputs.version }}' -X 'github.com/iniwex5/vohive/internal/global.BuildTime=${{ steps.vars.outputs.buildtime }}'" \
|
|
-o dist/vo-hive ./cmd/vohive
|
|
|
|
- name: Install UPX
|
|
if: ${{ steps.vars.outputs.enable_upx == '1' }}
|
|
shell: bash
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y upx-ucl || sudo apt-get install -y upx
|
|
|
|
- name: Compress with UPX
|
|
if: ${{ steps.vars.outputs.enable_upx == '1' }}
|
|
shell: bash
|
|
run: |
|
|
upx --best --lzma dist/vo-hive || upx -9 dist/vo-hive
|
|
|
|
- name: Package artifact
|
|
shell: bash
|
|
run: |
|
|
OUT="vohive_${{ steps.vars.outputs.version }}_linux_${{ matrix.artifact_arch }}"
|
|
mkdir -p out
|
|
cp dist/vo-hive "out/${OUT}"
|
|
sha256sum "out/${OUT}" > "out/${OUT}.sha256"
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: binaries-${{ matrix.artifact_arch }}
|
|
path: out/*
|
|
retention-days: 3
|
|
|
|
release:
|
|
name: Publish release assets
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
|
|
steps:
|
|
- name: Prepare release vars
|
|
id: release_vars
|
|
shell: bash
|
|
run: |
|
|
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
|
RELEASE_VERSION="${GITHUB_REF_NAME}"
|
|
else
|
|
RELEASE_VERSION="${{ github.event.inputs.version || 'dev' }}"
|
|
fi
|
|
echo "release_version=${RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: binaries-*
|
|
merge-multiple: true
|
|
path: dist
|
|
|
|
- name: Publish to this GitHub Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: ${{ steps.release_vars.outputs.release_version }}
|
|
files: dist/*
|
|
fail_on_unmatched_files: true
|
|
overwrite_files: true
|