Repository navigation
workspace: project-root file tree & fuzzy picker follow the opened file #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| # 打 v* 标签(如 git tag v0.1.0 && git push origin v0.1.0)时, | |
| # 在 4 个平台目标上编译 oz 并发布到 GitHub Release: | |
| # x86_64-linux / aarch64-linux(Linux 交叉编译,glibc 2.31 基线兼容老发行版) | |
| # x86_64-macos / aarch64-macos(macOS 双架构) | |
| # 每个产物附带 sha256,用户解压即用,无需安装 Zig。 | |
| on: | |
| push: | |
| tags: ["v*"] | |
| permissions: | |
| contents: write # 创建 Release 并上传产物 | |
| jobs: | |
| build: | |
| name: ${{ matrix.name }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false # 一个平台失败不阻塞其他平台 | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-linux-gnu.2.31 | |
| name: x86_64-linux | |
| - os: ubuntu-latest | |
| target: aarch64-linux-gnu.2.31 | |
| name: aarch64-linux | |
| - os: macos-15 # Apple Silicon runner | |
| target: aarch64-macos | |
| name: aarch64-macos | |
| - os: macos-15 | |
| target: x86_64-macos | |
| name: x86_64-macos | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cache Zig toolchain | |
| uses: actions/cache@v4 | |
| with: | |
| path: zig-*.tar.xz | |
| key: zig-${{ runner.os }}-${{ runner.arch }}-0.16.0 | |
| # 手动安装 Zig 0.16.0(mlugg/setup-zig 的镜像经常 404/502, | |
| # 且其 action 基于被弃用的 Node 20):官方源优先,带重试; | |
| # 失败后依次尝试备用镜像。tar.xz 命中 actions/cache 时秒装。 | |
| # 注意:下载的 Zig 必须匹配 RUNNER 架构(交叉编译是让本机 zig | |
| # 产出别的 target,不是让 target 的 zig 在 runner 上运行)。 | |
| - name: Install Zig 0.16.0 | |
| env: | |
| ZIG_VERSION: 0.16.0 | |
| run: | | |
| set -euo pipefail | |
| case "${{ runner.os }}-${{ runner.arch }}" in | |
| Linux-X64) triple="x86_64-linux" ;; | |
| Linux-ARM64) triple="aarch64-linux" ;; | |
| macOS-X64) triple="x86_64-macos" ;; | |
| macOS-ARM64) triple="aarch64-macos" ;; | |
| *) echo "unsupported runner: ${{ runner.os }}-${{ runner.arch }}"; exit 1 ;; | |
| esac | |
| file="zig-${triple}-${ZIG_VERSION}.tar.xz" | |
| sources=( | |
| "https://ziglang.org/download/${ZIG_VERSION}/${file}" | |
| "https://pkg.machengine.org/zig/${file}" | |
| "https://zig.linus.dev/zig/${file}" | |
| "https://zigmirror.hryx.net/zig/${file}" | |
| ) | |
| if [ ! -f "$file" ]; then | |
| ok=0 | |
| for u in "${sources[@]}"; do | |
| echo "downloading ${u}" | |
| if curl -fL --retry 5 --retry-all-errors --connect-timeout 20 -o "$file" "$u"; then | |
| ok=1 | |
| break | |
| fi | |
| done | |
| [ "$ok" = 1 ] || { echo "all Zig download sources failed"; exit 1; } | |
| fi | |
| tar -xf "$file" | |
| # GITHUB_PATH 只影响后续步骤;本步骤内先手动 export 以便校验 | |
| export PATH="$PWD/zig-${triple}-${ZIG_VERSION}:$PATH" | |
| echo "$PWD/zig-${triple}-${ZIG_VERSION}" >> "$GITHUB_PATH" | |
| zig version | |
| - name: Build (ReleaseFast + strip) | |
| run: zig build -Doptimize=ReleaseFast -Dstrip -Dtarget=${{ matrix.target }} | |
| - name: Package | |
| run: | | |
| mkdir -p dist | |
| cp zig-out/bin/oz dist/oz | |
| tar -C dist -czf oz-${{ matrix.name }}.tar.gz oz | |
| sha256sum oz-${{ matrix.name }}.tar.gz > oz-${{ matrix.name }}.tar.gz.sha256 | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: oz-${{ matrix.name }} | |
| path: | | |
| oz-${{ matrix.name }}.tar.gz | |
| oz-${{ matrix.name }}.tar.gz.sha256 | |
| if-no-files-found: error | |
| release: | |
| name: Publish GitHub Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Collect artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: assets | |
| merge-multiple: true | |
| - name: Publish | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: assets/* | |
| generate_release_notes: true |