tod 0.11.2

An unofficial Todoist command-line client
# This runs an OS-specific test, then builds and releases binaries for macOS (ARM and Intel) and publishes them to GitHub.
# It is triggered by push with a version tag is present (generally from a release-please release)

name: macOS Build & Release
permissions:
  contents: write
  pull-requests: write

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

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0
  CARGO_PROFILE_TEST_DEBUG: 0
  CARGO_PROFILE_RELEASE_LTO: true
  CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1

jobs:
  build:
    name: Build, Release, and Publish for macOS (ARM & Intel)
    runs-on: macos-latest

    steps:
      - name: App token
        id: app-token
        uses: actions/create-github-app-token@v2
        with:
          app-id: ${{ vars.TODD_APP_ID }}
          private-key: ${{ secrets.TODD_PRIVATE_KEY }}
          owner: tod-org
          repositories: tod

      - name: Checkout repository
        uses: actions/checkout@v6

      - uses: taiki-e/install-action@nextest

      - name: Install Rust Toolchain
        run: rustup toolchain install

      - uses: Swatinem/rust-cache@v2
        with:
          cache-all-crates: true

      - name: Run tests using cargo-nextest
        run: cargo nextest run --all-features
        continue-on-error: false

      - name: Set VERSION and TAG from Cargo.toml
        id: cargo-get
        uses: nicolaiunrein/cargo-get@master
        with:
          subcommand: package.version

      - name: Set version output
        id: package-version
        run: |
          echo "VERSION=$(cargo get package.version)" >> $GITHUB_ENV
          echo "TAG=$(cargo get package.version --pretty)" >> $GITHUB_ENV

      - name: Add x86_64 target for cross-compilation
        run: rustup target add x86_64-apple-darwin

      - name: Build for macOS (ARM)
        run: cargo build --release --target aarch64-apple-darwin

      - name: Gzipping the ARM binary
        run: tar -czf target/release/tod-$VERSION-darwin-arm64.tar.gz -C target/aarch64-apple-darwin/release tod

      - name: Hash ARM release binary
        run: |
          HASH=$(shasum -a 256 target/release/tod-$VERSION-darwin-arm64.tar.gz | awk '{print $1}')
          echo "ARM HASH: $HASH"

      - name: Build for macOS (Intel)
        run: cargo build --release --target x86_64-apple-darwin

      - name: Gzipping the x86 binary
        run: tar -czf target/release/tod-$VERSION-darwin-amd64.tar.gz -C target/x86_64-apple-darwin/release tod

      - name: Hash Intel release binary
        run: |
          HASH=$(shasum -a 256 target/release/tod-$VERSION-darwin-amd64.tar.gz | awk '{print $1}')
          echo "Intel HASH: $HASH"

      - name: Upload darwin (macOS) binaries
        run: |
          gh release upload "$TAG" \
            target/release/tod-$VERSION-darwin-amd64.tar.gz \
            target/release/tod-$VERSION-darwin-arm64.tar.gz \
            --repo "$GITHUB_REPOSITORY" \
            --clobber
        env:
          GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
          VERSION: ${{ env.VERSION }}
          TAG: ${{ env.TAG }}