Skip to content

Commit 520e46b

Browse files
authored
Improve Github Actions Workflow and GoLint (#4672)
### Details: This PR improves the Go-Linting structure in our CI, as well as move the Github Actions workflows into the "Pipeline" mentality, rather than individual Workflows. Changes: 1. Currently Go linting is tightly coupled with pre-commits, which make things very complex and error prone. This commit removes Go linting from any pre-commit logic, and only have it as a first class citizen in Github Actions. 2. Create the Notion of a pipeline in github actions, and not just standalone workflows. One step towards migrating from BuildKite 3. Use CI built binaries in Test Containers Suite. ### Github actions pipeline will look like this: ![Screenshot 2024-10-28 at 6 00 11 PM](https://github.com/user-attachments/assets/9f927e69-4d9a-4a4a-b021-9ee5eb1df143)
1 parent efddb20 commit 520e46b

18 files changed

+220
-192
lines changed

.github/workflows/build.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build Bacalhau Binaries
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
name: Build Binary
9+
runs-on: ubuntu-latest
10+
outputs:
11+
status: ${{ job.status }}
12+
strategy:
13+
matrix:
14+
include:
15+
- os: linux
16+
goarch: amd64
17+
- os: linux
18+
goarch: arm64
19+
- os: linux
20+
goarch: armv7
21+
- os: linux
22+
goarch: armv6
23+
- os: darwin
24+
goarch: amd64
25+
- os: darwin
26+
goarch: arm64
27+
- os: windows
28+
goarch: amd64
29+
30+
steps:
31+
- name: Install earthly
32+
uses: earthly/actions-setup@v1
33+
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: "0" # Need to fetch all due to how bacalhau constructs semver
37+
38+
- uses: actions/setup-go@v5
39+
with:
40+
go-version-file: go.work
41+
42+
- name: Build
43+
env:
44+
GOOS: ${{ matrix.os }}
45+
GOARCH: ${{ matrix.goarch }}
46+
PRIVATE_PEM: ${{ secrets.PRIVATE_PEM }}
47+
PUBLIC_PEM: ${{ secrets.PUBLIC_PEM }}
48+
PRIVATE_KEY_PASSPHRASE: ${{ secrets.PRIVATE_KEY_PASSPHRASE }}
49+
run: |
50+
# Add Keys to expected files
51+
echo "${PRIVATE_PEM}" > /tmp/private.pem && chmod 600 /tmp/private.pem
52+
echo "${PUBLIC_PEM}" > /tmp/public.pem && chmod 600 /tmp/public.pem
53+
54+
# Start build
55+
echo "==> Building bacalhau binary for: ${GOOS} ${GOARCH}..."
56+
make build-bacalhau-tgz
57+
echo "===> Done building bacalhau binary."
58+
59+
# Listing Builds
60+
echo "===> Built Artifacts:"
61+
ls -lh dist/
62+
63+
# Remove keys, good security practice
64+
rm /tmp/private.pem /tmp/public.pem
65+
66+
- name: Upload binary artifacts
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: ${{ matrix.os }}-${{ matrix.goarch }}
70+
path: "dist/bacalhau_*"
71+
retention-days: 1 # Short retention since these are intermediate artifacts, also save money
72+
73+
- name: Report build status
74+
if: always()
75+
run: |
76+
echo "Build completed for ${{ matrix.os }}-${{ matrix.goarch }}"
77+
echo "Status: ${{ job.status }}"

.github/workflows/cspell.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
name: Codespell
33

44
on:
5-
push:
6-
branches: [main]
7-
pull_request:
8-
branches: [main]
9-
repository_dispatch:
10-
types: [ok-to-test]
5+
workflow_call:
116

127
jobs:
138
codespell:

.github/workflows/lint.yml

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
name: Lints
22

33
on:
4-
pull_request:
5-
push:
6-
branches: [main]
7-
repository_dispatch:
8-
types: [ok-to-test]
4+
workflow_call:
95

106
jobs:
7+
# A separate Go-Lint job since the current lint job is heavily
8+
# coupled with a lot of tooling, which will be removed and
9+
# simplified, one step at a time.
10+
# For now, we are just extracting the go-lint.
11+
go-lint:
12+
strategy:
13+
matrix:
14+
os: [ ubuntu-latest ]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.work
21+
- name: Setup Dummy WebUi Build
22+
if: matrix.os == 'ubuntu-latest'
23+
run: |
24+
mkdir -p webui/build && touch webui/build/index.html
25+
- uses: golangci/golangci-lint-action@v6
26+
with:
27+
skip-cache: true
28+
29+
# TODO: Decouple Each Component Linting
1130
lint:
1231
runs-on: ubuntu-latest
1332
steps:

.github/workflows/pipeline-main.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Main Pipeline
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
repository_dispatch:
9+
types: [ok-to-test]
10+
11+
jobs:
12+
build:
13+
uses: ./.github/workflows/build.yml
14+
secrets: inherit
15+
16+
lint:
17+
uses: ./.github/workflows/lint.yml
18+
19+
swagger-validation:
20+
uses: ./.github/workflows/swagger-validation.yml
21+
22+
cspell:
23+
uses: ./.github/workflows/cspell.yml
24+
25+
testcontainers-suite:
26+
needs: [build, lint, swagger-validation, cspell]
27+
if: success()
28+
uses: ./.github/workflows/testcontainers-suite.yml
29+
with:
30+
os: linux
31+
arch: amd64
+2-23
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: Swagger Validation
22

33
on:
4-
pull_request:
5-
branches:
6-
- main
4+
workflow_call:
75

86
jobs:
97
ensure-up-to-date:
@@ -17,50 +15,31 @@ jobs:
1715
with:
1816
fetch-depth: 1
1917

20-
# Detect Go version from go.mod
21-
- name: Detect Go version from go.mod
22-
id: detect-go-version
23-
shell: bash
24-
run: |
25-
set -euo pipefail
26-
go_version=$(grep '^go ' go.mod | awk '{print $2}')
27-
echo "Go version detected: $go_version"
28-
echo "golang-version=$go_version" >> $GITHUB_ENV
29-
30-
# Setup Go using the detected version
3118
- name: Setup Go
3219
uses: actions/setup-go@v5
3320
with:
34-
go-version: ${{ env.golang-version }}
21+
go-version-file: go.work
3522
cache: true
3623

3724
# Install swag (Swagger generator)
3825
- name: Install Swag
39-
shell: bash
4026
run: |
41-
set -euo pipefail
4227
go install github.com/swaggo/swag/cmd/swag@latest
4328
4429
# Verify swag installation
4530
- name: Verify Swag Installation
46-
shell: bash
4731
run: |
48-
set -euo pipefail
4932
if ! command -v swag &> /dev/null; then
5033
echo "Swag is not installed. Please ensure Go is properly configured and Swag is installed."
5134
exit 1
5235
fi
5336
5437
# Generate the swagger.json
5538
- name: Generate Swagger file
56-
shell: bash
5739
run: |
58-
set -euo pipefail
5940
make generate-swagger
6041
6142
# Compare the newly generated swagger.json with the committed swagger.json
6243
- name: Check for Swagger differences
63-
shell: bash
6444
run: |
65-
set -euo pipefail
6645
git diff --exit-code pkg/swagger/swagger.json || (echo "Swagger is outdated. Please regenerate it with 'make generate-swagger' and commit the changes." && exit 1)

.github/workflows/testcontainers-integration-tests.yml

-31
This file was deleted.
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: TestContainers Suite
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
os:
7+
required: true
8+
type: string
9+
arch:
10+
required: true
11+
type: string
12+
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Download compiled binary
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: ${{ inputs.os }}-${{ inputs.arch }}
24+
path: compiled-artifacts/
25+
26+
- name: Install Golang
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version-file: go.work
30+
31+
- name: Run Go tests in integration test directory
32+
shell: bash
33+
run: |
34+
echo "===> Copy compiled artifact to use in docker images..."
35+
cd compiled-artifacts
36+
tar -xzf bacalhau_*.tar.gz
37+
cp ./bacalhau ../test_integration/common_assets/bacalhau_bin
38+
39+
echo "===> Running tests..."
40+
cd ../test_integration
41+
go test -v -count=1 ./...

.github/workflows/trigger-development-deployment.yaml

-23
This file was deleted.

.gitprecommit/golangci-lint.sh

-3
This file was deleted.

.golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ linters:
6969
- depguard
7070
- dogsled
7171
- errcheck
72-
- exportloopref
72+
- copyloopvar
7373
- funlen
7474
- gochecknoinits
7575
- goconst
@@ -100,7 +100,7 @@ run:
100100
# concurrency: 16
101101
# Timeout for analysis, e.g. 30s, 5m.
102102
# Default: 1m
103-
timeout: 5m
103+
timeout: 10m
104104
# Exit code when at least one issue was found.
105105
# Default: 1
106106
issues-exit-code: 2

buildkite/scripts/lint.sh

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ set -x
66
# NB(forrest/udit): this step needs to be done before linting as without it the code doesn't compile since webuid/build DNE.
77
make build-webui
88

9-
# NB(forrest/udit): linting cannot be done by pre-commit because it doesn't work...
10-
make lint
11-
129
# TODO(forrest/udit): deprecate pre-commit and replace it with the individual steps required to validate the code.
1310
# e.g. modtidy check, credentials check, go fmt, test file header validation.
1411
pre-commit run --show-diff-on-failure --color=always --all-files

cmd/util/flags/types.go

-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func (s *ArrayValueFlag[T]) Set(input string) error {
9696
func (s *ArrayValueFlag[T]) String() string {
9797
strs := make([]string, 0, len(*s.value))
9898
for _, spec := range *s.value {
99-
spec := spec
10099
strs = append(strs, s.stringer(&spec))
101100
}
102101
return strings.Join(strs, ", ")
@@ -152,7 +151,6 @@ func (s *MapValueFlag[K, V]) Set(input string) error {
152151
func (s *MapValueFlag[K, V]) String() string {
153152
strs := make([]string, len(*s.value))
154153
for key, value := range *s.value {
155-
key, value := key, value
156154
strs = append(strs, s.stringer(&key, &value))
157155
}
158156
return strings.Join(strs, ", ")

pkg/executor/results.go

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ func WriteJobResults(
139139

140140
wg := multierrgroup.Group{}
141141
for _, output := range outputs {
142-
output := output
143142
wg.Go(func() error {
144143
return writeOutputResult(resultsDir, output)
145144
})

pkg/test/scenario/results.go

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func ManyChecks(checks ...CheckResults) CheckResults {
132132
return func(resultsDir string) error {
133133
var wg multierrgroup.Group
134134
for _, check := range checks {
135-
check := check
136135
wg.Go(func() error { return check(resultsDir) })
137136
}
138137
return wg.Wait()

test_integration/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ Then:
3838

3939
```shell
4040
cd test_integration
41-
go test -v -count=1 ./...
41+
./run_locally.sh
4242
```

0 commit comments

Comments
 (0)