Skip to content

Commit

Permalink
Go: refactor workflows with shared action
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed Apr 29, 2024
1 parent 6ec223c commit 2f6dd2a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 104 deletions.
57 changes: 14 additions & 43 deletions .github/workflows/go-tests-other-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,21 @@ permissions:
contents: read

jobs:
test:
name: Test
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest-xl]
if: matrix.os == 'macos-latest' || github.repository_owner == 'github'
runs-on: ${{ matrix.os }}
test-mac:
name: Test MacOS
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Run tests
uses: ./go/actions/test

- name: Get go version
shell: bash
run: |
(
echo -n "GO_VERSION="
bazel run @rules_go//go -- version | sed 's/go version go\(\S*\) .*/\1/'
) | tee -a "$GITHUB_ENV"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
id: go

- name: Set up CodeQL CLI
uses: ./.github/actions/fetch-codeql

- name: Enable problem matchers in repository
shell: bash
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'

- name: Build
run: |
bazel run //go:create-extractor-pack
- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: go-qltest
- name: Test
run: |
cd go
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
test-win:
if: github.repository_owner == 'github'
name: Test Windows
runs-on: windows-latest-xl
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Run tests
uses: ./go/actions/test
64 changes: 3 additions & 61 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,7 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Get go version
shell: bash
run: |
(
echo -n "GO_VERSION="
bazel run @rules_go//go -- version | sed 's/go version go\(\S*\) .*/\1/'
) | tee -a "$GITHUB_ENV"
- name: Set up Go
uses: actions/setup-go@v5
- name: Run tests
uses: ./go/actions/test
with:
go-version: ${{ env.GO_VERSION }}
cache: false
id: go

- name: Set up CodeQL CLI
uses: ./.github/actions/fetch-codeql

- name: Enable problem matchers in repository
shell: bash
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'

- name: Build
run: |
bazel run //go:create-extractor-pack
- name: Check that all Go code is autoformatted
run: |
cd go
make check-formatting
- name: Check checked-in generated code
run: |
bazel run //go:gen
git add .
git diff --exit-code HEAD || (
echo "please run bazel run //go:gen"
exit 1
)
- name: Compile qhelp files to markdown
run: |
cd go
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown
- name: Upload qhelp markdown
uses: actions/upload-artifact@v3
with:
name: qhelp-markdown
path: go/qhelp-out/**/*.md

- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: go-qltest

- name: Test
run: |
cd go
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
run-code-checks: true
80 changes: 80 additions & 0 deletions go/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Test go extractor
description: Run build, QL tests and optionally basic code sanity checks (formatting and generation)
inputs:
run-code-checks:
description: Whether to run formatting, code and qhelp generation checks
required: false
default: false
runs:
using: composite
steps:
- name: Get go version
shell: bash
run: |
(
echo -n "GO_VERSION="
bazel run @rules_go//go -- version | sed 's/go version go\(\S*\) .*/\1/'
) | tee -a "$GITHUB_ENV"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
id: go

- name: Set up CodeQL CLI
uses: ./.github/actions/fetch-codeql

- name: Enable problem matchers in repository
shell: bash
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'

- name: Build
shell: bash
run: |
bazel run //go:create-extractor-pack
- name: Check that all Go code is autoformatted
if: inputs.run-code-checks == 'true'
shell: bash
run: |
cd go
make check-formatting
- name: Check checked-in generated code
if: inputs.run-code-checks == 'true'
shell: bash
run: |
bazel run //go:gen
git add .
git diff --exit-code HEAD || (
echo "please run bazel run //go:gen"
exit 1
)
- name: Compile qhelp files to markdown
if: inputs.run-code-checks == 'true'
shell: bash
run: |
cd go
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown
- name: Upload qhelp markdown
if: inputs.run-code-checks == 'true'
uses: actions/upload-artifact@v3
with:
name: qhelp-markdown
path: go/qhelp-out/**/*.md

- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: go-qltest

- name: Test
shell: bash
run: |
cd go
make test cache="${{ steps.query-cache.outputs.cache-dir }}"

0 comments on commit 2f6dd2a

Please sign in to comment.