From 011cf58524baa3ec4e4ebebb0c39a0488d7b13ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Fri, 5 Jan 2024 11:37:34 +0100 Subject: [PATCH] Add release action (#7) * add release action * review suggestions --- .github/workflows/release.yml | 139 ++++++++++++++++++++++++++++++++++ scripts/package.sh | 21 +++++ 2 files changed, 160 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/package.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dc90d9a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,139 @@ +name: Release + +on: + workflow_dispatch: + +permissions: + contents: write + +jobs: + get-version: + name: Get version from Cargo.toml + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + + steps: + - uses: actions/checkout@v4 + + - name: Get version from Cargo.toml + id: lookupVersion + uses: mikefarah/yq@dd648994340a5d03225d97abf19c9bf1086c3f07 + with: + cmd: yq -oy '"v" + .package.version' 'Cargo.toml' + + - name: Print version + id: version + run: | + VERSION=${{ steps.lookupVersion.outputs.result }} + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + build-binaries: + name: Build ${{ matrix.target }} + needs: get-version + runs-on: ${{ matrix.os }} + + env: + # Cross-compiled targets will override this to `cross`. + CARGO: cargo + + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + # Use cross to link oldest GLIBC possible. + cross: true + + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + cross: true + + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + cross: true + + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + cross: true + + - target: x86_64-apple-darwin + os: macos-latest + + - target: aarch64-apple-darwin + os: macos-latest + + - target: x86_64-pc-windows-msvc + os: windows-latest + + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@439cf607258077187679211f12aa6f19af4a0af7 + with: + toolchain: stable + target: ${{ matrix.target }} + + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 + + - name: Install cross + if: matrix.cross + uses: taiki-e/install-action@cross + + - name: Enable cross-compilation + if: matrix.cross + shell: bash + run: | + echo "CARGO=cross" >> $GITHUB_ENV + + - name: Build + run: ${{ env.CARGO }} build --release --locked --target ${{ matrix.target }} + + - name: Package + shell: bash + run: | + set -euxo pipefail + PKG_FULL_NAME="universal-sierra-compiler-${{ needs.get-version.outputs.version }}-${{ matrix.target }}" + echo "PKG_FULL_NAME=$PKG_FULL_NAME" >> $GITHUB_ENV + + bash ./scripts/package.sh "${{ matrix.target }}" "$PKG_FULL_NAME" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: build-${{ matrix.target }} + path: ${{ env.PKG_FULL_NAME }}.* + + create-release: + name: Create release + runs-on: ubuntu-latest + needs: [build-binaries, get-version] + steps: + - uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts-dl + + - name: Unpack artifacts to staging directory + run: | + mkdir -p artifacts + mv artifacts-dl/build-*/universal-sierra-compiler-* artifacts/ + + - name: Create GitHub release + id: create-release + uses: taiki-e/create-gh-release-action@8df4de6534ceacdaed10a08f73418ca751f31793 + with: + token: ${{ secrets.GITHUB_TOKEN }} + changelog: CHANGELOG.md + allow-missing-changelog: true + title: $version + ref: refs/tags/${{ needs.get-version.outputs.version }} + + - name: Upload artifacts to the release + working-directory: artifacts + run: gh release upload "$TAG" * + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ steps.create-release.outputs.computed-prefix }}${{ steps.create-release.outputs.version }} diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100644 index 0000000..393d593 --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euxo pipefail + +TARGET="$1" +PKG_FULL_NAME="$2" + +rm -rf "$PKG_FULL_NAME" +mkdir -p "$PKG_FULL_NAME/bin" + +bin_ext="" +[[ "$TARGET" == *-windows-* ]] && bin_ext=".exe" + +cp "./target/${TARGET}/release/universal-sierra-compiler${bin_ext}" "$PKG_FULL_NAME/bin/" + +cp -r README.md "$PKG_FULL_NAME/" + +if [[ "$TARGET" == *-windows-* ]]; then + 7z a "${PKG_FULL_NAME}.zip" "$PKG_FULL_NAME" +else + tar czvf "${PKG_FULL_NAME}.tar.gz" "$PKG_FULL_NAME" +fi