Chore: Migrate backend testing from drone to gha (#100765)

* baldm0mma/ add gha workflow

* baldm0mma/ add codeowners

* baldm0mma/ update health command

* baldm0mma/ update aliases for services

* baldm0mma/ rewrite migration attempt

* baldm0mma/ fix package names for ubuntu

* baldm0mma/ add authentication

* baldm0mma/ update auth

* baldm0mma/ add debugs

* baldm0mma/ add continue on error

* baldm0mma/ simplyfy ent fork logic

* baldm0mma/ debug fork status

* baldm0mma/ add debug workflow for enterprise access

* chore: add workflow_dispatch trigger to backend test workflow

* baldm0mma/ debug ent run

* baldm0mma/ add more robust debugging info

* baldm0mma/ use old drone ci app for testing

* baldm0mma/ update app name

* baldm0mma/ update workflow creds

* baldm0mma/ rename

* baldm0mma/ update codeownders

* baldm0mma/ update paths to ignore paths for docs and markdown files

* baldm0mma/ create 'Setup Grafana Enterprise' action and remove from current workflow

* baldm0mma/ fail at git clone

* baldm0mma/ absract away "Run backend tests" and "Run backend integration tests" into their own actions

* baldm0mma/ update directory strcuture to adhere to GHAs best practices

* baldm0mma/ remove optional configs

* baldm0mma/ update codeowners

* baldm0mma/ update gh app name

* baldm0mma/ remove circ dep

* baldm0mma/ uncomment out enterprise setup for test

* baldm0mma/ update valut url

* baldm0mma/ use vault instance rather than url

* baldm0mma/ debug

* baldm0mma/ Removed the multiline string format

* baldm0mma/ add installation key

* baldm0mma/ update path

* baldm0mma/ debug vault access

* baldm0mma/ add ent

* baldm0mma/ remove debugging

* baldm0mma/ update paths

* baldm0mma/ update codeowners

* baldm0mma/ update paths and codeowners

* baldm0mma/ add continue-on-error to assure the workflow isn't blocking

* baldm0mma/ simplify test action execution

* baldm0mma/ remove wire install step

* baldm0mma/ add conditions for coverage output

* baldm0mma/ add conditions for coverage output for integration test action

* baldm0mma/ add report converage file

* baldm0mma/ remove uneeded action

* baldm0mma/ update codeowners

* baldm0mma/ push small change to go file and add log

* baldm0mma/ update trigger conditions

* baldm0mma/ update converage conditions

* baldm0mma/ update Run backend integration tests with correct action

* baldm0mma/ test 2

* baldm0mma/ update with -coverpkg flag

* baldm0mma/ remove backend-coverage as it is now redundant

* baldm0mma/ update codeowners

* baldm0mma/ update test file

* baldm0mma/ update coverage logic
This commit is contained in:
Jev Forsberg
2025-02-28 14:53:17 -07:00
committed by GitHub
parent 2466685a41
commit 6abf0434df
6 changed files with 228 additions and 110 deletions
-109
View File
@@ -1,109 +0,0 @@
name: Backend Coverage (OSS)
on:
push:
paths:
- pkg/**
- .github/workflows/backend-coverage.yml
- go.*
branches:
- main
pull_request:
jobs:
unit-tests:
name: Run unit tests (OSS)
runs-on: ubuntu-latest
if: github.repository == 'grafana/grafana'
steps:
- name: Check out repository
uses: actions/checkout@v4.2.2
- name: Setup Go environment
uses: actions/setup-go@v5.3.0
with:
go-version-file: go.work
- name: Run tests
run: make gen-go test-go-unit
- name: Upload coverage file
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: unit-cov
path: unit.cov
retention-days: 1
compression-level: 9 # this is raw text, and includes a _lot_ of repetition. compressing it should yield pretty good results.
integration-tests:
name: Run integration tests (OSS)
runs-on: ubuntu-latest
if: github.repository == 'grafana/grafana'
steps:
- name: Check out repository
uses: actions/checkout@v4.2.2
- name: Setup Go environment
uses: actions/setup-go@v5.3.0
with:
go-version-file: go.work
- name: Run tests
run: make gen-go test-go-integration
- name: Upload coverage file
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: integration-cov
path: integration.cov
retention-days: 1
compression-level: 9 # this is raw text, and includes a _lot_ of repetition. compressing it should yield pretty good results.
report-coverage:
name: Report coverage from unit and integration tests (OSS)
needs: [unit-tests, integration-tests]
runs-on: ubuntu-latest
# we don't do always() so as to not run even if the workflow is cancelled
if: github.repository == 'grafana/grafana' && (success() || failure())
steps:
- name: Check out repository
uses: actions/checkout@v4.2.2
- name: Setup Go environment
uses: actions/setup-go@v5.3.0
with:
go-version-file: go.work
- name: Generate Go
run: make gen-go
- uses: actions/download-artifact@v4
with:
pattern: '*-cov'
path: .
merge-multiple: true
- name: Join coverage outputs
run: |
cp unit.cov backend.cov
tail -n+2 integration.cov >> backend.cov
- name: Convert coverage info to per-func stats
run: go tool cover -func backend.cov > backend-funcs.log
# The HTML can be useful in some UI to browse the artifacts easily.
- name: Convert coverage info to HTML
run: go tool cover -html backend.cov -o backend.html
- name: Upload coverage file
uses: actions/upload-artifact@v4
with:
name: backend-cov
path: |
backend.cov
backend-funcs.log
backend.html
retention-days: 30
compression-level: 9 # this is raw text, and includes a _lot_ of repetition. compressing it should yield pretty good results.
- name: Delete old coverage files
# This is a community tool, not one provided by GitHub. Hence it shall be pinned to a hash.
# https://github.com/GeekyEggo/delete-artifact/tree/v5
uses: GeekyEggo/delete-artifact@f275313e70c08f6120db482d7a6b98377786765b
with:
name: |
unit-cov
integration-cov
failOnError: false # oh well, we'll just have the extra artifacts...
- name: Set summary to total coverage
# We use single quotes here to disable the bash backtick behaviour of executing commands.
run: |
echo '# Coverage' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
grep 'total:' backend-funcs.log | tr '\t' ' ' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
+106
View File
@@ -0,0 +1,106 @@
name: Test Backend
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- 'docs/**'
- '**/*.md'
pull_request:
paths-ignore:
- 'docs/**'
- '**/*.md'
permissions:
contents: read
id-token: write
env:
EDITION: 'oss'
jobs:
test-backend:
name: Test Backend
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.5'
cache: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential shared-mime-info make
- name: Get runner name
run: echo ${{ runner.name }}
- name: Setup Enterprise (PR only)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: ./.github/actions/setup-enterprise
- name: Verify CUE generation
run: CODEGEN_VERIFY=1 make gen-cue
- name: Verify Jsonnet generation
run: CODEGEN_VERIFY=1 make gen-jsonnet
- name: Check if coverage should be generated
id: check-coverage
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Event: ${{ github.event_name }}"
echo "Ref: ${{ github.ref }}"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "PR changed files:"
files=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[].filename')
echo "$files"
if echo "$files" | grep -E "(pkg/|go\.)"; then
echo "Coverage will be generated: true (PR changes)"
echo "generate=true" >> $GITHUB_OUTPUT
else
echo "Coverage will be generated: false"
echo "generate=false" >> $GITHUB_OUTPUT
fi
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]] && \
[[ "${{ github.event.head_commit.modified }}" =~ (pkg/|go\.|\.github/workflows/pr-test-backend\.yml) ]]; then
echo "Coverage will be generated: true (push to main)"
echo "generate=true" >> $GITHUB_OUTPUT
else
echo "Coverage will be generated: false"
echo "generate=false" >> $GITHUB_OUTPUT
fi
- name: Run backend tests
uses: ./.github/actions/run-backend-tests
with:
coverage-opts: ${{ steps.check-coverage.outputs.generate == 'true' && '-coverprofile=unit.cov -coverpkg=github.com/grafana/grafana/...' || '' }}
test-command: 'make gen-go test-go-unit'
- name: Run backend integration tests
uses: ./.github/actions/run-backend-tests
with:
coverage-opts: ${{ steps.check-coverage.outputs.generate == 'true' && '-coverprofile=integration.cov -coverpkg=github.com/grafana/grafana/...' || '' }}
test-command: 'make gen-go test-go-integration'
- name: Generate Coverage Report
if: steps.check-coverage.outputs.generate == 'true'
uses: ./.github/actions/report-coverage
with:
unit-cov-path: unit.cov
integration-cov-path: integration.cov
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true