mirror of
https://github.com/house-of-vanity/khm.git
synced 2025-08-21 14:27:14 +00:00
262 lines
9.9 KiB
YAML
262 lines
9.9 KiB
YAML
name: Rust static build and publish
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*.*.*'
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
CLI_BINARY_NAME: khm
|
|
DESKTOP_BINARY_NAME: khm-desktop
|
|
|
|
jobs:
|
|
build:
|
|
name: Build static binary
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
# - os: ubuntu-latest
|
|
# build_target: x86_64-unknown-linux-musl
|
|
# platform_name: linux-amd64-musl
|
|
# build_type: musl
|
|
- os: ubuntu-latest
|
|
build_target: x86_64-unknown-linux-gnu
|
|
platform_name: linux-amd64
|
|
build_type: dynamic
|
|
- os: ubuntu-latest
|
|
build_target: aarch64-unknown-linux-gnu
|
|
platform_name: linux-arm64
|
|
build_type: dynamic
|
|
- os: windows-latest
|
|
build_target: x86_64-pc-windows-msvc
|
|
platform_name: windows-amd64
|
|
build_type: default
|
|
- os: macos-latest
|
|
build_target: aarch64-apple-darwin
|
|
platform_name: macos-arm64
|
|
build_type: default
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Cache Cargo registry
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/registry
|
|
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-registry-
|
|
|
|
- name: Cache Cargo index
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/git
|
|
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-index-
|
|
|
|
- name: Cache Cargo build
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: target
|
|
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-build-
|
|
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
|
|
- name: Install rust targets
|
|
run: rustup target add ${{ matrix.build_target }}
|
|
|
|
- name: Install Linux x86_64 dependencies
|
|
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'dynamic' && matrix.build_target == 'x86_64-unknown-linux-gnu'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y libssl-dev pkg-config libgtk-3-dev libglib2.0-dev libcairo2-dev libpango1.0-dev libatk1.0-dev libgdk-pixbuf2.0-dev libxdo-dev
|
|
|
|
- name: Install Linux ARM64 cross-compilation dependencies
|
|
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'dynamic' && matrix.build_target == 'aarch64-unknown-linux-gnu'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y gcc-aarch64-linux-gnu pkg-config libssl-dev
|
|
sudo dpkg --add-architecture arm64
|
|
sudo apt-get update
|
|
sudo apt-get install -y libssl-dev:arm64 libgtk-3-dev:arm64 libglib2.0-dev:arm64 libcairo2-dev:arm64 libpango1.0-dev:arm64 libatk1.0-dev:arm64 libgdk-pixbuf2.0-dev:arm64 libxdo-dev:arm64
|
|
|
|
- name: Build Linux x86_64
|
|
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'dynamic' && matrix.build_target == 'x86_64-unknown-linux-gnu'
|
|
run: cargo build --target ${{ matrix.build_target }} --release --bins
|
|
|
|
- name: Build Linux ARM64
|
|
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'dynamic' && matrix.build_target == 'aarch64-unknown-linux-gnu'
|
|
env:
|
|
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
|
|
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
|
|
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
|
|
PKG_CONFIG_ALLOW_CROSS: 1
|
|
PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig
|
|
run: cargo build --target ${{ matrix.build_target }} --release --bins
|
|
|
|
# - name: Build Linux MUSL (no GUI)
|
|
# if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'musl'
|
|
# uses: gmiam/rust-musl-action@master
|
|
# with:
|
|
# args: |
|
|
# sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list
|
|
# sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list
|
|
# sed -i '/buster-updates/d' /etc/apt/sources.list
|
|
# apt-get update && apt-get install -y pkg-config
|
|
# cargo build --target ${{ matrix.build_target }} --release --no-default-features --features server
|
|
|
|
- name: Build MacOS
|
|
if: matrix.os == 'macos-latest'
|
|
run: cargo build --target ${{ matrix.build_target }} --release --bins
|
|
|
|
- name: Build Windows
|
|
if: matrix.os == 'windows-latest'
|
|
run: cargo build --target ${{ matrix.build_target }} --release --bins
|
|
|
|
- name: Upload CLI artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ env.CLI_BINARY_NAME }}_${{ matrix.platform_name }}
|
|
path: |
|
|
target/${{ matrix.build_target }}/release/${{ env.CLI_BINARY_NAME }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
|
|
|
|
- name: Upload Desktop artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ env.DESKTOP_BINARY_NAME }}_${{ matrix.platform_name }}
|
|
path: |
|
|
target/${{ matrix.build_target }}/release/${{ env.DESKTOP_BINARY_NAME }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
|
|
continue-on-error: true # Don't fail if desktop binary doesn't build on some platforms
|
|
|
|
release:
|
|
name: Create Release and Upload Assets
|
|
if: always() # Always run even if some builds fail
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: artifacts/
|
|
|
|
- name: Prepare release assets
|
|
run: |
|
|
mkdir -p release-assets/
|
|
# Copy files with proper naming from each artifact directory
|
|
for artifact_dir in artifacts/*/; do
|
|
if [[ -d "$artifact_dir" ]]; then
|
|
artifact_name=$(basename "$artifact_dir")
|
|
echo "Processing artifact: $artifact_name"
|
|
|
|
# Extract binary type and platform from artifact name
|
|
if [[ "$artifact_name" =~ ^khm-desktop_(.*)$ ]]; then
|
|
binary_type="desktop"
|
|
platform="${BASH_REMATCH[1]}"
|
|
binary_name="${{ env.DESKTOP_BINARY_NAME }}"
|
|
elif [[ "$artifact_name" =~ ^khm_(.*)$ ]]; then
|
|
binary_type="cli"
|
|
platform="${BASH_REMATCH[1]}"
|
|
binary_name="${{ env.CLI_BINARY_NAME }}"
|
|
else
|
|
echo "Unknown artifact format: $artifact_name"
|
|
continue
|
|
fi
|
|
|
|
echo "Binary type: $binary_type, Platform: $platform, Binary name: $binary_name"
|
|
|
|
# For Windows, look for .exe file specifically
|
|
if [[ "$platform" == "windows-amd64" ]]; then
|
|
exe_file=$(find "$artifact_dir" -name "${binary_name}.exe" -type f | head -1)
|
|
if [[ -n "$exe_file" ]]; then
|
|
cp "$exe_file" "release-assets/${binary_name}_${platform}.exe"
|
|
echo "Copied: $exe_file -> release-assets/${binary_name}_${platform}.exe"
|
|
fi
|
|
else
|
|
# For Linux/macOS, look for binary without extension
|
|
binary_file=$(find "$artifact_dir" -name "${binary_name}" -type f | head -1)
|
|
if [[ -n "$binary_file" ]]; then
|
|
cp "$binary_file" "release-assets/${binary_name}_${platform}"
|
|
echo "Copied: $binary_file -> release-assets/${binary_name}_${platform}"
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
|
|
echo "Final release assets:"
|
|
ls -la release-assets/
|
|
|
|
- name: Create Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
name: Release ${{ github.ref_name }}
|
|
files: release-assets/*
|
|
draft: false
|
|
prerelease: false
|
|
generate_release_notes: true
|
|
fail_on_unmatched_files: false
|
|
|
|
build_docker:
|
|
name: Build and Publish Docker Image
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download Linux AMD64 CLI artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: ${{ env.CLI_BINARY_NAME }}_linux-amd64
|
|
path: amd64/
|
|
|
|
- name: Download Linux ARM64 CLI artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: ${{ env.CLI_BINARY_NAME }}_linux-arm64
|
|
path: arm64/
|
|
|
|
- name: Prepare binaries for multi-arch build
|
|
run: |
|
|
mkdir -p bin/linux_amd64 bin/linux_arm64
|
|
cp amd64/${{ env.CLI_BINARY_NAME }} bin/linux_amd64/${{ env.CLI_BINARY_NAME }}
|
|
cp arm64/${{ env.CLI_BINARY_NAME }} bin/linux_arm64/${{ env.CLI_BINARY_NAME }}
|
|
chmod +x bin/linux_amd64/${{ env.CLI_BINARY_NAME }}
|
|
chmod +x bin/linux_arm64/${{ env.CLI_BINARY_NAME }}
|
|
ls -la bin/*/
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ultradesu
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Set outputs
|
|
id: get_tag
|
|
run: |
|
|
echo "tag=$(echo ${GITHUB_REF} | cut -d'/' -f3)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ultradesu/${{ env.CLI_BINARY_NAME }}:latest,ultradesu/${{ env.CLI_BINARY_NAME }}:${{ steps.get_tag.outputs.tag }}
|
|
|