Skip to content

Commit ea75176

Browse files
authored
Run base test in same working copy (#43)
1 parent 38eb3ee commit ea75176

2 files changed

Lines changed: 16 additions & 26 deletions

File tree

templates/github/workflows/test-integration.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,22 @@ jobs:
5555
5656
- name: Restore base test coverage
5757
id: base-coverage
58+
if: github.event.pull_request.base.sha != ''
5859
uses: actions/cache@v2
5960
with:
6061
path: |
6162
integration-base.txt
6263
# Use base sha for PR or new commit hash for master/main push in test result key.
63-
key: ${{ runner.os }}-integration-test-base-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
64+
key: ${{ runner.os }}-integration-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
6465

65-
- name: Checkout base code
66-
if: env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
67-
uses: actions/checkout@v2
68-
with:
69-
ref: ${{ github.event.pull_request.base.sha }}
70-
path: __base
71-
- name: Docker Compose
72-
run: (test -f ${{ env.DOCKER_COMPOSE_FILE }} && docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d && docker ps && docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} logs) || echo "::warning ::Missing ${{ env.DOCKER_COMPOSE_FILE }} file"
7366
- name: Run test for base code
7467
if: env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
7568
run: |
76-
cd __base
77-
make | grep test-integration && (make test-integration && go tool cover -func=./integration.coverprofile > ../integration-base.txt) || echo "No test-integration in base"
69+
git fetch origin master ${{ github.event.pull_request.base.sha }}
70+
HEAD=$(git rev-parse HEAD)
71+
git reset --hard ${{ github.event.pull_request.base.sha }}
72+
(make test-integration && go tool cover -func=./integration.coverprofile > integration-base.txt) || echo "No test-integration in base"
73+
git reset --hard $HEAD
7874
7975
- name: Test
8076
id: test
@@ -90,12 +86,11 @@ jobs:
9086
if: github.event.pull_request.base.sha != ''
9187
run: |
9288
git fetch origin master ${{ github.event.pull_request.base.sha }}
93-
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && echo "78146b31ec37ac8037a25d33b0f3c70c85adb0f8b682441b04b3daa518eaa489 gocovdiff" | shasum -c
89+
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.4/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && shasum -a 256 gocovdiff && echo "b351c67526eefeb0671c82e9271ae984875865eed19e911f40f78348cb98347c gocovdiff" | shasum -c
9490
REP=$(./gocovdiff -cov integration.coverprofile -gha-annotations gha-integration.txt -delta-cov-file delta-cov-integration.txt -target-delta-cov ${TARGET_DELTA_COV})
9591
echo "${REP}"
9692
REP="${REP//$'\n'/%0A}"
9793
cat gha-integration.txt
98-
test -e integration-base.txt && cat integration-base.txt
9994
DIFF=$(test -e integration-base.txt && ./gocovdiff -func-cov integration.txt -func-base-cov integration-base.txt || echo "Missing base coverage file")
10095
DIFF="${DIFF//$'\n'/%0A}"
10196
TOTAL=$(cat delta-cov-integration.txt)

templates/github/workflows/test-unit.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,22 @@ jobs:
5858
5959
- name: Restore base test coverage
6060
id: base-coverage
61-
if: matrix.go-version == env.COV_GO_VERSION
61+
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
6262
uses: actions/cache@v2
6363
with:
6464
path: |
6565
unit-base.txt
6666
# Use base sha for PR or new commit hash for master/main push in test result key.
67-
key: ${{ runner.os }}-unit-test-base-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
68-
69-
- name: Checkout base code
70-
if: matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
71-
uses: actions/checkout@v2
72-
with:
73-
ref: ${{ github.event.pull_request.base.sha }}
74-
path: __base
67+
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
7568

7669
- name: Run test for base code
7770
if: matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
7871
run: |
79-
cd __base
80-
make | grep test-unit && (make test-unit && go tool cover -func=./unit.coverprofile > ../unit-base.txt) || echo "No test-unit in base"
72+
git fetch origin master ${{ github.event.pull_request.base.sha }}
73+
HEAD=$(git rev-parse HEAD)
74+
git reset --hard ${{ github.event.pull_request.base.sha }}
75+
(make test-unit && go tool cover -func=./unit.coverprofile > unit-base.txt) || echo "No test-unit in base"
76+
git reset --hard $HEAD
8177
8278
- name: Test
8379
id: test
@@ -93,12 +89,11 @@ jobs:
9389
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
9490
run: |
9591
git fetch origin master ${{ github.event.pull_request.base.sha }}
96-
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && echo "78146b31ec37ac8037a25d33b0f3c70c85adb0f8b682441b04b3daa518eaa489 gocovdiff" | shasum -c
92+
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.4/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && shasum -a 256 gocovdiff && echo "b351c67526eefeb0671c82e9271ae984875865eed19e911f40f78348cb98347c gocovdiff" | shasum -c
9793
REP=$(./gocovdiff -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV})
9894
echo "${REP}"
9995
REP="${REP//$'\n'/%0A}"
10096
cat gha-unit.txt
101-
test -e unit-base.txt && cat unit-base.txt
10297
DIFF=$(test -e unit-base.txt && ./gocovdiff -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file")
10398
DIFF="${DIFF//$'\n'/%0A}"
10499
TOTAL=$(cat delta-cov-unit.txt)

0 commit comments

Comments
 (0)