name: Test
on:
  workflow_run:
    workflows: ["Build/Test"]
    types: [completed]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: 'Download code coverage'
        uses: actions/github-script@v7
        with:
          script: |
            let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
               owner: context.repo.owner,
               repo: context.repo.repo,
               run_id: context.payload.workflow_run.id,
            });
            let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
              return artifact.name == "oc-code-coverage"
            })[0];
            let download = await github.rest.actions.downloadArtifact({
               owner: context.repo.owner,
               repo: context.repo.repo,
               artifact_id: matchArtifact.id,
               archive_format: 'zip',
            });
            let fs = require('fs');
            fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/oc-code-coverage.zip`, Buffer.from(download.data));
      - name: 'Unzip code coverage'
        run: unzip oc-code-coverage.zip -d coverage
      - name: set env vars 
        run: | 
          echo "PR_NUM=$(cat coverage/pr_num.txt)" >> $GITHUB_ENV
          echo "BASE=$(cat coverage/base.txt)" >> $GITHUB_ENV
          echo "HEAD=$(cat coverage/head.txt)" >> $GITHUB_ENV
