name: Release

permissions:
  contents: read

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

env:
  RUST_BACKTRACE: 1
  CARGO_INCREMENTAL: 0
  CARGO_NET_GIT_FETCH_WITH_CLI: true
  CARGO_NET_RETRY: 10
  RUSTFLAGS: -D warnings
  RUSTUP_MAX_RETRIES: 10
  CARGO_TERM_COLOR: always

defaults:
  run:
    shell: bash

jobs:
  # create-release:
  #   runs-on: ubuntu-22.04
  #   timeout-minutes: 60
  #   permissions:
  #     contents: write
  #   steps:
  #     - uses: actions/checkout@v3
  #       with:
  #         persist-credentials: false
  #     - name: Install Rust
  #       run: |
  #         rustup update stable --no-self-update
  #         rustup target add wasm32-unknown-unknown
  #     - uses: taiki-e/create-gh-release-action@v1
  #       with:
  #         title: $version
  #         branch: main
  #         token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    name: ${{ matrix.target }}
    # needs:
    #   - create-release
    strategy:
      matrix:
        # When updating this list, remember to update the target list in tests too
        include:
          - target: aarch64-unknown-linux-gnu
          - target: x86_64-unknown-linux-gnu
          - target: aarch64-apple-darwin
            os: macos-11
          - target: x86_64-apple-darwin
            os: macos-11
          - target: universal-apple-darwin
            os: macos-11
          - target: x86_64-pc-windows-msvc
            os: windows-2019
    runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
    timeout-minutes: 60
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v3
        with:
          persist-credentials: false
      - name: Install Rust
        run: |
          rustup update stable --no-self-update
          rustup target add wasm32-unknown-unknown
      - uses: taiki-e/setup-cross-toolchain-action@v1
        if: (matrix.os == '' || startsWith(matrix.os, 'ubuntu'))
        with:
          target: ${{ matrix.target }}
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: node-template
          target: ${{ matrix.target }}
          tar: all
          zip: windows
          token: ${{ secrets.GITHUB_TOKEN }}