github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/.github/workflows/code-cover-gen.yaml (about) 1 name: PR code coverage (generate) 2 3 on: 4 # This workflow does not have access to secrets because it runs on top of 5 # potentially unsafe changes. 6 pull_request: 7 types: [ opened, reopened, synchronize ] 8 branches: [ master ] 9 10 jobs: 11 # The results of this job are uploaded as artifacts. A separate job will 12 # download the artifacts and upload them to a GCS bucket. 13 code-cover-gen: 14 runs-on: ubuntu-latest 15 env: 16 PR: ${{ github.event.pull_request.number }} 17 HEAD_SHA: ${{ github.event.pull_request.head.sha }} 18 GH_TOKEN: ${{ github.token }} 19 steps: 20 - uses: actions/checkout@v3 21 with: 22 # By default, checkout merges the PR into the current master. 23 # Instead, we want to check out the PR as-is. 24 ref: ${{ github.event.pull_request.head.sha }} 25 # Fetch all branches and history (we'll need the origin/master ref and 26 # the base commit). 27 fetch-depth: 0 28 29 - name: Set up Go 30 uses: actions/setup-go@v2 31 with: 32 go-version: "1.21" 33 34 - name: Get list of changed packages 35 shell: bash 36 run: | 37 set -euxo pipefail 38 # To get the base commit, we get the number of commits in the PR. 39 # Note that github.event.pull_request.base.sha is not what we want, 40 # that is the tip of master and not necessarily the PR fork point. 41 NUM_COMMITS=$(gh pr view $PR --json commits --jq '.commits | length') 42 BASE_SHA=$(git rev-parse HEAD~${NUM_COMMITS}) 43 CHANGED_PKGS=$(scripts/changed-go-pkgs.sh ${BASE_SHA} ${HEAD_SHA}) 44 echo "BASE_SHA=${BASE_SHA}" >> "${GITHUB_ENV}" 45 echo "CHANGED_PKGS=${CHANGED_PKGS}" >> "${GITHUB_ENV}" 46 47 - name: Generate "after" coverage 48 shell: bash 49 run: | 50 set -euxo pipefail 51 CHANGED_PKGS='${{ env.CHANGED_PKGS }}' 52 mkdir -p artifacts 53 # Make a copy of the script so that the "before" run below uses the 54 # same version. 55 cp scripts/pr-codecov-run-tests.sh ${RUNNER_TEMP}/ 56 ${RUNNER_TEMP}/pr-codecov-run-tests.sh artifacts/cover-${PR}-${HEAD_SHA}.json "${CHANGED_PKGS}" 57 58 - name: Generate "before" coverage 59 shell: bash 60 run: | 61 set -euxo pipefail 62 BASE_SHA='${{ env.BASE_SHA }}' 63 CHANGED_PKGS='${{ env.CHANGED_PKGS }}' 64 git checkout -f ${BASE_SHA} 65 ${RUNNER_TEMP}/pr-codecov-run-tests.sh artifacts/cover-${PR}-${BASE_SHA}.json "${CHANGED_PKGS}" 66 67 - name: Upload artifacts 68 uses: actions/upload-artifact@v2 69 with: 70 name: cover 71 path: artifacts/cover-*.json