name: release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  release:
    if: github.repository == 'AmmarAbouZor/tui-journal'
    name: build-release
    runs-on: ${{ matrix.os }}
    container: ${{ matrix.container }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            container: rust
            dependencies: "libssl-dev"
          - os: ubuntu-24.04-arm
            container: rust
            dependencies: "libssl-dev"
          - os: macos-latest
            arch: arm64
          - os: windows-latest

    steps:
      - uses: actions/checkout@v7

      - name: Validate tag
        shell: bash
        run: |
          [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]

      - name: Install Latest Rust
        run: |
          rustup update --no-self-update ${{ env.RUST_CHANNEL }}
          rustup default ${{ env.RUST_CHANNEL }}

      - name: Install Linux dependencies
        if: matrix.dependencies
        run: apt update && apt install -y ${{ matrix.dependencies }}

      - name: Build Release Mac ARM64
        if: matrix.os == 'macos-latest' && matrix.arch == 'arm64'
        run: make release-mac-arm64
      - name: Build Release Linux ARM64
        if: matrix.os == 'ubuntu-24.04-arm'
        run: make release-linux-arm64
      - name: Build Release Linux
        if: matrix.os == 'ubuntu-latest'
        run: make release-linux
      - name: Build Release Win
        if: matrix.os == 'windows-latest'
        run: make release-win

      - name: release
        if: success()
        uses: softprops/action-gh-release@v3
        with:
          generate_release_notes: true
          tag_name: ${{ github.ref_name }}
          files: |
            ./release/*.tar.gz
            ./release/*.zip

        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
