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