name: Upload binaries

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

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

  upload-assets:
    strategy:
      matrix:

        # See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
        include:
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-apple-darwin
            os: macos-13

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

    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4

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

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

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