From ea59a72cd0f82989839b3c8ea6a95c761f2be9e8 Mon Sep 17 00:00:00 2001 From: "Jens K." <47693+sectore@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:21:38 +0100 Subject: [PATCH] Prepare release workflow (#40) --- .github/workflows/ci.yml | 3 +- .github/workflows/release.yml | 104 ++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc9894c..4190f17 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,8 @@ name: lint, format, test, build on: push: branches: [ main ] - pull_request: + # ignore for now + # pull_request: jobs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b35082c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,104 @@ +name: release + +on: + push: + branches: + - "release/**" + tags: + - "v*" + +jobs: + get-version: + name: Get version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v4 + - name: Get version from Cargo.toml + id: version + run: | + VERSION=$(grep '^version =' Cargo.toml | cut -d '"' -f2) + echo "version=$VERSION" >> $GITHUB_OUTPUT + + build: + name: Build ${{ matrix.os_target }} on ${{ matrix.os }} + needs: get-version + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + os_target: linux + binary_name: timr-tui + arch: x86_64 # `x86_64` by default + - os: ubuntu-latest + os_target: windows + binary_name: timr-tui.exe + arch: x86_64 # based on target 'x86_64-pc-windows-gnu' defined by `CARGO_BUILD_TARGET` in flake.nix + - os: macOS-latest + os_target: macos + binary_name: timr-tui + arch: x86_64 # `x86_64` by default + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Build (windows) + if: matrix.os_target == 'windows' + run: nix build .#windows + + - name: Build (linux/macos) + if: matrix.os_target != 'windows' + run: nix build + + - name: Copy artifact + run: | + mkdir artifacts + cp result/bin/${{ matrix.binary_name }} artifacts/ + + - name: Install zip + if: matrix.os_target == 'windows' + run: sudo apt-get install -y zip + + - name: Archive (windows) + if: matrix.os_target == 'windows' + run: | + cd artifacts + zip ${{ matrix.binary_name }}-${{ needs.get-version.outputs.version }}-${{ matrix.os_target }}_${{ matrix.arch }}.zip ${{ matrix.binary_name }} + + - name: Archive (linux/macos) + if: matrix.os_target != 'windows' + run: | + cd artifacts + tar -czf ${{ matrix.binary_name }}-${{ needs.get-version.outputs.version }}-${{ matrix.os_target }}_${{ matrix.arch }}.tar.gz ${{ matrix.binary_name }} + + - name: Upload archive + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os_target }}-build + path: | + artifacts/*.tar.gz + artifacts/*.zip + overwrite: true + + create-release: + name: Create draft release + needs: [get-version, build] + runs-on: ubuntu-latest + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: true + + - name: Create draft release + uses: softprops/action-gh-release@v2 + with: + draft: true + tag_name: "v${{ needs.get-version.outputs.version }}" + name: "v${{ needs.get-version.outputs.version }}" + body: Draft release generated by CI. + files: artifacts/**/*