name: Release

on:
  release:
    types: [created]

env:
  CARGO_TERM_COLOR: always

jobs:
  release:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            artifact_name: atlas_77
            asset_name: atlas_77-linux-amd64
          - os: windows-latest
            artifact_name: atlas_77.exe
            asset_name: atlas_77-windows-amd64.exe

    name: release ${{ matrix.os }}
    runs-on: '${{ matrix.os }}'
    environment: production

    env:
      CARGO_INCREMENTAL: 0

    steps:
      - uses: actions/checkout@v4

      - name: Build Server
        run: cargo build --release
      
      - name: Upload server binary to release
        uses: svenstaro/upload-release-action@v2
        with:
          file: ./target/release/${{ matrix.artifact_name }}
          asset_name: ${{ matrix.asset_name }}
          tag: ${{ github.ref }}

      - uses: chrnorm/deployment-action@v2
        name: Create GitHub deployment
        id: deployment
        with:
          token: "${{ github.token }}"
          environment-url: https://github.com/atlas77-lang/Atlas77
          environment: production

      - name: Update deployment status (success)
        if: success()
        uses: chrnorm/deployment-status@v2
        with:
          token: "${{ github.token }}"
          environment-url: ${{ steps.deployment.outputs.environment_url }}
          deployment-id: ${{ steps.deployment.outputs.deployment_id }}
          state: "success"

      - name: Update deployment status (failure)
        if: failure()
        uses: chrnorm/deployment-status@v2
        with:
          token: "${{ github.token }}"
          environment-url: ${{ steps.deployment.outputs.environment_url }}
          deployment-id: ${{ steps.deployment.outputs.deployment_id }}
          state: "failure"