From 2f6dd2ab819c59425a4c636cdb65930d6c6405fb Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 29 Apr 2024 11:11:23 +0200 Subject: [PATCH] Go: refactor workflows with shared action --- .github/workflows/go-tests-other-os.yml | 57 +++++------------- .github/workflows/go-tests.yml | 64 +------------------- go/actions/test/action.yml | 80 +++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 104 deletions(-) create mode 100644 go/actions/test/action.yml diff --git a/.github/workflows/go-tests-other-os.yml b/.github/workflows/go-tests-other-os.yml index ba3dd0335ad4..9915b0869db7 100644 --- a/.github/workflows/go-tests-other-os.yml +++ b/.github/workflows/go-tests-other-os.yml @@ -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 diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 5c9204f8405f..63e2b7c49740 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -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 diff --git a/go/actions/test/action.yml b/go/actions/test/action.yml new file mode 100644 index 000000000000..f9bdee5fe0c0 --- /dev/null +++ b/go/actions/test/action.yml @@ -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 }}"