-
Notifications
You must be signed in to change notification settings - Fork 7
115 lines (104 loc) · 3.17 KB
/
ci.yml
File metadata and controls
115 lines (104 loc) · 3.17 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
fetch-depth: 0
- id: filter
run: |
if [ "${{ github.event_name }}" = "push" ]; then
# On push to main, always run
echo "code=true" >> "$GITHUB_OUTPUT"
else
# On PR, check if any non-markdown files changed
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -v '\.md$' || true)
if [ -z "$FILES" ]; then
echo "code=false" >> "$GITHUB_OUTPUT"
else
echo "code=true" >> "$GITHUB_OUTPUT"
fi
fi
CI:
name: CI
needs: [changes]
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Setup GO environment
run: |
go mod download
go get -u golang.org/x/lint/golint
go get -t .
- name: Vet
run: |
go vet ./...
- name: Unit tests
run: |
make test
make test-cov
- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 4
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi
integration:
name: Integration Tests
needs: [changes]
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build
run: make -B build
- uses: octo-sts/action@f603d3be9d8dd9871a265776e625a27b00effe05
id: octo-sts
with:
scope: privateerproj/privateer
identity: privateer
- name: pvtr-github-repo-scanner Plugin Integration Test
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
run: |
set -o pipefail
./test/integration_test.sh 2>&1 | tee integration_output.txt
- name: Verify integration test output
run: |
grep -E 'privateer_osps-baseline.*Passed.*Warnings.*Failed.*Possible' integration_output.txt