a3s-tui 0.1.14

TEA (The Elm Architecture) framework for terminal user interfaces
Documentation
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      release_tag:
        description: "Existing semantic-version tag to publish or finalize"
        required: true
        default: "v0.1.8"
        type: string

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always
  RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}

jobs:
  ci:
    name: CI
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ env.RELEASE_TAG }}

      - name: Validate release tag and package version
        shell: bash
        run: |
          set -euo pipefail
          if ! [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
            echo "release tag must be semantic, got: $RELEASE_TAG" >&2
            exit 1
          fi
          VERSION="${RELEASE_TAG#v}"
          PACKAGE_VERSION="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["packages"][0]["version"])')"
          if [ "$PACKAGE_VERSION" != "$VERSION" ]; then
            echo "Tag version ($VERSION) does not match Cargo.toml version ($PACKAGE_VERSION)" >&2
            exit 1
          fi

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@v2

      - name: Generate lockfile
        run: cargo generate-lockfile

      - name: Format check
        run: cargo fmt --all -- --check

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

      - name: Test
        run: cargo test --all-targets --all-features

      - name: Test minimal features
        run: cargo test --lib --no-default-features

      - name: Verify package
        run: cargo package --locked

  publish:
    name: Publish to crates.io
    needs: ci
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ env.RELEASE_TAG }}

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

      - name: Generate lockfile
        run: cargo generate-lockfile

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
        shell: bash
        run: |
          set -euo pipefail
          VERSION="${RELEASE_TAG#v}"
          if curl --retry 5 --retry-all-errors --retry-delay 3 -fsSL \
            -A "a3s-tui-release-check/1.0" \
            "https://crates.io/api/v1/crates/a3s-tui/${VERSION}" >/dev/null 2>&1; then
            echo "a3s-tui ${VERSION} is already published; skipping."
            exit 0
          fi
          cargo publish --locked

  github-release:
    name: GitHub Release
    needs: publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ env.RELEASE_TAG }}

      - name: Generate release notes
        shell: bash
        run: |
          set -euo pipefail
          PREVIOUS_TAG="$(git tag --sort=-v:refname | grep '^v' | head -2 | tail -1 || true)"
          if [ -z "$PREVIOUS_TAG" ]; then
            echo "Initial release" > /tmp/release-notes.md
          else
            git log "${PREVIOUS_TAG}..HEAD" --oneline --no-merges --pretty=format:'- %s' | head -50 > /tmp/release-notes.md
          fi

      - name: Create GitHub release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        shell: bash
        run: |
          set -euo pipefail
          if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
            gh release edit "$RELEASE_TAG" \
              --title "$RELEASE_TAG" \
              --notes-file /tmp/release-notes.md \
              --draft=false \
              --prerelease=false \
              --verify-tag
          else
            gh release create "$RELEASE_TAG" \
              --title "$RELEASE_TAG" \
              --notes-file /tmp/release-notes.md \
              --verify-tag
          fi