From 35443431b0efc01b46e96d37775d9fd67cab37b6 Mon Sep 17 00:00:00 2001 From: thomasschafer Date: Tue, 19 Nov 2024 10:08:42 +0000 Subject: [PATCH] Refactor workflows --- .github/workflows/release.yml | 68 +++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1ff793..5762120 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,20 +5,22 @@ on: branches: [ "main" ] paths: - 'Cargo.toml' - workflow_dispatch: # Allows manual triggering + workflow_dispatch: permissions: contents: write jobs: - release: - name: Release + prepare-release: + name: Prepare Release runs-on: ubuntu-latest + outputs: + version: ${{ steps.get-package-info.outputs.version }} + should_release: ${{ steps.check-version.outputs.exists == 'false' }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - name: Get package info from Cargo.toml id: get-package-info @@ -53,25 +55,12 @@ jobs: gh release create "v${version}" \ --title "v${version}" \ - --generate-notes - - - name: Install Rust toolchain - if: steps.check-version.outputs.exists == 'false' - uses: dtolnay/rust-toolchain@stable - - - name: Rust cache - if: steps.check-version.outputs.exists == 'false' - uses: Swatinem/rust-cache@v2 - - - name: Publish to crates.io - if: steps.check-version.outputs.exists == 'false' - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run: cargo publish - - name: Build and upload release binaries + --generate-notes \ + --draft # Make it draft until binaries are uploaded build-and-upload: + needs: prepare-release + if: needs.prepare-release.outputs.should_release == 'true' name: ${{ matrix.target }} runs-on: ${{ matrix.os }} strategy: @@ -99,13 +88,6 @@ jobs: with: fetch-depth: 0 - - name: Get latest tag - shell: bash - run: | - git fetch --tags - LATEST_TAG=$(git tag --sort=committerdate | tail -1) - echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV - - name: Install Rust uses: dtolnay/rust-toolchain@stable with: @@ -133,12 +115,13 @@ jobs: shell: bash run: | cd target/${{ matrix.target }}/release + VERSION="${{ needs.prepare-release.outputs.version }}" if [ "${{ runner.os }}" = "Windows" ]; then - ARCHIVE="${{ env.BINARY_NAME }}-${{ env.LATEST_TAG }}-${{ matrix.target }}.zip" + ARCHIVE="${{ env.BINARY_NAME }}-v${VERSION}-${{ matrix.target }}.zip" mv "${{ env.BINARY_NAME }}.exe" "${{ env.BINARY_NAME }}-${{ matrix.target }}.exe" 7z a "$ARCHIVE" "${{ env.BINARY_NAME }}-${{ matrix.target }}.exe" else - ARCHIVE="${{ env.BINARY_NAME }}-${{ env.LATEST_TAG }}-${{ matrix.target }}.tar.gz" + ARCHIVE="${{ env.BINARY_NAME }}-v${VERSION}-${{ matrix.target }}.tar.gz" mv "${{ env.BINARY_NAME }}" "${{ env.BINARY_NAME }}-${{ matrix.target }}" tar -czvf "$ARCHIVE" "${{ env.BINARY_NAME }}-${{ matrix.target }}" fi @@ -167,7 +150,7 @@ jobs: - name: Upload to release uses: softprops/action-gh-release@v1 with: - tag_name: ${{ env.LATEST_TAG }} + tag_name: v${{ needs.prepare-release.outputs.version }} files: | target/${{ matrix.target }}/release/${{ env.ASSET }} target/${{ matrix.target }}/release/${{ env.ASSET }}.sha256 @@ -175,3 +158,26 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + publish: + needs: [prepare-release, build-and-upload] + if: needs.prepare-release.outputs.should_release == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: cargo publish + + - name: Publish release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release edit "v${{ needs.prepare-release.outputs.version }}" --draft=false