thales 0.4.1

A comprehensive Computer Algebra System (CAS) library for symbolic mathematics, equation solving, calculus, and linear algebra
Documentation
name: Release

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'

env:
  CARGO_TERM_COLOR: always

jobs:
  release:
    name: Create Release and Publish
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

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

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}

      - name: Verify version matches tag
        run: |
          CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
          TAG_VERSION=${GITHUB_REF#refs/tags/v}
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "Error: Cargo.toml version ($CARGO_VERSION) does not match tag version ($TAG_VERSION)"
            exit 1
          fi
          echo "Version verified: $CARGO_VERSION"

      - name: Build release
        run: cargo build --release --verbose

      - name: Run tests
        run: cargo test --release --verbose

      - name: Extract changelog for this version
        id: changelog
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          # Extract the section for this version from CHANGELOG.md
          CHANGELOG=$(awk -v ver="$VERSION" '
            /^## \[/ {
              if (found) exit
              if ($0 ~ "\\[" ver "\\]") found=1
            }
            found && !/^## \['"$VERSION"'\]/ { print }
          ' CHANGELOG.md)

          # If no changelog found, use a default message
          if [ -z "$CHANGELOG" ]; then
            CHANGELOG="Release v$VERSION"
          fi

          # Write to file for GitHub release body
          echo "$CHANGELOG" > release_notes.md

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          body_path: release_notes.md
          generate_release_notes: false
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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