Skip to content

feat: auto-versioning for artifacts and test build release #9

feat: auto-versioning for artifacts and test build release

feat: auto-versioning for artifacts and test build release #9

Workflow file for this run

name: Build & Release
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
jobs:
# โ”€โ”€ ๅˆคๆ–ญๆ˜ฏๅฆ้œ€่ฆๆž„ๅปบ / ๅ‘ๅธƒ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
check:
name: Check commit message
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.flags.outputs.should_build }}
should_release: ${{ steps.flags.outputs.should_release }}
should_publish: ${{ steps.flags.outputs.should_publish }}
version: ${{ steps.flags.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Parse commit message
id: flags
run: |
MSG="${{ github.event.head_commit.message }}"
# ไปŽ Cargo.toml ๆๅ–็‰ˆๆœฌๅท
VERSION="v$(grep '^version' rust/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "๐Ÿ“ฆ Version: $VERSION"
# PR ๅง‹็ปˆๆž„ๅปบ
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "should_build=true" >> "$GITHUB_OUTPUT"
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# "build publish" = ๅฎŒๆ•ดๅ‘ๅธƒๆต็จ‹
if echo "$MSG" | grep -qi "build publish"; then
echo "should_build=true" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "should_publish=true" >> "$GITHUB_OUTPUT"
# "build release" = ๆž„ๅปบ + GitHub Release
elif echo "$MSG" | grep -qi "build release"; then
echo "should_build=true" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
# "build action" = ไป…ๆž„ๅปบ
elif echo "$MSG" | grep -qi "build action"; then
echo "should_build=true" >> "$GITHUB_OUTPUT"
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
else
echo "should_build=false" >> "$GITHUB_OUTPUT"
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
fi
# โ”€โ”€ ๅคšๅนณๅฐๆž„ๅปบ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
build:
name: Build ${{ matrix.name }}
needs: check
if: needs.check.outputs.should_build == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# โ”€โ”€ Windows x64 (MSVC, native) โ”€โ”€
- target: x86_64-pc-windows-msvc
os: windows-latest
name: windows-x86_64
binary: winload.exe
asset: winload-windows-x86_64.exe
# โ”€โ”€ Linux x64 (native) โ”€โ”€
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: linux-x86_64
binary: winload
asset: winload-linux-x86_64
# โ”€โ”€ macOS x64 (build on Apple Silicon runner) โ”€โ”€
- target: x86_64-apple-darwin
os: macos-latest
name: macos-x86_64
binary: winload
asset: winload-macos-x86_64
# โ”€โ”€ macOS ARM64 (Apple Silicon runner) โ”€โ”€
- target: aarch64-apple-darwin
os: macos-latest
name: macos-aarch64
binary: winload
asset: winload-macos-aarch64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: rust -> target
cache-on-failure: true
- name: Build release binary
working-directory: rust
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare artifact
shell: bash
run: |
VERSION="${{ needs.check.outputs.version }}"
ASSET_BASE="${{ matrix.asset }}"
# ๅœจๆ‰ฉๅฑ•ๅๅ‰ๆ’ๅ…ฅ็‰ˆๆœฌๅท
# winload-linux-x86_64 -> winload-linux-x86_64-v0.1.0
# winload-windows-x86_64.exe -> winload-windows-x86_64-v0.1.0.exe
if [[ "$ASSET_BASE" == *.* ]]; then
# ๆœ‰ๆ‰ฉๅฑ•ๅ
BASE_NAME="${ASSET_BASE%.*}"
EXTENSION="${ASSET_BASE##*.}"
ASSET_WITH_VERSION="${BASE_NAME}-${VERSION}.${EXTENSION}"
else
# ๆ— ๆ‰ฉๅฑ•ๅ
ASSET_WITH_VERSION="${ASSET_BASE}-${VERSION}"
fi
echo "๐Ÿ“ฆ Output: $ASSET_WITH_VERSION"
cp "rust/target/${{ matrix.target }}/release/${{ matrix.binary }}" "$ASSET_WITH_VERSION"
echo "asset_name=$ASSET_WITH_VERSION" >> "$GITHUB_ENV"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.asset_name }}
path: ${{ env.asset_name }}
# โ”€โ”€ ๅ‘ๅธƒๅˆฐ GitHub Releases โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
release:
name: Publish Release
needs: [check, build]
if: needs.check.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: List downloaded files
run: |
echo "Downloaded artifacts:"
ls -lh
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check.outputs.version }}
name: "winload ${{ needs.check.outputs.version }}"
generate_release_notes: true
make_latest: true
files: winload-*-${{ needs.check.outputs.version }}*