-
Notifications
You must be signed in to change notification settings - Fork 2
83 lines (81 loc) · 3.03 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
name: "Build lint and test CCIP-OCR3"
on:
pull_request:
push:
branches:
- 'main'
jobs:
build-lint-test:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version: ['1.22']
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: |
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 }}
TEST_COUNT=1 COVERAGE_FILE=coverage_target.out make test
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 = "| Metric |";
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: `| Metric | \`${{ github.head_ref }}\` | \`${{ github.base_ref }}\` |\n|--|--|--|\n| **Coverage** | ${coverage} | ${coverage_target} |`
});