Skip to content

Commit 2f6dd2a

Browse files
committed
Go: refactor workflows with shared action
1 parent 6ec223c commit 2f6dd2a

File tree

3 files changed

+97
-104
lines changed

3 files changed

+97
-104
lines changed

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

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,21 @@ permissions:
1212
contents: read
1313

1414
jobs:
15-
test:
16-
name: Test
17-
strategy:
18-
fail-fast: false
19-
matrix:
20-
os: [macos-latest, windows-latest-xl]
21-
if: matrix.os == 'macos-latest' || github.repository_owner == 'github'
22-
runs-on: ${{ matrix.os }}
15+
test-mac:
16+
name: Test MacOS
17+
runs-on: macos-latest
2318
steps:
2419
- name: Check out code
2520
uses: actions/checkout@v4
21+
- name: Run tests
22+
uses: ./go/actions/test
2623

27-
- name: Get go version
28-
shell: bash
29-
run: |
30-
(
31-
echo -n "GO_VERSION="
32-
bazel run @rules_go//go -- version | sed 's/go version go\(\S*\) .*/\1/'
33-
) | tee -a "$GITHUB_ENV"
34-
35-
- name: Set up Go
36-
uses: actions/setup-go@v5
37-
with:
38-
go-version: ${{ env.GO_VERSION }}
39-
cache: false
40-
id: go
41-
42-
- name: Set up CodeQL CLI
43-
uses: ./.github/actions/fetch-codeql
44-
45-
- name: Enable problem matchers in repository
46-
shell: bash
47-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
48-
49-
- name: Build
50-
run: |
51-
bazel run //go:create-extractor-pack
52-
53-
- name: Cache compilation cache
54-
id: query-cache
55-
uses: ./.github/actions/cache-query-compilation
56-
with:
57-
key: go-qltest
58-
- name: Test
59-
run: |
60-
cd go
61-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
24+
test-win:
25+
if: github.repository_owner == 'github'
26+
name: Test Windows
27+
runs-on: windows-latest-xl
28+
steps:
29+
- name: Check out code
30+
uses: actions/checkout@v4
31+
- name: Run tests
32+
uses: ./go/actions/test

.github/workflows/go-tests.yml

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,7 @@ jobs:
2727
steps:
2828
- name: Check out code
2929
uses: actions/checkout@v4
30-
31-
- name: Get go version
32-
shell: bash
33-
run: |
34-
(
35-
echo -n "GO_VERSION="
36-
bazel run @rules_go//go -- version | sed 's/go version go\(\S*\) .*/\1/'
37-
) | tee -a "$GITHUB_ENV"
38-
39-
- name: Set up Go
40-
uses: actions/setup-go@v5
30+
- name: Run tests
31+
uses: ./go/actions/test
4132
with:
42-
go-version: ${{ env.GO_VERSION }}
43-
cache: false
44-
id: go
45-
46-
- name: Set up CodeQL CLI
47-
uses: ./.github/actions/fetch-codeql
48-
49-
- name: Enable problem matchers in repository
50-
shell: bash
51-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
52-
53-
- name: Build
54-
run: |
55-
bazel run //go:create-extractor-pack
56-
57-
- name: Check that all Go code is autoformatted
58-
run: |
59-
cd go
60-
make check-formatting
61-
62-
- name: Check checked-in generated code
63-
run: |
64-
bazel run //go:gen
65-
git add .
66-
git diff --exit-code HEAD || (
67-
echo "please run bazel run //go:gen"
68-
exit 1
69-
)
70-
71-
- name: Compile qhelp files to markdown
72-
run: |
73-
cd go
74-
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown
75-
76-
- name: Upload qhelp markdown
77-
uses: actions/upload-artifact@v3
78-
with:
79-
name: qhelp-markdown
80-
path: go/qhelp-out/**/*.md
81-
82-
- name: Cache compilation cache
83-
id: query-cache
84-
uses: ./.github/actions/cache-query-compilation
85-
with:
86-
key: go-qltest
87-
88-
- name: Test
89-
run: |
90-
cd go
91-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
33+
run-code-checks: true

go/actions/test/action.yml

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

0 commit comments

Comments
 (0)