-
Notifications
You must be signed in to change notification settings - Fork 27
73 lines (73 loc) · 2.91 KB
/
test.yml
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
72
73
on: [push, pull_request]
name: Test
permissions:
pull-requests: write
jobs:
test:
strategy:
matrix:
go-version: [1.20.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Test
run: |
make web-build
go test -coverpkg=./... -coverprofile=coverage.out -covermode=count ./...
- name: Get total code coverage
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
id: cc
run: |
set -x
cc_total=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "cc_total=$cc_total" >> $GITHUB_OUTPUT
- name: Restore base test coverage
id: base-coverage
if: matrix.os == 'ubuntu-latest' && github.event.pull_request.base.sha != ''
uses: actions/cache@v3
with:
path: |
unit-base.txt
# Use base sha for PR or new commit hash for master/main push in test result key.
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
- name: Run test for base code
if: matrix.os == 'ubuntu-latest' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
run: |
git fetch origin main ${{ github.event.pull_request.base.sha }}
HEAD=$(git rev-parse HEAD)
git reset --hard ${{ github.event.pull_request.base.sha }}
make web-build
go generate ./...
go test -coverpkg=./... -coverprofile=base_coverage.out -covermode=count ./...
go tool cover -func=base_coverage.out > unit-base.txt
git reset --hard $HEAD
- name: Get base code coverage value
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
id: cc_b
run: |
set -x
cc_base_total=`grep total ./unit-base.txt | grep -Eo '[0-9]+\.[0-9]+'`
echo "cc_base_total=$cc_base_total" >> $GITHUB_OUTPUT
- name: Add coverage information to action summary
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
run: echo 'Code coverage ' ${{steps.cc.outputs.cc_total}}'% Prev ' ${{steps.cc_b.outputs.cc_base_total}}'%' >> $GITHUB_STEP_SUMMARY
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: build --rm-dist --snapshot
- name: Copy files (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
cp dist/pelican_linux_amd64_v1/pelican ./
- name: Run Integration Tests
if: matrix.os == 'ubuntu-latest'
run: ./tests/citests.sh