Files
quickjump/.github/workflows/build.yml
2026-02-04 18:13:32 +08:00

127 lines
3.6 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Cross Platform Build
on:
push:
tags:
- 'v*'
jobs:
build:
name: ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Linux x86_64
- os: ubuntu-latest
arch: x86_64
ext: ""
# macOS Apple Silicon
- os: macos-latest
arch: arm64
ext: ""
# Windows
- os: windows-latest
arch: x86_64
ext: ".exe"
steps:
- uses: actions/checkout@v4
# 安装 GHC 和 Cabal
- name: Setup Haskell
uses: haskell-actions/setup@v2
with:
ghc-version: '9.6.7'
cabal-version: '3.12'
# 缓存依赖加速构建
- name: Cache Cabal
uses: actions/cache@v4
with:
path: |
~/.cabal/store
dist-newstyle
key: ${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('**/*.cabal') }}
# 配置静态链接Linux
- name: Configure Static Build (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
echo "GHC_MUSL=1" >> $GITHUB_ENV
# 构建
- name: Build
run: |
cabal update
cabal build --enable-executable-stripping --disable-debug-info -j2
# 安装 UPX
- name: Install UPX
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
wget https://github.com/upx/upx/releases/download/v5.1.0/upx-5.1.0-amd64_linux.tar.xz
tar -xf upx-5.1.0-amd64_linux.tar.xz
sudo mv upx-5.1.0-amd64_linux/upx /usr/local/bin/
rm -rf upx-5.1.0-amd64_linux*
elif [ "$RUNNER_OS" == "macOS" ]; then
wget https://github.com/upx/upx/releases/download/v5.1.0/upx-5.1.0-arm64_macos.tar.xz
tar -xf upx-5.1.0-arm64_macos.tar.xz
sudo mv upx-5.1.0-arm64_macos/upx /usr/local/bin/
rm -rf upx-5.1.0-arm64_macos*
elif [ "$RUNNER_OS" == "Windows" ]; then
curl -L -o upx.zip https://github.com/upx/upx/releases/download/v5.1.0/upx-5.1.0-win64.zip
unzip -o upx.zip
echo "$PWD/upx-5.1.0-win64" >> $GITHUB_PATH
rm upx.zip
fi
# 使用 UPX 压缩可执行文件
- name: Compress with UPX
shell: bash
run: |
EXE_PATH=$(cabal list-bin quickjump)
upx --best "$EXE_PATH"
# 提取可执行文件路径
- name: Find Executable
id: exe
shell: bash
run: |
EXE_PATH=$(cabal list-bin quickjump)
echo "path=$EXE_PATH" >> $GITHUB_OUTPUT
# 重命名为标准格式
- name: Rename Artifact
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/}
cp "${{ steps.exe.outputs.path }}" ./quickjump-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}
# 上传产物
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: quickjump-${{ matrix.os }}-${{ matrix.arch }}
path: quickjump-*-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}
# 创建 Release
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
path: ./artifacts
merge-multiple: true
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: ./artifacts/*
generate_release_notes: true