name: "~ OSDC: Slow tests (reusable)"

# NOTE: AWS region is hardcoded to us-west-1 in all jobs below, matching
# _osdc-deploy.yml. This reusable is currently called only for the
# meta-staging-aws-uw1 cluster (which lives in us-west-1). Re-using it for a
# cluster in a different region requires either parameterizing the
# region from `just region "${{ inputs.cluster }}"` or adding an
# aws_region input. Do not call this reusable for non-us-west-1
# clusters without first making that change.

on:
  workflow_call:
    inputs:
      cluster:
        description: "Cluster id from clusters.yaml (e.g. meta-staging-aws-uw1, meta-prod-aws-ue2)"
        required: true
        type: string
      environment:
        description: "GitHub environment for deployment gating (empty = no gate)"
        required: false
        type: string
        default: ""

permissions:
  id-token: write
  contents: read

jobs:
  load-test:
    name: Load tests
    runs-on: ubuntu-latest
    environment: ${{ inputs.environment }}
    timeout-minutes: 120
    defaults:
      run:
        working-directory: osdc
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

      - name: Install just
        uses: extractions/setup-just@f8a3cce218d9f83db3a2ecd90e41ac3de6cdfd9b # v3.1.0

      - name: Install mise
        uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
        with:
          version: "2026.5.11"
          install: true
          working_directory: osdc

      - name: Install Python dependencies
        run: uv sync

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
        with:
          role-to-assume: arn:aws:iam::${{ secrets.META_AWS_ACC_ID }}:role/${{ secrets.META_AWS_DEPLOY_ROLE }}
          aws-region: us-west-1
          role-duration-seconds: 7200

      - name: Run load tests
        run: just load-test "${{ inputs.cluster }}"
        env:
          GH_TOKEN: ${{ secrets.CANARY_GITHUB_TOKEN }}

  compactor:
    name: Compactor e2e tests
    needs: load-test
    if: ${{ !cancelled() && !failure() }}
    runs-on: ubuntu-latest
    environment: ${{ inputs.environment }}
    timeout-minutes: 30
    defaults:
      run:
        working-directory: osdc
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

      - name: Install just
        uses: extractions/setup-just@f8a3cce218d9f83db3a2ecd90e41ac3de6cdfd9b # v3.1.0

      - name: Install mise
        uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
        with:
          version: "2026.5.11"
          install: true
          working_directory: osdc

      - name: Install Python dependencies
        run: uv sync

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
        with:
          role-to-assume: arn:aws:iam::${{ secrets.META_AWS_ACC_ID }}:role/${{ secrets.META_AWS_DEPLOY_ROLE }}
          aws-region: us-west-1
          role-duration-seconds: 7200

      - name: Run compactor e2e tests
        run: just test-compactor "${{ inputs.cluster }}"

  janitor:
    name: Janitor e2e tests
    needs: load-test
    if: ${{ !cancelled() && !failure() }}
    runs-on: ubuntu-latest
    environment: ${{ inputs.environment }}
    timeout-minutes: 30
    defaults:
      run:
        working-directory: osdc
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

      - name: Install just
        uses: extractions/setup-just@f8a3cce218d9f83db3a2ecd90e41ac3de6cdfd9b # v3.1.0

      - name: Install mise
        uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
        with:
          version: "2026.5.11"
          install: true
          working_directory: osdc

      - name: Install Python dependencies
        run: uv sync

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
        with:
          role-to-assume: arn:aws:iam::${{ secrets.META_AWS_ACC_ID }}:role/${{ secrets.META_AWS_DEPLOY_ROLE }}
          aws-region: us-west-1
          role-duration-seconds: 7200

      - name: Run janitor e2e tests
        run: just test-janitor "${{ inputs.cluster }}"
