Skip to content

Commit

Permalink
.github/workflows: add build and release binary executable
Browse files Browse the repository at this point in the history
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
  • Loading branch information
imlk0 committed Feb 24, 2025
1 parent 17d34e0 commit 13fc107
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/build-binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build Binary Executable

on:
push:
branches:
- master
tags:
- "v*.*.*"
pull_request:

jobs:
build-all:
strategy:
matrix:
target:
- "aarch64-apple-darwin"
- "x86_64-apple-darwin"
- "x86_64-unknown-linux-gnu"
- "aarch64-unknown-linux-gnu"
# - "x86_64-pc-windows-msvc"
name: Build For ${{ matrix.target }}
uses: ./.github/workflows/zigbuild.yml
with:
target: ${{ matrix.target }}
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: build-all
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: product
pattern: name-*
merge-multiple: false
- name: compress
run: |
cd product
for dir in */; do
dirname="${dir%/}"
if [[ $dirname == *"windows"* ]]; then
echo "package $dirname to $dirname.zip"
zip -r "$dirname.zip" "$dirname"
else
echo "package $dirname to $dirname.tar.gz"
tar -czf "$dirname.tar.gz" "$dirname"
fi
done
- name: List Directory
run: ls -R product
- name: Upload Release
uses: softprops/action-gh-release@v2
with:
draft: false
fail_on_unmatched_files: true
prerelease: false
files: |
./product/*.zip
./product/*.tar.gz
48 changes: 48 additions & 0 deletions .github/workflows/zigbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Zigbuild Specify Target

on:
workflow_dispatch:
inputs:
target:
required: true
type: string
description: compile target
workflow_call:
inputs:
target:
required: true
type: string
description: compile target

jobs:
build:
runs-on: ${{ contains( inputs.target, 'linux' ) && 'ubuntu-latest' || ( contains( inputs.target, 'apple' ) && 'macos-latest' || ( contains( inputs.target, 'windows' ) && 'windows-latest' || 'ubuntu-latest' ) ) }}
env:
build-tool: ${{ contains( inputs.target, 'windows-msvc' ) && 'build' || 'zigbuild' }}
executable: ./target/${{inputs.target}}/release/*.exe
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup protoc
uses: arduino/setup-protoc@v3.0.0
- name: install target
run: rustup target add ${{ inputs.target }}
- uses: goto-bus-stop/setup-zig@v2
if: ${{ env.build-tool == 'zigbuild' }}
- name: Install cargo-zigbuild
if: ${{ env.build-tool == 'zigbuild' }}
run: rustup toolchain add nightly && cargo +nightly install cargo-zigbuild
- name: cargo compile
run: cargo ${{ env.build-tool }} --target ${{ inputs.target }} --release
- name: show target
run: ls -R ./target
- name: Get product path
if: ${{ runner.os != 'Windows' }}
run: echo "executable=$(find . -maxdepth 4 -type f -exec file {} \; | grep 'executable' | grep 'target' | grep -o '^[^:]*')" >> "$GITHUB_ENV"
- name: Upload product as an artifact
uses: actions/upload-artifact@v4
with:
name: executable
path: |
${{ env.executable }}

0 comments on commit 13fc107

Please sign in to comment.