name: Sims Nightly (Long)
# Release Sims workflow runs long-lived (multi-seed & large block size) simulations
# This workflow only runs mightly at 8am UTC and on releases
on:
  schedule:
    - cron: "0 8 * * *"
  release:
    types: [published]

permissions:
  contents: read

concurrency:
  group: ci-${{ github.ref }}-sims-nightly-long
  cancel-in-progress: true

jobs:
  test-sim-multi-seed-long:
    runs-on: depot-ubuntu-22.04-4
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: "1.23"
          check-latest: true
      - name: test-sim-multi-seed-long
        env:
          GOMEMLIMIT: 14GiB # reserve 2 GiB as buffer for GC to avoid OOM
        run: |
          make test-sim-multi-seed-long

  test-sim-import-export:
    runs-on: depot-ubuntu-22.04-4
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: "1.23"
          check-latest: true
      - name: test-sim-import-export
        env:
          GOMEMLIMIT: 14GiB # reserve 2 GiB as buffer for GC to avoid OOM
        run: |
          make test-sim-import-export

  sims-notify-success:
    needs: [test-sim-multi-seed-long, test-sim-import-export]
    runs-on: depot-ubuntu-22.04-4
    if: ${{ success() }}
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
      - name: Get previous workflow status
        uses: ./.github/actions/last-workflow-status
        id: last_status
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

      - name: Notify Slack on success
        if: ${{ steps.last_status.outputs.last_status == 'failure' }}
        uses: rtCamp/action-slack-notify@v2.3.3
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_CHANNEL: sdk-sims
          SLACK_USERNAME: Sim Tests
          SLACK_ICON_EMOJI: ":white_check_mark:"
          SLACK_COLOR: good
          SLACK_MESSAGE: Sims Nightly (Long) are passing
          SLACK_FOOTER: ""

  sims-notify-failure:
    permissions:
      contents: none
    needs: [test-sim-multi-seed-long]
    runs-on: depot-ubuntu-22.04-4
    if: ${{ failure() }}
    steps:
      - name: Notify Slack on failure
        uses: rtCamp/action-slack-notify@v2.3.3
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_CHANNEL: sdk-sims
          SLACK_USERNAME: Sim Tests
          SLACK_ICON_EMOJI: ":skull:"
          SLACK_COLOR: danger
          SLACK_MESSAGE: Sims Nightly (Long) are failing
          SLACK_FOOTER: ""
