Skip to content

Commit 12662ad

Browse files
authored
Merge pull request #3 from mortenmj/mmj/bazel
Set up Bazel build for the backend
2 parents 39b5a7b + b5481ae commit 12662ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+6029
-9
lines changed

.bazelignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bazel-demo
2+
third_party/bazel/_generate-via-bazel

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run --workspace_status_command="bash tools/workspace-status.sh"

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.2.0

.github/workflows/master.yaml

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
{
2+
"jobs": {
3+
"build_and_test": {
4+
"runs-on": "ubuntu-latest",
5+
"steps": [
6+
{
7+
"name": "Check out source code",
8+
"uses": "actions/checkout@v1"
9+
},
10+
{
11+
"name": "Installing Bazel",
12+
"run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
13+
},
14+
{
15+
"name": "Bazel mod tidy",
16+
"run": "bazel mod tidy"
17+
},
18+
{
19+
"name": "Gazelle",
20+
"run": "rm -f $(find . -name '*.pb.go' | sed -e 's/[^/]*$/BUILD.bazel/') && bazel run //:gazelle"
21+
},
22+
{
23+
"name": "Buildifier",
24+
"run": "bazel run @com_github_bazelbuild_buildtools//:buildifier"
25+
},
26+
{
27+
"name": "Gofmt",
28+
"run": "bazel run @cc_mvdan_gofumpt//:gofumpt -- -w -extra $(pwd)"
29+
},
30+
{
31+
"name": "Clang format",
32+
"run": "find . -name '*.proto' -exec bazel run @llvm_toolchain_llvm//:bin/clang-format -- -i {} +"
33+
},
34+
{
35+
"name": "GitHub workflows",
36+
"run": "bazel build //tools/github_workflows && cp bazel-bin/tools/github_workflows/*.yaml .github/workflows"
37+
},
38+
{
39+
"name": "Protobuf generation",
40+
"run": "find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\nbazel build $(bazel query --output=label 'kind(\"go_proto_library\", //...)')\nfind bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\ndone\n"
41+
},
42+
{
43+
"name": "Embedded asset generation",
44+
"run": "bazel build $(git grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |//\\1:|' | sort -u)\ngit grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |\\1/|' | while read o; do\n if [ -e \"bazel-bin/$o\" ]; then\n rm -rf \"$o\"\n cp -r \"bazel-bin/$o\" \"$o\"\n find \"$o\" -type f -exec chmod -x {} +\n fi\ndone\n"
45+
},
46+
{
47+
"name": "Test style conformance",
48+
"run": "git add . && git diff --exit-code HEAD --"
49+
},
50+
{
51+
"name": "Golint",
52+
"run": "bazel run @org_golang_x_lint//golint -- -set_exit_status $(pwd)/..."
53+
},
54+
{
55+
"name": "linux_amd64: build and test",
56+
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_amd64 //..."
57+
},
58+
{
59+
"name": "linux_amd64: copy bb_portal",
60+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_amd64 //cmd/bb_portal $(pwd)/bb_portal"
61+
},
62+
{
63+
"name": "linux_amd64: upload bb_portal",
64+
"uses": "actions/upload-artifact@v4",
65+
"with": {
66+
"name": "bb_portal.linux_amd64",
67+
"path": "bb_portal"
68+
}
69+
},
70+
{
71+
"name": "linux_386: build and test",
72+
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_386 //..."
73+
},
74+
{
75+
"name": "linux_386: copy bb_portal",
76+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_386 //cmd/bb_portal $(pwd)/bb_portal"
77+
},
78+
{
79+
"name": "linux_386: upload bb_portal",
80+
"uses": "actions/upload-artifact@v4",
81+
"with": {
82+
"name": "bb_portal.linux_386",
83+
"path": "bb_portal"
84+
}
85+
},
86+
{
87+
"name": "linux_arm: build and test",
88+
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm //..."
89+
},
90+
{
91+
"name": "linux_arm: copy bb_portal",
92+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_arm //cmd/bb_portal $(pwd)/bb_portal"
93+
},
94+
{
95+
"name": "linux_arm: upload bb_portal",
96+
"uses": "actions/upload-artifact@v4",
97+
"with": {
98+
"name": "bb_portal.linux_arm",
99+
"path": "bb_portal"
100+
}
101+
},
102+
{
103+
"name": "linux_arm64: build and test",
104+
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm64 //..."
105+
},
106+
{
107+
"name": "linux_arm64: copy bb_portal",
108+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_arm64 //cmd/bb_portal $(pwd)/bb_portal"
109+
},
110+
{
111+
"name": "linux_arm64: upload bb_portal",
112+
"uses": "actions/upload-artifact@v4",
113+
"with": {
114+
"name": "bb_portal.linux_arm64",
115+
"path": "bb_portal"
116+
}
117+
},
118+
{
119+
"name": "darwin_amd64: build and test",
120+
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_amd64 //..."
121+
},
122+
{
123+
"name": "darwin_amd64: copy bb_portal",
124+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:darwin_amd64 //cmd/bb_portal $(pwd)/bb_portal"
125+
},
126+
{
127+
"name": "darwin_amd64: upload bb_portal",
128+
"uses": "actions/upload-artifact@v4",
129+
"with": {
130+
"name": "bb_portal.darwin_amd64",
131+
"path": "bb_portal"
132+
}
133+
},
134+
{
135+
"name": "darwin_arm64: build and test",
136+
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_arm64 //..."
137+
},
138+
{
139+
"name": "darwin_arm64: copy bb_portal",
140+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:darwin_arm64 //cmd/bb_portal $(pwd)/bb_portal"
141+
},
142+
{
143+
"name": "darwin_arm64: upload bb_portal",
144+
"uses": "actions/upload-artifact@v4",
145+
"with": {
146+
"name": "bb_portal.darwin_arm64",
147+
"path": "bb_portal"
148+
}
149+
},
150+
{
151+
"name": "freebsd_amd64: build and test",
152+
"run": "bazel build --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_portal"
153+
},
154+
{
155+
"name": "freebsd_amd64: copy bb_portal",
156+
"run": "rm -f bb_portal && bazel run --run_under cp --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_portal $(pwd)/bb_portal"
157+
},
158+
{
159+
"name": "freebsd_amd64: upload bb_portal",
160+
"uses": "actions/upload-artifact@v4",
161+
"with": {
162+
"name": "bb_portal.freebsd_amd64",
163+
"path": "bb_portal"
164+
}
165+
},
166+
{
167+
"name": "windows_amd64: build and test",
168+
"run": "bazel build --platforms=@rules_go//go/toolchain:windows_amd64 //..."
169+
},
170+
{
171+
"name": "windows_amd64: copy bb_portal",
172+
"run": "rm -f bb_portal.exe && bazel run --run_under cp --platforms=@rules_go//go/toolchain:windows_amd64 //cmd/bb_portal $(pwd)/bb_portal.exe"
173+
},
174+
{
175+
"name": "windows_amd64: upload bb_portal",
176+
"uses": "actions/upload-artifact@v4",
177+
"with": {
178+
"name": "bb_portal.windows_amd64",
179+
"path": "bb_portal.exe"
180+
}
181+
},
182+
{
183+
"env": {
184+
"GITHUB_TOKEN": "${{ secrets.GITHUB_TOKEN }}"
185+
},
186+
"name": "Install Docker credentials",
187+
"run": "echo \"${GITHUB_TOKEN}\" | docker login ghcr.io -u $ --password-stdin"
188+
},
189+
{
190+
"name": "Push container bb_portal:bb_portal",
191+
"run": "bazel run --stamp //cmd/bb_portal:bb_portal_container_push"
192+
}
193+
]
194+
}
195+
},
196+
"name": "master",
197+
"on": {
198+
"push": {
199+
"branches": [
200+
"master"
201+
]
202+
}
203+
}
204+
}

.github/workflows/pull-requests.yaml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"jobs": {
3+
"build_and_test": {
4+
"runs-on": "ubuntu-latest",
5+
"steps": [
6+
{
7+
"name": "Check out source code",
8+
"uses": "actions/checkout@v1"
9+
},
10+
{
11+
"name": "Installing Bazel",
12+
"run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
13+
},
14+
{
15+
"name": "Bazel mod tidy",
16+
"run": "bazel mod tidy"
17+
},
18+
{
19+
"name": "Gazelle",
20+
"run": "rm -f $(find . -name '*.pb.go' | sed -e 's/[^/]*$/BUILD.bazel/') && bazel run //:gazelle"
21+
},
22+
{
23+
"name": "Buildifier",
24+
"run": "bazel run @com_github_bazelbuild_buildtools//:buildifier"
25+
},
26+
{
27+
"name": "Gofmt",
28+
"run": "bazel run @cc_mvdan_gofumpt//:gofumpt -- -w -extra $(pwd)"
29+
},
30+
{
31+
"name": "Clang format",
32+
"run": "find . -name '*.proto' -exec bazel run @llvm_toolchain_llvm//:bin/clang-format -- -i {} +"
33+
},
34+
{
35+
"name": "GitHub workflows",
36+
"run": "bazel build //tools/github_workflows && cp bazel-bin/tools/github_workflows/*.yaml .github/workflows"
37+
},
38+
{
39+
"name": "Protobuf generation",
40+
"run": "find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\nbazel build $(bazel query --output=label 'kind(\"go_proto_library\", //...)')\nfind bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\ndone\n"
41+
},
42+
{
43+
"name": "Embedded asset generation",
44+
"run": "bazel build $(git grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |//\\1:|' | sort -u)\ngit grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |\\1/|' | while read o; do\n if [ -e \"bazel-bin/$o\" ]; then\n rm -rf \"$o\"\n cp -r \"bazel-bin/$o\" \"$o\"\n find \"$o\" -type f -exec chmod -x {} +\n fi\ndone\n"
45+
},
46+
{
47+
"name": "Test style conformance",
48+
"run": "git add . && git diff --exit-code HEAD --"
49+
},
50+
{
51+
"name": "Golint",
52+
"run": "bazel run @org_golang_x_lint//golint -- -set_exit_status $(pwd)/..."
53+
},
54+
{
55+
"name": "linux_amd64: build and test",
56+
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_amd64 //..."
57+
},
58+
{
59+
"name": "linux_386: build and test",
60+
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_386 //..."
61+
},
62+
{
63+
"name": "linux_arm: build and test",
64+
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm //..."
65+
},
66+
{
67+
"name": "linux_arm64: build and test",
68+
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm64 //..."
69+
},
70+
{
71+
"name": "darwin_amd64: build and test",
72+
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_amd64 //..."
73+
},
74+
{
75+
"name": "darwin_arm64: build and test",
76+
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_arm64 //..."
77+
},
78+
{
79+
"name": "freebsd_amd64: build and test",
80+
"run": "bazel build --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_portal"
81+
},
82+
{
83+
"name": "windows_amd64: build and test",
84+
"run": "bazel build --platforms=@rules_go//go/toolchain:windows_amd64 //..."
85+
}
86+
]
87+
}
88+
},
89+
"name": "pull-requests",
90+
"on": {
91+
"pull_request": {
92+
"branches": [
93+
"master"
94+
]
95+
}
96+
}
97+
}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ buildportal.db*
33
bep-files/
44
blob-archive/
55

6+
bazel-*
7+
!bazel-demo/
68
bazel-demo/bazel-*
79
bazel-demo/*.ndjson

BUILD.bazel

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# gazelle:ignore
2+
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
3+
load("@gazelle//:def.bzl", "gazelle")
4+
5+
# gazelle:prefix github.com/buildbarn/bb-portal
6+
gazelle(
7+
name = "gazelle",
8+
)
9+
10+
buildifier(
11+
name = "buildifier",
12+
)

0 commit comments

Comments
 (0)