name: Upload binaries

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6
      - uses: taiki-e/create-gh-release-action@v1
        with:
          changelog: CHANGELOG.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    strategy:
      matrix:
        include:
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-apple-darwin
            os: macos-latest

    runs-on: ${{ matrix.os }}

    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v6

      - name: Compile the Swift script
        run: swiftc get_live_text.swift

      - name: Create the zip archive
        run: zip "get_live_text.${{ matrix.target }}.zip" get_live_text README.md LICENSE

      - name: Push the zip file to the GitHub release
        run: gh release upload "$GITHUB_REF_NAME" "get_live_text.${{ matrix.target }}.zip" --clobber
        env:
          GH_TOKEN: ${{ github.token }}
