Skip to content

Commit

Permalink
Refactor workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Nov 19, 2024
1 parent 479126e commit 3544343
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -167,11 +150,34 @@ 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
target/${{ matrix.target }}/release/${{ env.ASSET }}.sha512
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

0 comments on commit 3544343

Please sign in to comment.