From d5a5b4eac2f6bf20d1fd5cb6bc1895a4b0ada587 Mon Sep 17 00:00:00 2001 From: Kaya Gokalp Date: Mon, 5 Sep 2022 18:05:55 -0700 Subject: [PATCH] CI: build binaries in CI --- .github/workflows/ci.yml | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53d00f0..d311a66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -138,3 +138,95 @@ jobs: notify_when: 'failure' env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_NOTIFY_BUILD }} + + build-release: + name: build forc wallet release binaries + runs-on: ${{ matrix.job.os }} + if: github.event_name == 'release' && github.event.action == 'published' + needs: cancel-previous-runs + strategy: + matrix: + job: + - os: ubuntu-latest + platform: linux + target: x86_64-unknown-linux-gnu + - os: ubuntu-latest + platform: linux + target: aarch64-unknown-linux-gnu + - os: macos-latest + platform: darwin + target: x86_64-apple-darwin + - os: macos-latest + platform: darwin + target: aarch64-apple-darwin + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: ${{ matrix.job.target }} + override: true + + - uses: Swatinem/rust-cache@v1 + with: + cache-on-failure: true + key: "${{ matrix.job.target }}" + + - name: Use Cross + uses: baptiste0928/cargo-install@v1 + with: + crate: cross + cache-key: "${{ matrix.job.target }}" + + - name: Build forc-wallet + run: | + cross build --profile=release --target ${{ matrix.job.target }} -p forc-wallet + - name: Strip release binary x86_64-linux-gnu + if: matrix.job.target == 'x86_64-unknown-linux-gnu' + run: strip "target/${{ matrix.job.target }}/release/forc-wallet" + + - name: Strip release binary aarch64-linux-gnu + if: matrix.job.target == 'aarch64-unknown-linux-gnu' + run: | + docker run --rm -v \ + "$PWD/target:/target:Z" \ + ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main \ + aarch64-linux-gnu-strip \ + /target/aarch64-unknown-linux-gnu/release/forc-wallet + - name: Strip release binary mac + if: matrix.job.os == 'macos-latest' + run: strip -x "target/${{ matrix.job.target }}/release/forc-wallet" + + - name: Prep assets + id: prep_assets + env: + PLATFORM_NAME: ${{ matrix.job.platform }} + TARGET: ${{ matrix.job.target }} + run: | + # Get tag name + # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 + FORC_WALLET_VERSION="${GITHUB_REF#refs/tags/}" + # trim v from tag prefix + FORC_WALLET_VERSION="${FORC_WALLET_VERSION#v}" + echo "version is: $FORC_WALLET_VERSION" + # setup artifact filename + ARTIFACT="forc-wallet-$FORC_WALLET_VERSION-${{ env.TARGET }}" + ZIP_FILE_NAME="$ARTIFACT.tar.gz" + echo "ZIP_FILE_NAME=$ZIP_FILE_NAME" >> $GITHUB_ENV + # create zip file + mkdir -pv "$ARTIFACT" + cp "target/${{ matrix.job.target }}/release/forc-wallet" "$ARTIFACT" + tar -czvf $ZIP_FILE_NAME "$ARTIFACT" + - name: Upload release archive + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./${{ env.ZIP_FILE_NAME }} + asset_name: ${{ env.ZIP_FILE_NAME }} + asset_content_type: application/gzipa