Compare commits

...

5 Commits

Author SHA1 Message Date
Michael B. Gale
e4458cf9a8 Revert to using workflow_call 2024-07-15 14:08:46 +01:00
Michael B. Gale
7ed1a78ba5 Create and merge PR for Bazel files 2024-07-15 14:00:32 +01:00
Michael B. Gale
8ff58885d1 Dispatch workflow instead of calling it 2024-07-09 13:35:21 +01:00
Michael B. Gale
a6a2f05aa5 Go: Dispatch test workflows from common prepare workflow 2024-07-08 16:15:19 +01:00
Michael B. Gale
47e476c078 Go: Rename go-tests workflow to go-tests-linux 2024-07-08 14:14:14 +01:00
3 changed files with 152 additions and 20 deletions

26
.github/workflows/go-tests-linux.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: "Go: Run Tests"
on:
workflow_dispatch:
workflow_call:
inputs:
ref:
required: true
type: string
permissions:
contents: read
jobs:
test-linux:
if: github.repository_owner == 'github'
name: Test Linux (Ubuntu)
runs-on: ubuntu-latest-xl
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Run tests
uses: ./go/actions/test
with:
run-code-checks: true

View File

@@ -1,15 +1,11 @@
name: "Go: Run Tests - Other OS"
on:
pull_request:
paths:
- "go/**"
- "!go/ql/**" # don't run other-os if only ql/ files changed
- .github/workflows/go-tests-other-os.yml
- .github/actions/**
- codeql-workspace.yml
- MODULE.bazel
- .bazelrc
- misc/bazel/**
workflow_dispatch:
workflow_call:
inputs:
ref:
required: true
type: string
permissions:
contents: read
@@ -21,6 +17,8 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Run tests
uses: ./go/actions/test
@@ -31,5 +29,7 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Run tests
uses: ./go/actions/test

View File

@@ -1,9 +1,11 @@
name: "Go: Run Tests"
name: "Go: Prepare Tests"
on:
push:
paths:
- "go/**"
- .github/workflows/go-tests.yml
- .github/workflows/go-tests-linux.yml
- .github/workflows/go-tests-other-os.yml
- .github/actions/**
- codeql-workspace.yml
branches:
@@ -13,24 +15,128 @@ on:
paths:
- "go/**"
- .github/workflows/go-tests.yml
- .github/workflows/go-tests-linux.yml
- .github/workflows/go-tests-other-os.yml
- .github/actions/**
- codeql-workspace.yml
- MODULE.bazel
- .bazelrc
- misc/bazel/**
permissions:
contents: read
jobs:
test-linux:
prepare-go-tests:
if: github.repository_owner == 'github'
name: Test Linux (Ubuntu)
runs-on: ubuntu-latest-xl
name: "Prepare tests"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
# Skip tests for this workflow run if we just created a new commit/PR to run the
# tests on.
skipTests: ${{ steps.push-bazel-files.outputs.SKIP_TESTS }}
# We don't want to run macOS/Windows workflows if only .ql files have changed
onlyQL: ${{ steps.only-ql-check.outputs.ONLY_QL_CHANGES }}
steps:
- name: Print information about the workflow
shell: bash
run: |
echo $GITHUB_CONTEXT
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Check out code
uses: actions/checkout@v4
- name: Run tests
uses: ./go/actions/test
with:
run-code-checks: true
# For PRs, this ensures that we do not end up in a detached HEAD state;
# For pushes, this does not change anything.
# We require this to be able to easily push changes, if needed.
ref: ${{ github.event.pull_request.head.ref || '' }}
# We need HEAD^ to determine the list of changed files
fetch-depth: 2
# Determine whether only .ql files changed: if so, we won't run the macOS and Windows workflows
- name: Determine whether only .ql files changed
id: only-ql-check
shell: bash
run: |
CHANGES=$(git diff --name-only HEAD^)
echo $CHANGES
ONLY_QL_CHANGES=true
for change in $(git diff --name-only HEAD^)
do
if [[ $change != go/ql/* ]];
then
ONLY_QL_CHANGES=false
echo "Files other than .ql files have changed"
break
fi
done
echo "Setting ONLY_QL_CHANGES to $ONLY_QL_CHANGES"
echo "ONLY_QL_CHANGES=$ONLY_QL_CHANGES" >> $GITHUB_OUTPUT
# Dependabot will nuke Bazel build files when it updates Go dependencies;
# this will restore them
- name: Regenerate Bazel files for Dependabot PR
if: github.event.pull_request.user.login == 'dependabot[bot]'
shell: bash
run: |
bazel run //go:gazelle
bazel run //go:gen
# And this will push the Bazel files to the PR branch
- name: Push Bazel files for Dependabot PR
id: push-bazel-files
if: github.event.pull_request.user.login == 'dependabot[bot]'
shell: bash
run: |
git add go/extractor/vendor/**
if git diff --exit-code HEAD;
then
echo "Regenerate Bazel files resulted in no changes"
else
BAZEL_BRANCH_NAME="${{ github.head_ref }}/bazel"
echo "Pushing regenerated Bazel files to $BAZEL_BRANCH_NAME"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m 'Regenerate Bazel build files for Dependabot PR'
git checkout -b "$BAZEL_BRANCH_NAME"
git push -u origin "$BAZEL_BRANCH_NAME"
echo "Creating PR for $BAZEL_BRANCH_NAME"
gh pr create -B "${{ github.head_ref }}" -H "$BAZEL_BRANCH_NAME" \
--title "Go: Regenerate Bazel files for Dependabot PR" \
--body "Created automatically to update Bazel build files for a Dependabot PR"
echo "Merging PR by pushing to ${{ github.head_ref }}"
git checkout "${{ github.head_ref }}"
git push
fi
echo "SKIP_TESTS=true" >> $GITHUB_OUTPUT
run-linux-tests:
name: "Run Linux tests"
if: needs.prepare-go-tests.outputs.skipTests != 'true'
needs:
- prepare-go-tests
uses: ./.github/workflows/go-tests-linux.yml
secrets: inherit
with:
ref: ${{ github.head_ref || github.ref_name }}
run-other-os-tests:
name: "Run other OS tests"
# Only run this workflow for PRs and only if something other than .ql files changed
if: github.event_name == 'pull_request' && needs.prepare-go-tests.outputs.skipTests != 'true' && !(needs.prepare-go-tests.outputs.onlyQL == 'true')
needs:
- prepare-go-tests
uses: ./.github/workflows/go-tests-other-os.yml
secrets: inherit
with:
ref: ${{ github.head_ref }}