Skip to content

Commit

Permalink
chore: add release ci
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Jan 1, 2023
1 parent ab61398 commit 8944e5b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 79 deletions.
107 changes: 39 additions & 68 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,107 +1,78 @@
name: Make Distribution

name: Build Releases
on:
workflow_dispatch:
push:
tags:
- "*"
release:
types: [published]

env:
CARGO_TERM_COLOR: always
AUTH_SERVER_IP: ${{ secrets.AUTH_SERVER_IP }}


jobs:
make_dist:
name: Make Distribution File(${{ matrix.os }})
runs-on: ${{ matrix.os }}-latest
name: Build Release on (${{ matrix.platform }})
strategy:
fail-fast: false
matrix:
include:
- os: windows
filetag: win-x86_64
- os: ubuntu
filetag: linux-x86_64
- os: macos
filetag: macos-x86_64
platform: [macos-latest, ubuntu-20.04, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: |
mkdir dist
pushd frontend
pnpm install && pnpm build
popd
- name: Make executable
make frontend_preinstall
- name: Build dist
run: |
cargo build --release -p zlib-searcher
- name: Make dist(MacOS)
if: matrix.os == 'macos'
make frontend
- name: Build on Linux
if: matrix.platform == 'ubuntu-20.04'
run: |
cp target/release/zlib-searcher .
zip zlib-searcher-macos.zip zlib-searcher && cp zlib-searcher-macos.zip dist/
- name: Make dist(Windows)
if: matrix.os == 'windows'
cargo install cross
make releases
- name: Build on MacOS
if: matrix.platform == 'macos-latest'
run: |
cp target/release/zlib-searcher.exe .
Compress-Archive -Path zlib-searcher.exe -DestinationPath dist/zlib-searcher-windows.zip
- name: Make dist(Linux)
if: matrix.os == 'ubuntu'
mkdir -p target/dist
rustup target add x86_64-apple-darwin
cargo build --release --target x86_64-apple-darwin -p zlib-searcher
cd target/x86_64-apple-darwin/release && zip zlib-searcher-x86_64-apple-darwin.zip zlib-searcher && cp zlib-searcher-x86_64-apple-darwin.zip ../../dist/ && cd ../../../
rustup target add aarch64-apple-darwin
cargo build --release --target aarch64-apple-darwin -p zlib-searcher
cd target/aarch64-apple-darwin/release && zip zlib-searcher-aarch64-apple-darwin.zip zlib-searcher && cp zlib-searcher-aarch64-apple-darwin.zip ../../dist/ && cd ../../../
- name: Build on Windows
if: matrix.platform == 'windows-latest'
run: |
cp target/release/zlib-searcher .
zip zlib-searcher-linux.zip zlib-searcher && cp zlib-searcher-linux.zip dist/
- name: Archive Distribution Files
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/*

create_release:
name: Create GitHub Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: make_dist

steps:
- uses: actions/checkout@v3

- name: Get Dists
uses: actions/download-artifact@v2
with:
name: dist
path: dist

- name: Create GitHub Release
mkdir -p target/dist
rustup target add x86_64-pc-windows-msvc
cargo build --release --target x86_64-pc-windows-msvc -p zlib-searcher
cd target/x86_64-pc-windows-msvc/release && Compress-Archive -Path zlib-searcher.exe -DestinationPath zlib-searcher-x86_64-pc-windows-msvc.zip && cp zlib-searcher-x86_64-pc-windows-msvc.zip ../../dist/ && cd ../../../
- name: Upload Github Assets
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/*

- uses: actions/setup-node@v3
with:
node-version: 16.x
files: target/dist/*
prerelease: ${{ contains(github.ref, '-') }}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ endif
clean:
cargo clean
rm -rf release

releases:
cd scripts && ./build_release.sh -a a
42 changes: 31 additions & 11 deletions scripts/build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,32 @@ project=zlib-searcher
targets=()
features=()

while getopts "t:f:u" opt; do
ALL_TARGETS="
i686-unknown-linux-musl
x86_64-pc-windows-gnu
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
armv7-unknown-linux-musleabihf
armv7-unknown-linux-gnueabihf
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
"

while getopts "p:t:a:f" opt; do
case $opt in
p)
project=($OPTARG)
;;
t)
targets+=($OPTARG)
;;
a)
targets+=($ALL_TARGETS)
;;
f)
features+=($OPTARG)
;;
Expand Down Expand Up @@ -44,11 +62,13 @@ function build() {
cross build --target "${TARGET}" \
--default-features=false
--features "${TARGET_FEATURES}" \
-p zlib-searcher \
--release
else
echo "* Building ${project} package for ${TARGET} ..."

cross build --target "${TARGET}" \
-p zlib-searcher \
--release
fi

Expand All @@ -59,28 +79,28 @@ function build() {
PKG_DIR="${CUR_DIR}/../release"
mkdir -p "${PKG_DIR}"

if [[ "$TARGET" == *"-linux-"* ]]; then
PKG_NAME="${project}-${TARGET}.tar.gz"
if [[ "$TARGET" == *"-windows-"* ]]; then
PKG_NAME="${project}-${TARGET}.zip"
PKG_PATH="${PKG_DIR}/${PKG_NAME}"

echo "* Packaging ZIP in ${PKG_PATH} ..."
cd ${RELEASE_DIR}

echo "* Packaging gz in ${PKG_PATH} ..."
tar -czf ${PKG_PATH} ${project}
zip ${PKG_PATH} ${project}.exe

if [[ $? != "0" ]]; then
exit 1
fi

cd "${PKG_DIR}"
shasum -a 256 "${PKG_NAME}" > "${PKG_NAME}.sha256"
elif [[ "$TARGET" == *"-windows-"* ]]; then
PKG_NAME="${project}-${TARGET}.zip"
else
PKG_NAME="${project}-${TARGET}.tar.gz"
PKG_PATH="${PKG_DIR}/${PKG_NAME}"

echo "* Packaging ZIP in ${PKG_PATH} ..."
cd ${RELEASE_DIR}
zip ${PKG_PATH} ${project}.exe

echo "* Packaging gz in ${PKG_PATH} ..."
tar -czf ${PKG_PATH} ${project}

if [[ $? != "0" ]]; then
exit 1
Expand All @@ -96,4 +116,4 @@ function build() {
for target in "${targets[@]}"; do
cargo clean;
build "$target";
done
done

0 comments on commit 8944e5b

Please sign in to comment.