Release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: Version bump to release | |
| type: choice | |
| required: true | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| concurrency: | |
| group: release-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| publish-rust: | |
| name: Release Rust Crate | |
| if: ${{ github.ref == 'refs/heads/main' }} | |
| runs-on: ubuntu-latest | |
| environment: Production | |
| env: | |
| CRATE_NAME: tinyflows | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: . | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run clippy | |
| run: cargo clippy --all-targets -- -D warnings | |
| - name: Run tests | |
| run: cargo test | |
| - name: Compute next version | |
| id: version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| current_version="$(cargo metadata --format-version 1 --no-deps | jq -r --arg crate "$CRATE_NAME" '.packages[] | select(.name == $crate) | .version')" | |
| if [[ -z "$current_version" ]]; then | |
| echo "Could not resolve current version for crate $CRATE_NAME" >&2 | |
| exit 1 | |
| fi | |
| IFS=. read -r major minor patch <<< "$current_version" | |
| case "${{ inputs.bump }}" in | |
| major) | |
| major=$((major + 1)) | |
| minor=0 | |
| patch=0 | |
| ;; | |
| minor) | |
| minor=$((minor + 1)) | |
| patch=0 | |
| ;; | |
| patch) | |
| patch=$((patch + 1)) | |
| ;; | |
| *) | |
| echo "Unsupported bump: ${{ inputs.bump }}" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| next_version="${major}.${minor}.${patch}" | |
| tag="v${next_version}" | |
| git fetch --tags origin | |
| if git rev-parse --verify --quiet "refs/tags/${tag}"; then | |
| echo "Tag ${tag} already exists" >&2 | |
| exit 1 | |
| fi | |
| { | |
| echo "current_version=${current_version}" | |
| echo "next_version=${next_version}" | |
| echo "tag=${tag}" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Update crate version | |
| env: | |
| NEXT_VERSION: ${{ steps.version.outputs.next_version }} | |
| run: | | |
| perl -0pi -e 's/(\[package\][\s\S]*?\nversion = ")[^"]+(")/$1$ENV{NEXT_VERSION}$2/' Cargo.toml | |
| cargo update -p "$CRATE_NAME" --precise "$NEXT_VERSION" | |
| - name: Commit version bump and tag | |
| env: | |
| NEXT_VERSION: ${{ steps.version.outputs.next_version }} | |
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add Cargo.toml Cargo.lock | |
| git commit -m "Release ${RELEASE_TAG}" | |
| git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}" | |
| - name: Package crate | |
| run: cargo package --locked | |
| - name: Push release commit and tag | |
| env: | |
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | |
| run: | | |
| git push origin "HEAD:${GITHUB_REF_NAME}" | |
| git push origin "${RELEASE_TAG}" | |
| - name: Publish to crates.io | |
| run: cargo publish --locked | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |