rust-lib-reference-genome 0.3.0

Reference genome library for Rust
Documentation
# This workflow reads the version from Cargo.toml. If a GitHub Release for that
# version does not exist, it creates the tag, a notes-only GitHub Release, and
# publishes the crate to crates.io.
# Steps:
# - Get the version from the Cargo.toml file
# - Check if the release already exists
# - If not:
#   - Call the create-lib-release workflow (tests, tag, changelog GitHub Release)
#   - Publish to crates.io
# Errors:
# - If no version is found in the Cargo.toml file, the workflow will fail
# - If CHANGELOG.md has no section for the version, create-lib-release will fail
# - If the create-lib-release workflow fails, the workflow will fail
# Maintenance:
# - Update the Rust version here and in create-lib-release / crates.io publish to match

name: Check for new version

on:
  push:
    branches:
      - main

jobs:
  check-new-tag:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      actions: read

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Get version from Cargo.toml
      id: get_version
      run: |
        # Try to get version from Cargo.toml first
        if [ -f "Cargo.toml" ]; then
          VERSION=$(grep '^version =' Cargo.toml | cut -d'"' -f2)
        else
          echo "No Cargo.toml found to determine version"
          exit 1
        fi

        # make sure we have a version
        if [ -z "$VERSION" ]; then
          echo "No version found in Cargo.toml"
          exit 1
        fi
        
        # We have a version, the tag has a 'v' prefix
        echo "version=$VERSION" >> $GITHUB_OUTPUT
        echo "tag=v$VERSION" >> $GITHUB_OUTPUT
        echo "Detected version: $VERSION"
    
    - name: Check if the release already exists
      uses: insightsengineering/release-existence-action@v1
      id: check_release
      with:
        release-tag: '${{ steps.get_version.outputs.tag }}'

    outputs:
      release_exists: ${{ steps.check_release.outputs.release-exists }}
      version: ${{ steps.get_version.outputs.version }}
      tag: ${{ steps.get_version.outputs.tag }}

  call-create-lib-release:
    name: Call create-lib-release workflow
    needs: check-new-tag
    if: needs.check-new-tag.outputs.release_exists == 'false'
    uses: holtjma/shared_github_workflows/.github/workflows/create-lib-release.yml@v0.7.0
    permissions:
      contents: write
    with:
      release_name: 'rust-lib-reference-genome'
      tag: ${{ needs.check-new-tag.outputs.tag }}
      rust_version: 1.98.0
      test_docs: true

  publish-to-crates-io:
    name: Publish to Crates.io
    needs: [check-new-tag, call-create-lib-release]
    if: needs.check-new-tag.outputs.release_exists == 'false'
    runs-on: ubuntu-latest
    container:
      image: rust:1.98.0
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Publish to Crates.io
      run: cargo publish
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}