Skip to content

Commit

Permalink
ci: add workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Liu <sam@secondstate.io>
  • Loading branch information
apepkuss committed Jan 21, 2025
1 parent 60df080 commit 0ea44a5
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build

on:
push:
branches:
- dev
- main
- release-*
- feat-*
- ci-*
- refactor-*
- fix-*
- test-*
paths:
- '.github/workflows/build.yml'
- '**/Cargo.toml'
- '**/*.rs'
- '**/*.sh'
pull_request:
branches:
- dev
- main
types: [opened, synchronize, reopened]
paths:
- '.github/workflows/**'
- '**/Cargo.toml'
- '**/*.rs'
- '**/*.sh'

jobs:
build-wasm:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-13, macos-14, macos-15]
steps:
- name: Clone project
id: checkout
uses: actions/checkout@v3

- name: Install Rust-nightly
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rustfmt, clippy

- name: Install Rust-stable
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Clippy check
run: |
cargo +nightly clippy --all-features -- -D warnings
- name: Format check
run: |
cargo +nightly fmt --all -- --check
- name: Build
run: |
cargo build --release
156 changes: 156 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Release

on:
workflow_dispatch: # manual trigger release
inputs:
create_release:
description: 'Create new release'
required: true
type: boolean
release_version:
description: "Version (e.g. 1.0.0)"
required: true
type: string

jobs:
build:
name: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux-x86_64, macos-x86_64, macos-arm64]
include:
- build: linux-x86_64
os: ubuntu-20.04
rust: nightly
target: x86_64-unknown-linux-gnu
archive-name: server-assistant-x86_64-unknown-linux-gnu.tar.gz
bin-path: linux-x86_64-binary
- build: macos-x86_64
os: macos-latest
rust: nightly
target: x86_64-apple-darwin
archive-name: server-assistant-x86_64-apple-darwin.tar.gz
bin-path: macos-x86_64-binary
- build: macos-arm64
os: macos-latest
rust: nightly
target: aarch64-apple-darwin
archive-name: server-assistant-aarch64-apple-darwin.tar.gz
bin-path: macos-arm64-binary
fail-fast: false

steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
target: ${{ matrix.target }}

- name: Install dependencies
if: matrix.build == 'linux-x86_64'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev pkg-config
rustup target add ${{ matrix.target }}
- name: Build binary
run: cargo build --verbose --release --target ${{ matrix.target }}
env:
RUST_BACKTRACE: 1

- name: Strip binary (linux and macos)
if: matrix.build == 'linux-x86_64' || matrix.build == 'macos-x86_64' || matrix.build == 'macos-arm64'
run: |
strip "target/${{ matrix.target }}/release/gaias"
ls -al "target/${{ matrix.target }}/release/gaias"
- name: Build archive
shell: bash
run: |
mkdir archive
# cp LICENSE README.md archive/
cd archive
if [ "${{ matrix.build }}" = "windows" ]; then
cp "../target/${{ matrix.target }}/release/gaias.exe" ./
7z a "${{ matrix.archive-name }}" gaias.exe
fi
if [ "${{ matrix.build }}" = "linux-x86_64" ]; then
cp "../target/${{ matrix.target }}/release/gaias" ./
sha256sum gaias > SHA256SUM
echo "Debug info(SHA256SUM):"
cat SHA256SUM
tar -czf "${{ matrix.archive-name }}" SHA256SUM gaias
fi
if [ "${{ matrix.build }}" = "macos-x86_64" ] || [ "${{ matrix.build }}" = "macos-arm64" ]; then
cp "../target/${{ matrix.target }}/release/gaias" ./
shasum -a 256 gaias > SHA256SUM
echo "Debug info(SHA256SUM):"
cat SHA256SUM
tar -czf "${{ matrix.archive-name }}" SHA256SUM gaias
fi
ls -al
- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.bin-path }}
path: archive/${{ matrix.archive-name }}

release:
name: release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: linux-x86_64-binary
path: linux-x86_64-binary

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: macos-x86_64-binary
path: macos-x86_64-binary

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: macos-arm64-binary
path: macos-arm64-binary

- name: Display structure of downloaded files
run: |
ls -al
ls -al linux-x86_64-binary
ls -al macos-x86_64-binary
ls -al macos-arm64-binary
- name: Tag and release names
id: tag_and_release_names
run: |
echo "tag_name=${{ github.event.inputs.release_version }}" >> $GITHUB_OUTPUT
echo "release_name=kw-search-server ${{ github.event.inputs.release_version }}" >> $GITHUB_OUTPUT
- name: Create Release and Upload Release Asset
if: ${{ github.event.inputs.create_release == 'true' && github.ref == 'refs/heads/main'}}
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.tag_and_release_names.outputs.release_name }}
tag_name: ${{ steps.tag_and_release_names.outputs.tag_name }}
body: TODO New Release.
draft: true
prerelease: true
files: |
linux-x86_64-binary/*
macos-x86_64-binary/*
macos-arm64-binary/*

0 comments on commit 0ea44a5

Please sign in to comment.