-
Notifications
You must be signed in to change notification settings - Fork 2
85 lines (83 loc) · 3.24 KB
/
ccip-ocr3-build-lint-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
74
75
76
77
78
79
80
81
82
83
84
85
name: "Build lint and test CCIP-OCR3"
on:
pull_request:
push:
branches:
- 'ccip-develop'
jobs:
build-lint-test:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version: ['1.21']
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
run: go version
- name: Build
run: make
- name: Install linter
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.0
- name: Run linter
run: make lint
- name: Run tests
run: TEST_COUNT=20 COVERAGE_FILE=coverage.out make test
- name: Generate coverage report
if: github.event_name == 'pull_request'
run: |
go tool cover -func=coverage.out > coverage.txt
total=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
echo "coverage=$total" >> $GITHUB_ENV
- name: Coverage on target branch
if: github.event_name == 'pull_request'
run: |
git fetch origin ${{ github.base_ref }}
git checkout ${{ github.base_ref }}
go test -coverprofile=coverage_target.out ./...
go tool cover -func=coverage_target.out > coverage_target.txt
total=$(go tool cover -func=coverage_target.out | grep total | awk '{print $3}')
echo "coverage_target=$total" >> $GITHUB_ENV
- name: Remove previous coverage comments
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number: issue_number } = context.issue;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number
});
const coverageCommentPrefix = "### Test Coverage";
for (const comment of comments.data) {
if (comment.body.startsWith(coverageCommentPrefix)) {
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: comment.id
});
}
}
- name: Display coverage in PR comment
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const coverage = process.env.coverage;
const coverage_target = process.env.coverage_target;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Test Coverage\n\n| Branch | Coverage |\n|-----------------|-----------------|\n| ${{ github.head_ref }} | ${coverage} |\n| ${{ github.base_ref }} | ${coverage_target} |`
});