From 1ed00e53a15eb571ae94f91b5a318b0ebdb1021c Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Tue, 26 Mar 2024 20:35:27 +0100 Subject: [PATCH] Add release workflow and justfile --- .github/workflows/release.yaml | 122 +++++++++++++++++++++++++++++++++ .justfile | 67 ++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .justfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..fa87896 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,122 @@ +name: Release + +on: + workflow_dispatch: + +permissions: + contents: write + +defaults: + run: + shell: bash + +jobs: + init: + name: Init + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.value }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get version from manifest + uses: SebRollen/toml-action@9062fbef52816d61278d24ce53c8070440e1e8dd + id: get_version + with: + file: Cargo.toml + field: package.version + + build: + needs: ["init"] + strategy: + fail-fast: false + matrix: + include: + - name: Windows x86_64 + runner-os: windows-latest + artifact-name: rokit-${{ needs.init.outputs.version }}-windows-x86_64 + cargo-target: x86_64-pc-windows-msvc + + - name: Linux x86_64 + runner-os: ubuntu-latest + artifact-name: rokit-${{ needs.init.outputs.version }}-linux-x86_64 + cargo-target: x86_64-unknown-linux-gnu + + - name: Linux aarch64 + runner-os: ubuntu-latest + artifact-name: rokit-${{ needs.init.outputs.version }}-linux-aarch64 + cargo-target: aarch64-unknown-linux-gnu + + - name: macOS x86_64 + runner-os: macos-13 + artifact-name: rokit-${{ needs.init.outputs.version }}-macos-x86_64 + cargo-target: x86_64-apple-darwin + + - name: macOS aarch64 + runner-os: macos-14 + artifact-name: rokit-${{ needs.init.outputs.version }}-macos-aarch64 + cargo-target: aarch64-apple-darwin + + name: Build - ${{ matrix.name }} + runs-on: ${{ matrix.runner-os }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.cargo-target }} + + - name: Install Just + uses: extractions/setup-just@v1 + + - name: Install build tooling (aarch64-unknown-linux-gnu) + if: matrix.cargo-target == 'aarch64-unknown-linux-gnu' + run: | + sudo apt-get update -y + sudo apt-get install -y musl-tools clang llvm + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: Build binary + run: just build --locked --release --target ${{ matrix.cargo-target }} + + - name: Create release archive + run: just zip-release ${{ matrix.cargo-target }} + + - name: Upload release artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact-name }} + path: release.zip + + release: + name: Release + runs-on: ubuntu-latest + needs: ["init", "build"] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Just + uses: extractions/setup-just@v1 + + - name: Download releases + uses: actions/download-artifact@v3 + with: + path: ./releases + + - name: Unpack releases + run: just unpack-releases "./releases" + + - name: Create release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + name: ${{ needs.init.outputs.version }} + tag_name: v${{ needs.init.outputs.version }} + fail_on_unmatched_files: true + files: ./releases/*.zip + draft: true diff --git a/.justfile b/.justfile new file mode 100644 index 0000000..f2765d0 --- /dev/null +++ b/.justfile @@ -0,0 +1,67 @@ +EXT := if os() == "windows" { ".exe" } else { "" } +CWD := invocation_directory() +BIN_NAME := "rokit" + +# Builds the Rokit CLI binary +[no-exit-message] +build *ARGS: + #!/usr/bin/env bash + set -euo pipefail + cargo build --bin {{BIN_NAME}} {{ARGS}} + +# Used in GitHub workflow to zip up the built binary +[no-exit-message] +zip-release TARGET_TRIPLE: + #!/usr/bin/env bash + set -euo pipefail + rm -rf staging + rm -rf release.zip + mkdir -p staging + cp "target/{{TARGET_TRIPLE}}/release/{{BIN_NAME}}{{EXT}}" staging/ + cd staging + if [ "{{os_family()}}" = "windows" ]; then + 7z a ../release.zip * + else + chmod +x {{BIN_NAME}} + zip ../release.zip * + fi + cd "{{CWD}}" + rm -rf staging + +# Used in GitHub workflow to move per-matrix release zips +[no-exit-message] +unpack-releases RELEASES_DIR: + #!/usr/bin/env bash + set -euo pipefail + # + if [ ! -d "{{RELEASES_DIR}}" ]; then + echo "Releases directory is missing" + exit 1 + fi + # + cd "{{RELEASES_DIR}}" + echo "" + echo "Releases dir:" + ls -lhrt + echo "" + echo "Searching for zipped releases..." + # + for DIR in * ; do + if [ -d "$DIR" ]; then + cd "$DIR" + for FILE in * ; do + if [ ! -d "$FILE" ]; then + if [ "$FILE" = "release.zip" ]; then + echo "Found zipped release '$DIR'" + mv "$FILE" "../$DIR.zip" + rm -rf "../$DIR/" + fi + fi + done + cd .. + fi + done + # + echo "" + echo "Releases dir:" + ls -lhrt