timer-lib 0.4.0

A feature-rich Rust library for creating and managing timers.
Documentation
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Check out repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install stable Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Cargo artifacts
        uses: Swatinem/rust-cache@v2

      - name: Determine release version
        id: version
        shell: bash
        run: |
          if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
            version="${GITHUB_REF_NAME#v}"
          else
            version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="timer-lib") | .version')"
          fi
          echo "version=${version}" >> "$GITHUB_OUTPUT"

      - name: Validate tag matches crate version
        if: github.ref_type == 'tag'
        shell: bash
        run: |
          crate_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="timer-lib") | .version')"
          tag_version="${{ steps.version.outputs.version }}"
          if [[ "${crate_version}" != "${tag_version}" ]]; then
            echo "Tag version ${tag_version} does not match crate version ${crate_version}" >&2
            exit 1
          fi

      - name: Check formatting
        run: cargo fmt --check

      - name: Run Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Run tests
        run: cargo test

      - name: Check examples
        run: cargo check --examples

      - name: Verify package
        run: cargo package --allow-dirty

      - name: Publish to crates.io
        if: github.ref_type == 'tag'
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish

      - name: Create GitHub release
        if: github.ref_type == 'tag'
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref_name }}
          generate_release_notes: true