| 1 |
name: ci |
| 2 |
on: |
| 3 |
push: |
| 4 |
branches: |
| 5 |
- main |
| 6 |
pull_request: |
| 7 |
env: |
| 8 |
# Default version of Go to use by CI workflows. This should be the latest |
| 9 |
# release of Go; developers likely use the latest release in development and |
| 10 |
# we want to catch any bugs (e.g. lint errors, race detection) with this |
| 11 |
# release before they are merged. The Go compatibility guarantees ensure |
| 12 |
# backwards compatibility with the previous two minor releases and we |
| 13 |
# explicitly test our code for these versions so keeping this at prior |
| 14 |
# versions does not add value. |
| 15 |
DEFAULT_GO_VERSION: "~1.26.0" |
| 16 |
# Declare default permissions as read only. |
| 17 |
permissions: read-all |
| 18 |
jobs: |
| 19 |
lint: |
| 20 |
runs-on: ubuntu-latest |
| 21 |
steps: |
| 22 |
- name: Checkout Repo |
| 23 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 24 |
with: |
| 25 |
fetch-depth: 0 ## Needed for "Set internal/tools/go.mod timestamp" step. |
| 26 |
- name: Install Go |
| 27 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 28 |
with: |
| 29 |
go-version: ${{ env.DEFAULT_GO_VERSION }} |
| 30 |
check-latest: true |
| 31 |
cache-dependency-path: "**/go.sum" |
| 32 |
- name: Tools cache |
| 33 |
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 |
| 34 |
env: |
| 35 |
cache-name: go-tools-cache |
| 36 |
with: |
| 37 |
path: .tools |
| 38 |
key: ${{ runner.os }}-${{ env.DEFAULT_GO_VERSION }}-${{ env.cache-name }}-${{ hashFiles('./internal/tools/**') }} |
| 39 |
# The step below is needed to not rebuild all the build tools. |
| 40 |
- name: Set internal/tools timestamps |
| 41 |
run: | |
| 42 |
git ls-files \ |
| 43 |
internal/tools/go.mod \ |
| 44 |
internal/tools/semconvkit \ |
| 45 |
internal/tools/verifyreadmes \ |
| 46 |
| while IFS= read -r filename; do |
| 47 |
unixtime=$(git log -1 --format="%at" -- "${filename}") |
| 48 |
touchtime=$(date -d @"${unixtime}" +'%Y%m%d%H%M.%S') |
| 49 |
touch -t "${touchtime}" "${filename}" |
| 50 |
ls -la --time-style=full-iso "${filename}" |
| 51 |
done |
| 52 |
- name: Generate |
| 53 |
run: make generate |
| 54 |
- name: Run linters |
| 55 |
run: make toolchain-check license-check lint vanity-import-check verify-readmes verify-mods |
| 56 |
- name: Build |
| 57 |
run: make build |
| 58 |
- name: Check clean repository |
| 59 |
run: make check-clean-work-tree |
| 60 |
|
| 61 |
govulncheck: |
| 62 |
runs-on: ubuntu-latest |
| 63 |
steps: |
| 64 |
- name: Checkout Repo |
| 65 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 66 |
with: |
| 67 |
fetch-depth: 0 ## Needed for "Set internal/tools/go.mod timestamp" step. |
| 68 |
- name: Install Go |
| 69 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 70 |
with: |
| 71 |
go-version: ${{ env.DEFAULT_GO_VERSION }} |
| 72 |
check-latest: true |
| 73 |
cache-dependency-path: "**/go.sum" |
| 74 |
- name: Tools cache |
| 75 |
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 |
| 76 |
env: |
| 77 |
cache-name: go-tools-cache |
| 78 |
with: |
| 79 |
path: .tools |
| 80 |
key: ${{ runner.os }}-${{ env.DEFAULT_GO_VERSION }}-${{ env.cache-name }}-${{ hashFiles('./internal/tools/**') }} |
| 81 |
# The step below is needed to not rebuild all the build tools. |
| 82 |
- name: Set internal/tools timestamps |
| 83 |
run: | |
| 84 |
git ls-files \ |
| 85 |
internal/tools/go.mod \ |
| 86 |
internal/tools/semconvkit \ |
| 87 |
internal/tools/verifyreadmes \ |
| 88 |
| while IFS= read -r filename; do |
| 89 |
unixtime=$(git log -1 --format="%at" -- "${filename}") |
| 90 |
touchtime=$(date -d @"${unixtime}" +'%Y%m%d%H%M.%S') |
| 91 |
touch -t "${touchtime}" "${filename}" |
| 92 |
ls -la --time-style=full-iso "${filename}" |
| 93 |
done |
| 94 |
- name: Run govulncheck |
| 95 |
run: make govulncheck |
| 96 |
|
| 97 |
test-bench: |
| 98 |
runs-on: ubuntu-latest |
| 99 |
steps: |
| 100 |
- name: Checkout Repo |
| 101 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 102 |
- name: Setup Environment |
| 103 |
run: | |
| 104 |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV |
| 105 |
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH |
| 106 |
- name: Install Go |
| 107 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 108 |
with: |
| 109 |
go-version: ${{ env.DEFAULT_GO_VERSION }} |
| 110 |
cache-dependency-path: "**/go.sum" |
| 111 |
- name: Run benchmarks to check functionality |
| 112 |
run: make test-bench |
| 113 |
|
| 114 |
test-race: |
| 115 |
runs-on: ubuntu-latest |
| 116 |
steps: |
| 117 |
- name: Checkout Repo |
| 118 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 119 |
- name: Install Go |
| 120 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 121 |
with: |
| 122 |
go-version: ${{ env.DEFAULT_GO_VERSION }} |
| 123 |
check-latest: true |
| 124 |
cache-dependency-path: "**/go.sum" |
| 125 |
- name: Run tests with race detector |
| 126 |
run: make test-race |
| 127 |
|
| 128 |
test-concurrent-safe: |
| 129 |
runs-on: ubuntu-latest |
| 130 |
steps: |
| 131 |
- name: Checkout Repo |
| 132 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 133 |
- name: Install Go |
| 134 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 135 |
with: |
| 136 |
go-version: ${{ env.DEFAULT_GO_VERSION }} |
| 137 |
check-latest: true |
| 138 |
cache-dependency-path: "**/go.sum" |
| 139 |
- name: Run ConcurrentSafe tests multiple times with race detector |
| 140 |
run: make test-concurrent-safe |
| 141 |
|
| 142 |
test-coverage: |
| 143 |
runs-on: ubuntu-latest |
| 144 |
steps: |
| 145 |
- name: Checkout Repo |
| 146 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 147 |
- name: Install Go |
| 148 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 149 |
with: |
| 150 |
go-version: ${{ env.DEFAULT_GO_VERSION }} |
| 151 |
check-latest: true |
| 152 |
cache-dependency-path: "**/go.sum" |
| 153 |
- name: Run coverage tests |
| 154 |
run: make test-coverage |
| 155 |
- name: Store coverage test output |
| 156 |
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 157 |
with: |
| 158 |
name: coverage-artifacts-${{ env.DEFAULT_GO_VERSION }} |
| 159 |
path: coverage.txt |
| 160 |
|
| 161 |
codecov: |
| 162 |
runs-on: ubuntu-latest |
| 163 |
needs: [test-coverage] |
| 164 |
steps: |
| 165 |
- name: Checkout Repo |
| 166 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 167 |
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 168 |
with: |
| 169 |
pattern: coverage-artifacts-${{ env.DEFAULT_GO_VERSION }} |
| 170 |
- name: Upload coverage report |
| 171 |
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 |
| 172 |
with: |
| 173 |
fail_ci_if_error: true |
| 174 |
files: ./coverage.txt |
| 175 |
verbose: true |
| 176 |
|
| 177 |
compatibility-test: |
| 178 |
strategy: |
| 179 |
matrix: |
| 180 |
go-version: ["1.26.0", "1.25.0"] |
| 181 |
platform: |
| 182 |
- os: ubuntu-latest |
| 183 |
arch: "386" |
| 184 |
- os: ubuntu-latest |
| 185 |
arch: amd64 |
| 186 |
- os: ubuntu-22.04-arm |
| 187 |
arch: arm64 |
| 188 |
- os: macos-latest |
| 189 |
arch: amd64 |
| 190 |
- os: macos-latest |
| 191 |
arch: arm64 |
| 192 |
- os: windows-latest |
| 193 |
arch: "386" |
| 194 |
- os: windows-latest |
| 195 |
arch: amd64 |
| 196 |
runs-on: ${{ matrix.platform.os }} |
| 197 |
steps: |
| 198 |
- name: Checkout code |
| 199 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 200 |
- name: Install Go |
| 201 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 202 |
with: |
| 203 |
go-version: ${{ matrix.go-version }} |
| 204 |
check-latest: true |
| 205 |
cache-dependency-path: "**/go.sum" |
| 206 |
- name: Run tests |
| 207 |
env: |
| 208 |
GOARCH: ${{ matrix.platform.arch }} |
| 209 |
run: make test-short |
| 210 |
|
| 211 |
test-compatibility: |
| 212 |
runs-on: ubuntu-latest |
| 213 |
needs: [compatibility-test] |
| 214 |
if: always() |
| 215 |
steps: |
| 216 |
- name: Test if compatibility-test passed |
| 217 |
run: | |
| 218 |
echo ${{ needs.compatibility-test.result }} |
| 219 |
test ${{ needs.compatibility-test.result }} == "success" |