oxcache 0.3.2

A high-performance multi-level cache library for Rust with L1 (memory) and L2 (Redis) caching.
name: Release

on:
  push:
    tags:
      - 'v*.*.*'

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  verify:
    name: Verify Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

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

      - name: Verify build (full features)
        run: cargo build --release --features full --workspace

      - name: Verify tests pass
        run: cargo test --features full --workspace --no-fail-fast

      - name: Verify package
        run: cargo package --no-verify --features full

  github-release:
    name: GitHub Release
    needs: verify
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Get version from tag
        id: version
        run: |
          TAG_NAME="${GITHUB_REF#refs/tags/}"
          VERSION="${TAG_NAME#v}"
          echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "Tag: $TAG_NAME"
          echo "Version: $VERSION"

      - name: Generate changelog
        id: changelog
        run: |
          PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
          {
            echo "## What's Changed"
            echo ""
            if [ -n "$PREV_TAG" ]; then
              echo "Changes since $PREV_TAG:"
              git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)"
            else
              echo "Full changelog:"
              git log --pretty=format:"- %s (%h)"
            fi
            echo ""
            echo ""
            echo "## Assets"
            echo ""
            echo "- oxcache-${{ steps.version.outputs.version }}.crate (crates.io source package)"
          } > changelog.md
          cat changelog.md

      - name: Package crate
        run: cargo package --no-verify --features full

      - name: Rename crate package
        run: |
          cp target/package/oxcache-*.crate oxcache-${{ steps.version.outputs.version }}.crate

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ steps.version.outputs.tag_name }}
          name: Release ${{ steps.version.outputs.tag_name }}
          body_path: changelog.md
          files: |
            oxcache-${{ steps.version.outputs.version }}.crate
          draft: false
          prerelease: false
          generate_release_notes: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  # Conditional publish: only runs when CARGO_REGISTRY_TOKEN is configured.
  publish-crates:
    name: Publish to crates.io (conditional)
    needs: github-release
    runs-on: ubuntu-latest
    env:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
    if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Publish oxcache_macros
        run: cargo publish --token ${CARGO_REGISTRY_TOKEN} --manifest-path macros/Cargo.toml

      - name: Publish oxcache
        run: cargo publish --token ${CARGO_REGISTRY_TOKEN} --features full