Skip to content

Commit c30ca4d

Browse files
authored
Merge pull request #16398 from github/redsun82/go-make
Go: update `make` and CI to use `bazel`
2 parents 0d814e0 + e359744 commit c30ca4d

File tree

4 files changed

+91
-191
lines changed

4 files changed

+91
-191
lines changed

.github/workflows/go-tests-other-os.yml

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77
- .github/workflows/go-tests-other-os.yml
88
- .github/actions/**
99
- codeql-workspace.yml
10-
env:
11-
GO_VERSION: '~1.22.0'
1210

1311
permissions:
1412
contents: read
@@ -18,72 +16,17 @@ jobs:
1816
name: Test MacOS
1917
runs-on: macos-latest
2018
steps:
21-
- name: Set up Go ${{ env.GO_VERSION }}
22-
uses: actions/setup-go@v5
23-
with:
24-
go-version: ${{ env.GO_VERSION }}
25-
cache: false
26-
id: go
27-
2819
- name: Check out code
2920
uses: actions/checkout@v4
30-
31-
- name: Set up CodeQL CLI
32-
uses: ./.github/actions/fetch-codeql
33-
34-
- name: Enable problem matchers in repository
35-
shell: bash
36-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
37-
38-
- name: Build
39-
run: |
40-
cd go
41-
make
42-
43-
- name: Cache compilation cache
44-
id: query-cache
45-
uses: ./.github/actions/cache-query-compilation
46-
with:
47-
key: go-qltest
48-
- name: Test
49-
run: |
50-
cd go
51-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
21+
- name: Run tests
22+
uses: ./go/actions/test
5223

5324
test-win:
5425
if: github.repository_owner == 'github'
5526
name: Test Windows
5627
runs-on: windows-latest-xl
5728
steps:
58-
- name: Set up Go ${{ env.GO_VERSION }}
59-
uses: actions/setup-go@v5
60-
with:
61-
go-version: ${{ env.GO_VERSION }}
62-
cache: false
63-
id: go
64-
6529
- name: Check out code
6630
uses: actions/checkout@v4
67-
68-
- name: Set up CodeQL CLI
69-
uses: ./.github/actions/fetch-codeql
70-
71-
- name: Enable problem matchers in repository
72-
shell: bash
73-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
74-
75-
- name: Build
76-
run: |
77-
cd go
78-
make
79-
80-
- name: Cache compilation cache
81-
id: query-cache
82-
uses: ./.github/actions/cache-query-compilation
83-
with:
84-
key: go-qltest
85-
86-
- name: Test
87-
run: |
88-
cd go
89-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
31+
- name: Run tests
32+
uses: ./go/actions/test

.github/workflows/go-tests.yml

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ on:
1616
- .github/actions/**
1717
- codeql-workspace.yml
1818

19-
env:
20-
GO_VERSION: '~1.22.0'
21-
2219
permissions:
2320
contents: read
2421

@@ -28,51 +25,9 @@ jobs:
2825
name: Test Linux (Ubuntu)
2926
runs-on: ubuntu-latest-xl
3027
steps:
31-
- name: Set up Go ${{ env.GO_VERSION }}
32-
uses: actions/setup-go@v5
33-
with:
34-
go-version: ${{ env.GO_VERSION }}
35-
cache: false
36-
id: go
37-
3828
- name: Check out code
3929
uses: actions/checkout@v4
40-
41-
- name: Set up CodeQL CLI
42-
uses: ./.github/actions/fetch-codeql
43-
44-
- name: Enable problem matchers in repository
45-
shell: bash
46-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
47-
48-
- name: Build
49-
run: |
50-
cd go
51-
make
52-
53-
- name: Check that all Go code is autoformatted
54-
run: |
55-
cd go
56-
make check-formatting
57-
58-
- name: Compile qhelp files to markdown
59-
run: |
60-
cd go
61-
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown
62-
63-
- name: Upload qhelp markdown
64-
uses: actions/upload-artifact@v3
30+
- name: Run tests
31+
uses: ./go/actions/test
6532
with:
66-
name: qhelp-markdown
67-
path: go/qhelp-out/**/*.md
68-
69-
- name: Cache compilation cache
70-
id: query-cache
71-
uses: ./.github/actions/cache-query-compilation
72-
with:
73-
key: go-qltest
74-
75-
- name: Test
76-
run: |
77-
cd go
78-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
33+
run-code-checks: true

go/Makefile

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
1-
all: extractor ql/lib/go.dbscheme
2-
3-
ifeq ($(OS),Windows_NT)
4-
EXE = .exe
5-
CODEQL_PLATFORM = win64
6-
else
7-
EXE =
8-
UNAME_S := $(shell uname -s)
9-
ifeq ($(UNAME_S),Linux)
10-
CODEQL_PLATFORM = linux64
11-
endif
12-
ifeq ($(UNAME_S),Darwin)
13-
CODEQL_PLATFORM = osx64
14-
endif
15-
endif
16-
17-
CODEQL_TOOLS = $(addprefix codeql-tools/,autobuild.cmd autobuild.sh baseline-config-empty.json baseline-config-vendor.json configure-baseline.cmd configure-baseline.sh identify-environment.cmd identify-environment.sh index.cmd index.sh pre-finalize.cmd pre-finalize.sh tracing-config.lua)
1+
all: gen extractor
182

193
EXTRACTOR_PACK_OUT = build/codeql-extractor-go
204

21-
BINARIES = go-extractor go-tokenizer go-autobuilder go-build-runner go-bootstrap go-gen-dbscheme
22-
23-
.PHONY: tools tools-codeql tools-codeql-full clean autoformat \
24-
tools-linux64 tools-osx64 tools-win64 check-formatting
5+
.PHONY: extractor gen clean autoformat check-formatting
256

267
clean:
27-
rm -rf tools/bin tools/linux64 tools/osx64 tools/win64 tools/net tools/opencsv
288
rm -rf $(EXTRACTOR_PACK_OUT) build/stats build/testdb
299

3010
autoformat:
@@ -47,66 +27,11 @@ endif
4727
qhelp-to-markdown:
4828
scripts/qhelp-to-markdown.sh ql/src "$(QHELP_OUT_DIR)"
4929

50-
tools: tools-codeql tools/tokenizer.jar
51-
52-
.PHONY: $(addsuffix $(EXE),$(addprefix tools/bin/,$(BINARIES)))
53-
$(addsuffix $(EXE),$(addprefix tools/bin/,$(BINARIES))):
54-
go build -C extractor -mod=vendor -o ../$@ ./cli/$(basename $(@F))
55-
56-
tools-codeql: tools-$(CODEQL_PLATFORM)
57-
58-
tools-codeql-full: tools-linux64 tools-osx64 tools-win64
59-
60-
tools-linux64: $(addprefix tools/linux64/,$(BINARIES))
61-
62-
.PHONY: $(addprefix tools/linux64/,$(BINARIES))
63-
$(addprefix tools/linux64/,$(BINARIES)):
64-
GOOS=linux GOARCH=amd64 go build -C extractor -mod=vendor -o ../$@ ./cli/$(@F)
65-
66-
tools-osx64: $(addprefix tools/osx64/,$(BINARIES))
67-
68-
.PHONY: $(addprefix tools/osx64/,$(BINARIES))
69-
$(addprefix tools/osx64/,$(BINARIES)):
70-
GOOS=darwin GOARCH=amd64 go build -C extractor -mod=vendor -o ../$@.amd64 ./cli/$(@F)
71-
GOOS=darwin GOARCH=arm64 go build -C extractor -mod=vendor -o ../$@.arm64 ./cli/$(@F)
72-
lipo -create $@.amd64 $@.arm64 -output $@
73-
rm $@.amd64 $@.arm64
74-
75-
tools-win64: $(addsuffix .exe,$(addprefix tools/win64/,$(BINARIES)))
76-
77-
.PHONY: $(addsuffix .exe,$(addprefix tools/win64/,$(BINARIES)))
78-
$(addsuffix .exe,$(addprefix tools/win64/,$(BINARIES))):
79-
env GOOS=windows GOARCH=amd64 go build -C extractor -mod=vendor -o ../$@ ./cli/$(basename $(@F))
80-
81-
.PHONY: extractor-common extractor extractor-full
82-
extractor-common: codeql-extractor.yml LICENSE ql/lib/go.dbscheme \
83-
tools/tokenizer.jar $(CODEQL_TOOLS)
84-
rm -rf $(EXTRACTOR_PACK_OUT)
85-
mkdir -p $(EXTRACTOR_PACK_OUT)
86-
cp codeql-extractor.yml LICENSE ql/lib/go.dbscheme ql/lib/go.dbscheme.stats $(EXTRACTOR_PACK_OUT)
87-
mkdir $(EXTRACTOR_PACK_OUT)/tools
88-
cp -r tools/tokenizer.jar $(CODEQL_TOOLS) $(EXTRACTOR_PACK_OUT)/tools
89-
cp -r downgrades $(EXTRACTOR_PACK_OUT)
90-
91-
extractor: extractor-common tools-codeql
92-
cp -r tools/$(CODEQL_PLATFORM) $(EXTRACTOR_PACK_OUT)/tools
93-
94-
extractor-full: extractor-common tools-codeql-full
95-
cp -r $(addprefix tools/,linux64 osx64 win64) $(EXTRACTOR_PACK_OUT)/tools
96-
97-
tools/tokenizer.jar: tools/net/sourceforge/pmd/cpd/GoLanguage.class
98-
jar cf $@ -C tools net
99-
jar uf $@ -C tools opencsv
100-
101-
tools/net/sourceforge/pmd/cpd/GoLanguage.class: extractor/net/sourceforge/pmd/cpd/GoLanguage.java
102-
javac -cp extractor -d tools $<
103-
rm tools/net/sourceforge/pmd/cpd/AbstractLanguage.class
104-
rm tools/net/sourceforge/pmd/cpd/SourceCode.class
105-
rm tools/net/sourceforge/pmd/cpd/TokenEntry.class
106-
rm tools/net/sourceforge/pmd/cpd/Tokenizer.class
30+
extractor:
31+
bazel run :create-extractor-pack
10732

108-
ql/lib/go.dbscheme: tools/$(CODEQL_PLATFORM)/go-gen-dbscheme$(EXE)
109-
$< $@
33+
gen:
34+
bazel run :gen
11035

11136
build/stats/src.stamp:
11237
mkdir -p $(@D)/src
@@ -123,7 +48,7 @@ test: all build/testdb/check-upgrade-path
12348
codeql test run -j0 ql/test --search-path build/codeql-extractor-go --consistency-queries ql/test/consistency --compilation-cache=$(cache)
12449
# use GOOS=linux because GOOS=darwin GOARCH=386 is no longer supported
12550
env GOOS=linux GOARCH=386 codeql$(EXE) test run -j0 ql/test/query-tests/Security/CWE-681 --search-path build/codeql-extractor-go --consistency-queries ql/test/consistency --compilation-cache=$(cache)
126-
cd extractor; go test -mod=vendor ./...
51+
cd extractor; bazel test ...
12752
bash extractor-smoke-test/test.sh || (echo "Extractor smoke test FAILED"; exit 1)
12853

12954
.PHONY: build/testdb/check-upgrade-path

go/actions/test/action.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Test Go extractor
2+
description: Run build, QL tests, and optionally basic code sanity checks (formatting and generated code) for the Go extractor
3+
inputs:
4+
go-test-version:
5+
description: Which Go version to use for running the tests
6+
required: false
7+
default: ~1.22.0
8+
run-code-checks:
9+
description: Whether to run formatting, code and qhelp generation checks
10+
required: false
11+
default: false
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Set up Go ${{ inputs.go-test-version }}
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: ${{ inputs.go-test-version }}
19+
cache: false
20+
id: go
21+
22+
- name: Set up CodeQL CLI
23+
uses: ./.github/actions/fetch-codeql
24+
25+
- name: Enable problem matchers in repository
26+
shell: bash
27+
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
28+
29+
- name: Check checked-in generated code
30+
if: inputs.run-code-checks == 'true'
31+
shell: bash
32+
run: |
33+
bazel run go:gen
34+
git add .
35+
git diff --exit-code HEAD || (
36+
echo "please run bazel run //go:gen"
37+
exit 1
38+
)
39+
40+
- name: Build
41+
shell: bash
42+
run: |
43+
bazel run go:create-extractor-pack
44+
45+
- name: Check that all Go code is autoformatted
46+
if: inputs.run-code-checks == 'true' && !cancelled()
47+
shell: bash
48+
run: |
49+
cd go
50+
make check-formatting
51+
52+
- name: Compile qhelp files to markdown
53+
if: inputs.run-code-checks == 'true' && !cancelled()
54+
id: markdown
55+
shell: bash
56+
run: |
57+
cd go
58+
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown
59+
60+
- name: Upload qhelp markdown
61+
if: inputs.run-code-checks == 'true' && !cancelled()
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: qhelp-markdown
65+
path: go/qhelp-out/**/*.md
66+
67+
- name: Cache compilation cache
68+
id: query-cache
69+
uses: ./.github/actions/cache-query-compilation
70+
with:
71+
key: go-qltest
72+
73+
- name: Test
74+
shell: bash
75+
run: |
76+
cd go
77+
make test cache="${{ steps.query-cache.outputs.cache-dir }}"

0 commit comments

Comments
 (0)