name: Carry forward codecov reports
# This workflow carries forward coverage reports for commits in master
# The coverage reports are generated by .github/workflows/codecov_per_test_coverage.yml
# By carrying forward the reports and uploading the static analysis information
# We can use the commits in master as the BASE for Automated Test Selection
# see .github/workflows/codecov_ats.yml

on:
  push:
    branches: [master]

jobs:
  carryforward-reports-and-upload-static-analysis:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - name: Set up Python 3.10.10
        uses: actions/setup-python@v4
        with:
          python-version: '3.10.10'
      - name: Download Codecov CLI
        run: |
          pip install --extra-index-url https://pypi.org/simple --no-cache-dir pytest codecov-cli==0.4.0
      # Creates the commit and report objects in codecov
      # This carries forward previouly uploaded coverage reports to the new commit
      - name: Codecov startup
        run: |
          codecovcli create-commit
          codecovcli create-report
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      # Sends static analysis information to codecov
      # This is used as an input in Codecov Automated Test Selection.
      # It's necessary so we can use this commit as the BASE for comparison
      - name: Static Analysis
        run: |
          codecovcli static-analysis --token=${CODECOV_STATIC_TOKEN} \
          --folders-to-exclude .artifacts \
          --folders-to-exclude .github \
          --folders-to-exclude .venv \
          --folders-to-exclude static \
          --folders-to-exclude bin
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
          CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}