From 8944e5b736df1fa5a99654053b71fde5eb35e5ea Mon Sep 17 00:00:00 2001 From: zu1k Date: Sun, 1 Jan 2023 19:15:15 +0800 Subject: [PATCH] chore: add release ci --- .github/workflows/release.yml | 107 +++++++++++++--------------------- Makefile | 3 + scripts/build_release.sh | 42 +++++++++---- 3 files changed, 73 insertions(+), 79 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eff98a4a..3e9bd5e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,46 +1,39 @@ -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: @@ -48,60 +41,38 @@ jobs: 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, '-') }} diff --git a/Makefile b/Makefile index 9100ac13..66df8fa8 100644 --- a/Makefile +++ b/Makefile @@ -22,3 +22,6 @@ endif clean: cargo clean rm -rf release + +releases: + cd scripts && ./build_release.sh -a a diff --git a/scripts/build_release.sh b/scripts/build_release.sh index be4e1ddf..b871dbe3 100755 --- a/scripts/build_release.sh +++ b/scripts/build_release.sh @@ -6,7 +6,22 @@ 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) @@ -14,6 +29,9 @@ while getopts "t:f:u" opt; do t) targets+=($OPTARG) ;; + a) + targets+=($ALL_TARGETS) + ;; f) features+=($OPTARG) ;; @@ -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 @@ -59,14 +79,13 @@ 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 @@ -74,13 +93,14 @@ function build() { 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 @@ -96,4 +116,4 @@ function build() { for target in "${targets[@]}"; do cargo clean; build "$target"; -done \ No newline at end of file +done