tinty 0.22.0

Change the theme of your terminal, text editor and anything else with one command!
name: Setup Environment
on:
  workflow_call:
    outputs:
      git_tag_name:
        description: "Git release tag name"
        value: ${{ jobs.setup-environment.outputs.git_tag_name }}
      cargo_cache_key:
        description: "Cargo cache key for the build"
        value: ${{ jobs.setup-environment.outputs.cargo_cache_key }}

jobs:
  setup-environment:
    runs-on: ubuntu-latest
    outputs:
      git_tag_name: ${{ steps.git_tag_name.outputs.value }}
      cargo_cache_key: ${{ steps.cargo_cache_key.outputs.value }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 1
          ref: ${{ inputs.git_tag_name || github.ref }}
      - uses: actions-rust-lang/setup-rust-toolchain@v1

      - name: Set cargo cache key
        id: cargo_cache_key
        run: |
          CARGO_CACHE_KEY="${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
          echo "value=$CARGO_CACHE_KEY" >> $GITHUB_OUTPUT

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
            ~/.cargo/bin
          key: ${{ steps.cargo_cache_key.outputs.value }}
          id: cache-cargo-release

      - name: Set git_tag_name from latest Cargo.toml version
        id: git_tag_name
        run: |
          VERSION=$(cargo read-manifest | jq -r ".version")
          echo "value=v$VERSION" >> $GITHUB_OUTPUT

      - name: Ensure the release tag does not exist
        run: |
          version="${{ steps.git_tag_name.outputs.value }}"
          if git rev-parse "$version" >/dev/null 2>&1; then
            echo "This git tag already exists: $version"
            exit 1
          fi

      - name: Ensure crate version doesn't already exist
        run: |
          crate_name="tinty"
          version="${{ steps.git_tag_name.outputs.value }}"
          response=$(curl -s "https://crates.io/api/v1/crates/$crate_name")
          if echo "$response" | grep -q "\"num\":\"$version\""; then
            echo "Version $version of $crate_name already exists."
            exit 1
          fi

      - name: Ensure changelog entry for version exists
        run: |
          version=$(cargo read-manifest | jq -r ".version")
          if ! grep -q "\[$version\]" ./CHANGELOG.md; then
            echo "Changelog doesn't contain an entry for this version: $version"
            exit 1
          fi