name: Build Release

on:
  push:
    tags:
      - "*.*.*"

jobs:
  build:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v6
      - name: Get the version
        run: echo version=$(cargo pkgid | cut -d "#" -f2) >> $GITHUB_ENV
      - name: Build
        run: cargo build --verbose --release
      - name: Run tests
        run: cargo test --verbose --release
      - name: Compress
        run: tar -czvf caffeinate2-${{ env.version }}.tar.gz target/release/caffeinate2
      - name: Create a release
        uses: softprops/action-gh-release@v2
        with:
          name: ${{ env.version }}
          files: caffeinate2-${{ env.version }}.tar.gz
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
