-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (199 loc) · 6.67 KB
/
ci.yml
File metadata and controls
225 lines (199 loc) · 6.67 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Go CI / CD
on:
push:
branches:
- main
- master
pull_request:
permissions:
contents: read
jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.64.5
# Only report issues introduced in the PR.
only-new-issues: true
security:
name: Security Scans
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: '-no-fail -fmt sarif -out results.sarif ./...'
- name: govulncheck
# Upstream hedera-sdk-go transitively pulls go-ethereum with known
# vulns we cannot fix. Report but do not block the pipeline.
continue-on-error: true
uses: golang/govulncheck-action@v1
with:
go-version-file: go.mod
- name: Run Trivy vulnerability scanner
continue-on-error: true
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Gosec SARIF
if: always() && hashFiles('results.sarif') != ''
continue-on-error: true
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
category: gosec
- name: Upload Trivy SARIF
if: always() && hashFiles('trivy-results.sarif') != ''
continue-on-error: true
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-results.sarif
category: trivy
test:
name: Test and Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run Tests
run: go test -v -coverprofile=coverage.out ./...
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Verify Build
run: go build -v ./...
- name: Verify go.mod / go.sum are tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum
- name: Run go vet
run: go vet ./...
release:
name: Publish Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs:
- lint
- security
- test
- build
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: release-main
cancel-in-progress: false
env:
MODULE_PATH: github.com/hashgraph-online/standards-sdk-go
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine release tag
id: release_tag
shell: bash
run: |
set -euo pipefail
git fetch --tags --force
existing_tag="$(git tag --points-at "${GITHUB_SHA}" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)"
if [ -n "${existing_tag}" ]; then
echo "tag=${existing_tag}" >> "${GITHUB_OUTPUT}"
echo "created=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
latest_tag="$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -n1)"
if [ -z "${latest_tag}" ]; then
latest_tag="v0.0.0"
fi
version_without_v="${latest_tag#v}"
IFS='.' read -r major minor patch <<< "${version_without_v}"
next_tag="v${major}.${minor}.$((patch + 1))"
echo "tag=${next_tag}" >> "${GITHUB_OUTPUT}"
echo "created=true" >> "${GITHUB_OUTPUT}"
- name: Create git tag and GitHub release
if: steps.release_tag.outputs.created == 'true'
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
tag="${{ steps.release_tag.outputs.tag }}"
git tag "${tag}" "${GITHUB_SHA}"
git push origin "${tag}"
gh release create "${tag}" \
--title "${tag}" \
--generate-notes \
--target "${GITHUB_SHA}"
- name: Wait for pkg.go.dev index
id: pkg_index
continue-on-error: true
env:
RELEASE_TAG: ${{ steps.release_tag.outputs.tag }}
shell: bash
run: |
python3 - <<'PY'
import os
import sys
import time
import urllib.error
import urllib.request
module_path = os.environ["MODULE_PATH"]
release_tag = os.environ["RELEASE_TAG"]
url = f"https://pkg.go.dev/{module_path}@{release_tag}"
attempts = 40
delay_seconds = 15
timeout_seconds = 20
print(f"Polling {url} for {release_tag}")
for attempt in range(1, attempts + 1):
try:
with urllib.request.urlopen(url, timeout=timeout_seconds) as response:
body = response.read().decode("utf-8", "ignore")
ok = response.status == 200 and release_tag in body
print(f"attempt {attempt:02d}: status={response.status} indexed={ok}")
if ok:
sys.exit(0)
except urllib.error.HTTPError as error:
print(f"attempt {attempt:02d}: status={error.code} indexed=False")
except Exception as error:
print(f"attempt {attempt:02d}: error={error} indexed=False")
time.sleep(delay_seconds)
raise SystemExit(
f"Timed out waiting for pkg.go.dev to index {module_path}@{release_tag}"
)
PY
- name: Report pkg.go.dev indexing delay
if: steps.pkg_index.outcome == 'failure'
env:
RELEASE_TAG: ${{ steps.release_tag.outputs.tag }}
GITHUB_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
shell: bash
run: |
echo "::warning::pkg.go.dev indexing timed out for ${MODULE_PATH}@${RELEASE_TAG}. Release was published; recheck later. Run: ${GITHUB_RUN_URL}"