name: Integration Tests

on:
  schedule:
    - cron: '30 19 * * MON-FRI'
  workflow_dispatch:

jobs:
  build:
    if: ${{ vars.INTEGRATION_TESTS_BUCKET != '' }}
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
      - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
        with:
          distribution: 'temurin'
          java-version: '21'
          cache: 'maven'
      - uses: aws-actions/configure-aws-credentials@5579c002bb4778aa43395ef1df492868a9a1c83f # v4.0.2
        name: Configure AWS credentials from Test account
        with:
          role-to-assume: ${{ vars.AWS_ROLE }}
          aws-region: ${{ vars.AWS_REGION }}
      - name: Fetch integration utils library
        run: |
          mkdir -p integration-tests/.libs
          mkdir -p integration-tests/src/main/resources
          wget -O integration-tests/.libs/software.amazon.awssdk-sso.jar https://repo1.maven.org/maven2/software/amazon/awssdk/sso/2.19.8/sso-2.19.8.jar
          aws s3 cp "s3://${{ vars.INTEGRATION_TESTS_BUCKET }}/config-latest.yml" integration-tests/src/main/resources/config.yml
      - name: Run and verify integration tests
        run: ./mvnw clean compile test-compile failsafe:integration-test failsafe:verify
