weather_man 0.2.3

A feature-rich Rust-based CLI for weather forecasting with cyberpunk-themed animations
Documentation
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  packages: write

jobs:
  build:
    name: Build and release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          override: true
          components: rustfmt, clippy

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

      - name: Check formatting
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

      - name: Run clippy
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings

      - name: Run tests
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all-features

      - name: Install cliff
        uses: actions-rs/cargo@v1
        with:
          command: install
          args: git-cliff

      - name: Update version and generate changelog
        run: |
          # Extract version from tag (remove 'v' prefix)
          VERSION=${GITHUB_REF_NAME#v}
          echo "Updating version to: $VERSION"

          # Update Cargo.toml version
          sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml

          # Update full changelog with git-cliff
          git-cliff --config cliff.toml --latest --output CHANGELOG.md

          # Generate release notes with git-cliff
          LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")

          # Generate release changelog using git-cliff
          if [ -n "$LAST_TAG" ]; then
            # Generate changelog between tags
            git-cliff --config cliff.toml ${LAST_TAG}..${{ github.ref_name }} --strip header > CLIFF_CHANGES.md
          else
            # Generate changelog for first release
            git-cliff --config cliff.toml --tag ${{ github.ref_name }} --strip header > CLIFF_CHANGES.md
          fi

          # Create the release note template
          echo "# Weather Man ${VERSION}" > RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "## 🚀 What's New" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md

          if [ -n "$LAST_TAG" ]; then
            echo "### 📝 Changes since ${LAST_TAG}:" >> RELEASE_CHANGELOG.md
            echo "" >> RELEASE_CHANGELOG.md
          else
            echo "### 🎉 Initial Release" >> RELEASE_CHANGELOG.md
            echo "" >> RELEASE_CHANGELOG.md
          fi

          # Add the git-cliff generated changes to the release notes
          cat CLIFF_CHANGES.md >> RELEASE_CHANGELOG.md

          # Add installation and quick start info
          echo "" >> RELEASE_CHANGELOG.md
          echo "## 📦 Installation" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "\`\`\`bash" >> RELEASE_CHANGELOG.md
          echo "cargo install weather_man" >> RELEASE_CHANGELOG.md
          echo "\`\`\`" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "## 🚀 Quick Start" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "\`\`\`bash" >> RELEASE_CHANGELOG.md
          echo "# Get current weather" >> RELEASE_CHANGELOG.md
          echo "weather_man" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "# Get forecast for a specific location" >> RELEASE_CHANGELOG.md
          echo "weather_man -m forecast -l \"New York\"" >> RELEASE_CHANGELOG.md
          echo "\`\`\`" >> RELEASE_CHANGELOG.md

          # Show the generated release notes
          echo "Generated release notes:"
          cat RELEASE_CHANGELOG.md

      - name: Build release
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release

      - name: Package binary (Linux)
        run: |
          tar -C target/release -czvf weather_man-${{ github.ref_name }}-linux-x86_64.tar.gz weather_man

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          body_path: RELEASE_CHANGELOG.md
          files: |
            weather_man-${{ github.ref_name }}-linux-x86_64.tar.gz
            LICENSE
            README.md
            CHANGELOG.md
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Publish to crates.io
        uses: actions-rs/cargo@v1
        with:
          command: publish
          args: --token ${{ secrets.CRATES_IO_TOKEN }} --allow-dirty