mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Go: refactor workflows with shared action
This commit is contained in:
57
.github/workflows/go-tests-other-os.yml
vendored
57
.github/workflows/go-tests-other-os.yml
vendored
@@ -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
.github/workflows/go-tests.yml
vendored
64
.github/workflows/go-tests.yml
vendored
@@ -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
go/actions/test/action.yml
Normal file
80
go/actions/test/action.yml
Normal file
@@ -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 }}"
|
||||
Reference in New Issue
Block a user