Skip to content

github action: release.yaml #16

github action: release.yaml

github action: release.yaml #16

Workflow file for this run

name: Build and Release Rust Project
on:
push:
branches:
- 'release/**' # Trigger on branches matching release/{version}
jobs:
build:
name: ${{ matrix.target }} (${{ matrix.runner }})
runs-on: ${{ matrix.runner }}
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
platform: linux
arch: amd64
# - runner: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# platform: linux
# arch: arm64
# - runner: macos-12
# target: x86_64-apple-darwin
# platform: darwin
# arch: amd64
# - runner: macos-12
# target: aarch64-apple-darwin
# platform: darwin
# arch: arm64
# - runner: windows-latest
# target: x86_64-pc-windows-msvc
# platform: win32
# arch: amd64
env:
BUILD_TYPE: debug # Set this to "debug" or "release" based on your requirement
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
cache-on-failure: true
- name: Apple M1 setup
if: matrix.target == 'aarch64-apple-darwin'
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Linux ARM setup
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Install MSVC target
if: matrix.target == 'x86_64-pc-windows-msvc'
run: rustup target add x86_64-pc-windows-msvc
- name: Build binaries
working-directory: cli
env:
RUSTFLAGS: '-C target-cpu=native'
shell: bash
run: |
set -eo pipefail
target="${{ matrix.target }}"
flags=()
if [[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]]; then
flags+=(--features jemalloc)
fi
[[ "$target" == *windows* ]] && exe=".exe"
if [[ "${{ env.BUILD_TYPE }}" == "release" ]]; then
cargo build --release --target "$target" "${flags[@]}"
else
cargo build --target "$target" "${flags[@]}"
fi
- name: Archive binaries
working-directory: cli
id: artifacts
env:
PLATFORM_NAME: ${{ matrix.platform }}
TARGET: ${{ matrix.target }}
ARCH: ${{ matrix.arch }}
VERSION_NAME: ${{ github.ref_name }}
shell: bash
run: |
RELEASE_DIR="${{ github.workspace }}/documentation/docs/public/releases"
mkdir -p "$RELEASE_DIR/$VERSION_NAME"
BUILD_DIR="../target/${TARGET}/${{ env.BUILD_TYPE }}"
if [ "$PLATFORM_NAME" == "linux" ]; then
tar -czvf "$RELEASE_DIR/${PLATFORM_NAME}_${ARCH}.tar.gz" -C "$BUILD_DIR" .
cp $BUILD_DIR/* "$RELEASE_DIR/$VERSION_NAME/"
echo "file_name=${PLATFORM_NAME}_${ARCH}.tar.gz" >> $GITHUB_OUTPUT
elif [ "$PLATFORM_NAME" == "darwin" ]; then
tar -czvf "$RELEASE_DIR/${PLATFORM_NAME}_${ARCH}.tar.gz" -C "$BUILD_DIR" .
cp $BUILD_DIR/* "$RELEASE_DIR/$VERSION_NAME/"
echo "file_name=${PLATFORM_NAME}_${ARCH}.tar.gz" >> $GITHUB_OUTPUT
else
cd $BUILD_DIR
7z a -tzip "$RELEASE_DIR/${PLATFORM_NAME}_${ARCH}.zip" *
cp * "$RELEASE_DIR/$VERSION_NAME/"
echo "file_name=${PLATFORM_NAME}_${ARCH}.zip" >> $GITHUB_OUTPUT
fi
- name: Create release
uses: softprops/action-gh-release@v2
with:
name: ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
body: "Release ${{ github.ref_name }}"
files: ${{ steps.artifacts.outputs.file_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push changes
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add documentation/docs/public/releases
git commit -m "Add binaries for ${{ github.ref_name }}"
git push origin HEAD:refs/heads/release/${{ github.ref_name }}
- name: Create or update pull request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Add binaries for ${{ github.ref_name }}"
branch: release/${{ github.ref_name }}
base: master
title: "Release ${{ github.ref_name }}"
body: "This PR merges the release binaries for ${{ github.ref_name }} into master and triggers a deploy."
update-existing: true