name: "Copilot Setup Steps"

# These steps run in Copilot's ephemeral environment BEFORE the agent's
# firewall is enabled, so they have unrestricted network access (including
# dl.google.com / maven.google.com, which the firewall otherwise blocks).
# Warming the Gradle caches here lets the agent build the project afterwards
# even though the Google Maven repository is not reachable during the session.
#
# Note: jitpack.io (used for the MPAndroidChart dependency) is now on the
# firewall allowlist, so it stays reachable during the agent session. The
# Google Maven repository remains blocked, so the cache warming below is still
# required.
#
# Automatically run the setup steps when they are changed to allow for easy
# validation, and allow manual testing through the repository's "Actions" tab.
on:
  workflow_dispatch:
  push:
    paths:
      - .github/workflows/copilot-setup-steps.yml
  pull_request:
    paths:
      - .github/workflows/copilot-setup-steps.yml

jobs:
  # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
  copilot-setup-steps:
    runs-on: ubuntu-latest

    # Set the permissions to the lowest permissions possible needed for your steps.
    # Copilot will be given its own token for its operations.
    permissions:
      # Needed to clone the repository to resolve and download dependencies.
      contents: read

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: 'temurin'

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4

      # Resolve and cache the dependencies the agent needs to build and test the
      # project. This downloads artifacts from the Google Maven repository
      # (dl.google.com) while it is still reachable, populating ~/.gradle so the
      # subsequent agent build can run without hitting the blocked host.
      - name: Warm Gradle dependency cache
        run: |
          ./gradlew --no-daemon \
            :app:assembleDevDebug \
            :app:compileDevDebugUnitTestSources \
            :shared:assemble
