| 1 |
name: build-and-test |
| 2 |
on: |
| 3 |
push: |
| 4 |
branches: [main] |
| 5 |
tags: |
| 6 |
- "v[0-9]+.[0-9]+.[0-9]+*" |
| 7 |
merge_group: |
| 8 |
types: [checks_requested] |
| 9 |
pull_request: |
| 10 |
|
| 11 |
permissions: read-all |
| 12 |
|
| 13 |
concurrency: |
| 14 |
group: ${{ github.workflow }}-${{ github.ref_name }} |
| 15 |
cancel-in-progress: true |
| 16 |
|
| 17 |
jobs: |
| 18 |
setup-environment: |
| 19 |
runs-on: ubuntu-latest |
| 20 |
steps: |
| 21 |
- name: Checkout Repo |
| 22 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 23 |
- name: Setup Go |
| 24 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 25 |
with: |
| 26 |
go-version: oldstable |
| 27 |
cache: false |
| 28 |
- name: Cache Go |
| 29 |
id: go-cache |
| 30 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 31 |
with: |
| 32 |
path: | |
| 33 |
~/go/bin |
| 34 |
~/go/pkg/mod |
| 35 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 36 |
- name: Install dependencies |
| 37 |
if: steps.go-cache.outputs.cache-hit != 'true' |
| 38 |
run: make gomoddownload |
| 39 |
|
| 40 |
lint: |
| 41 |
runs-on: ubuntu-latest |
| 42 |
needs: [setup-environment] |
| 43 |
steps: |
| 44 |
- name: Checkout Repo |
| 45 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 46 |
- name: Setup Go |
| 47 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 48 |
with: |
| 49 |
go-version: oldstable |
| 50 |
cache: false |
| 51 |
- name: Cache Go |
| 52 |
id: go-cache |
| 53 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 54 |
with: |
| 55 |
path: | |
| 56 |
~/go/bin |
| 57 |
~/go/pkg/mod |
| 58 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 59 |
- name: golint |
| 60 |
run: make -j2 golint |
| 61 |
- name: goimpi |
| 62 |
run: make goimpi |
| 63 |
|
| 64 |
govulncheck: |
| 65 |
runs-on: ubuntu-latest |
| 66 |
timeout-minutes: 30 |
| 67 |
needs: [setup-environment] |
| 68 |
steps: |
| 69 |
- name: Checkout Repo |
| 70 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 71 |
- name: Setup Go |
| 72 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 73 |
with: |
| 74 |
go-version: oldstable |
| 75 |
cache: false |
| 76 |
- name: Cache Go |
| 77 |
id: go-cache |
| 78 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 79 |
with: |
| 80 |
path: | |
| 81 |
~/go/bin |
| 82 |
~/go/pkg/mod |
| 83 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 84 |
- name: Run `govulncheck` |
| 85 |
run: make govulncheck |
| 86 |
|
| 87 |
checks: |
| 88 |
runs-on: ubuntu-latest |
| 89 |
needs: [setup-environment] |
| 90 |
steps: |
| 91 |
- name: Checkout Repo |
| 92 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 93 |
- name: Setup Go |
| 94 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 95 |
with: |
| 96 |
go-version: stable |
| 97 |
cache: false |
| 98 |
- name: Cache Go |
| 99 |
id: go-cache |
| 100 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 101 |
with: |
| 102 |
path: | |
| 103 |
~/go/bin |
| 104 |
~/go/pkg/mod |
| 105 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 106 |
- name: checklicense |
| 107 |
run: make checklicense |
| 108 |
- name: misspell |
| 109 |
run: make misspell |
| 110 |
- name: checkdoc |
| 111 |
run: make checkdoc |
| 112 |
- name: checkapi |
| 113 |
run: make checkapi |
| 114 |
- name: Check for go mod dependency changes |
| 115 |
run: | |
| 116 |
make gotidy |
| 117 |
git diff --exit-code || (echo 'go.mod/go.sum deps changes detected, please run "make gotidy" and commit the changes in this PR.' && exit 1) |
| 118 |
- name: go:porto |
| 119 |
run: | |
| 120 |
make goporto |
| 121 |
git diff --exit-code || (echo 'Porto links are out of date, please run "make goporto" and commit the changes in this PR.' && exit 1) |
| 122 |
- name: go:generate |
| 123 |
run: | |
| 124 |
make gogenerate |
| 125 |
git diff --exit-code || (echo 'Generated code is out of date, please run "make gogenerate" and commit the changes in this PR.' && exit 1) |
| 126 |
- name: Generate proto files |
| 127 |
run: | |
| 128 |
make genproto |
| 129 |
git diff --exit-code || (echo 'Generated code is out of date, please run "make genproto" and commit the changes in this PR.' && exit 1) |
| 130 |
- name: Gen Pdata |
| 131 |
run: | |
| 132 |
make genpdata |
| 133 |
git diff --exit-code || (echo 'Generated code is out of date, please run "make genpdata" and commit the changes in this PR.' && exit 1) |
| 134 |
- name: Gen otelcorecol |
| 135 |
run: | |
| 136 |
make genotelcorecol |
| 137 |
git diff --exit-code || (echo 'Generated code is out of date, please run "make genotelcorecol" and commit the changes in this PR.' && exit 1) |
| 138 |
- name: Multimod verify |
| 139 |
run: make multimod-verify |
| 140 |
- name: crosslink |
| 141 |
run: | |
| 142 |
make crosslink |
| 143 |
git diff -s --exit-code || (echo 'Replace statements are out of date, please run "make crosslink" and commit the changes in this PR.' && exit 1) |
| 144 |
|
| 145 |
unittest-matrix: |
| 146 |
strategy: |
| 147 |
matrix: |
| 148 |
runner: [ubuntu-latest] |
| 149 |
go-version: ["stable", "oldstable"] |
| 150 |
runs-on: ${{ matrix.runner }} |
| 151 |
needs: [setup-environment] |
| 152 |
steps: |
| 153 |
- name: Checkout Repo |
| 154 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 155 |
- name: Setup Go |
| 156 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 157 |
with: |
| 158 |
go-version: ${{ matrix.go-version }} |
| 159 |
cache: false |
| 160 |
- name: Cache Go |
| 161 |
id: go-cache |
| 162 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 163 |
with: |
| 164 |
path: | |
| 165 |
~/go/bin |
| 166 |
~/go/pkg/mod |
| 167 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 168 |
- name: Cache Build |
| 169 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 170 |
with: |
| 171 |
path: ~/.cache/go-build |
| 172 |
key: unittest-${{ runner.os }}-${{ matrix.runner }}-go-build-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} |
| 173 |
- name: Run Unit Tests |
| 174 |
run: | |
| 175 |
make -j4 gotest-with-junit |
| 176 |
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 177 |
with: |
| 178 |
name: test-results-${{ runner.os }}-${{ matrix.runner }}-${{ matrix.go-version }} |
| 179 |
path: internal/tools/testresults/ |
| 180 |
retention-days: 4 |
| 181 |
unittest: |
| 182 |
if: always() |
| 183 |
runs-on: ubuntu-latest |
| 184 |
needs: [setup-environment, unittest-matrix] |
| 185 |
steps: |
| 186 |
- name: Print result |
| 187 |
run: echo ${{ needs.unittest-matrix.result }} |
| 188 |
- name: Interpret result |
| 189 |
run: | |
| 190 |
if [[ success == ${{ needs.unittest-matrix.result }} ]] |
| 191 |
then |
| 192 |
echo "All matrix jobs passed!" |
| 193 |
else |
| 194 |
echo "One or more matrix jobs failed." |
| 195 |
false |
| 196 |
fi |
| 197 |
|
| 198 |
test-coverage: |
| 199 |
runs-on: ubuntu-latest |
| 200 |
needs: [setup-environment] |
| 201 |
steps: |
| 202 |
- name: Checkout Repo |
| 203 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 204 |
- name: Setup Go |
| 205 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 206 |
with: |
| 207 |
go-version: oldstable |
| 208 |
cache: false |
| 209 |
- name: Cache Go |
| 210 |
id: go-cache |
| 211 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 212 |
with: |
| 213 |
path: | |
| 214 |
~/go/bin |
| 215 |
~/go/pkg/mod |
| 216 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 217 |
- name: Cache Build |
| 218 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 219 |
with: |
| 220 |
path: ~/.cache/go-build |
| 221 |
key: coverage-${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} |
| 222 |
- name: Run Unit Tests With Coverage |
| 223 |
run: make gotest-with-cover |
| 224 |
- name: Upload coverage report |
| 225 |
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # 5.5.1 |
| 226 |
env: |
| 227 |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 228 |
|
| 229 |
cross-build-collector: |
| 230 |
needs: [setup-environment] |
| 231 |
runs-on: ubuntu-latest |
| 232 |
timeout-minutes: 10 |
| 233 |
strategy: |
| 234 |
fail-fast: false |
| 235 |
matrix: |
| 236 |
include: |
| 237 |
# Go 1.15 dropped support for 32-bit binaries |
| 238 |
# on macOS: https://go.dev/doc/go1.15 |
| 239 |
#- goos: darwin |
| 240 |
# goarch: 386 |
| 241 |
- goos: aix |
| 242 |
goarch: ppc64 |
| 243 |
- goos: darwin |
| 244 |
goarch: amd64 |
| 245 |
- goos: darwin |
| 246 |
goarch: arm64 |
| 247 |
- goos: linux |
| 248 |
goarch: 386 |
| 249 |
- goos: linux |
| 250 |
goarch: amd64 |
| 251 |
- goos: linux |
| 252 |
goarch: arm64 |
| 253 |
- goos: linux |
| 254 |
goarch: ppc64le |
| 255 |
- goos: linux |
| 256 |
goarch: riscv64 |
| 257 |
- goos: linux |
| 258 |
goarch: arm |
| 259 |
goarm: 7 |
| 260 |
- goos: linux |
| 261 |
goarch: s390x |
| 262 |
- goos: windows |
| 263 |
goarch: 386 |
| 264 |
- goos: windows |
| 265 |
goarch: amd64 |
| 266 |
- goos: windows |
| 267 |
goarch: arm64 |
| 268 |
|
| 269 |
steps: |
| 270 |
- name: Checkout Repo |
| 271 |
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 272 |
- name: Setup Go |
| 273 |
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 274 |
with: |
| 275 |
go-version: oldstable |
| 276 |
cache: false |
| 277 |
- name: Cache Go |
| 278 |
id: go-cache |
| 279 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 280 |
with: |
| 281 |
path: | |
| 282 |
~/go/bin |
| 283 |
~/go/pkg/mod |
| 284 |
key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }} |
| 285 |
- name: Build |
| 286 |
env: |
| 287 |
GOOS: ${{matrix.goos}} |
| 288 |
GOARCH: ${{matrix.goarch}} |
| 289 |
GOARM: ${{matrix.goarm}} |
| 290 |
run: | |
| 291 |
make otelcorecol |