mirror of https://github.com/grafana/grafana
Chore: Backend unit test workflow (#101534)
* baldm0mma/ parallelize tests for reporting * baldm0mma/ update combining non-existant outputs * baldm0mma/ remove duplicate logic * baldm0mma/ rem any unnecessary logging * baldm0mma/ add workflow path for test coverage test * baldm0mma/ cache ent * baldm0mma/ update with crucial comments * baldm0mma/ generate go files * baldm0mma/ cache enterprise only once * baldm0mma/ adjust coverage threshholds * baldm0mma/ remove temp artifacts from storage to save $$$ * baldm0mma/ remove strict coverage for unit tests * baldm0mma/ pass coverage go opts * baldm0mma/ update run backend tests action to composite * baldm0mma/ separate make gen go into it's own composite step * baldm0mma/ move options to workflow * baldm0mma/ remove use of action * baldm0mma/ remove unsed action * baldm0mma/ update codeowners * baldm0mma/ add edition logic * baldm0mma/ set env vars in determine-edition action * baldm0mma/ make test * baldm0mma/ debug sequential * baldm0mma/ debugging by removing unit tests * baldm0mma/ TRY SOMETHING DIFFERENT!!! * baldm0mma/ uploading ent from within the workspace * baldm0mma/ revert run-backend-tests action * baldm0mma/ move edition to job level * baldm0mma/ update WIRE_TAGS * baldm0mma/ move the enterprise code to the correct location after extracting it * baldm0mma/ rem packaging/extracting of enterprise code * baldm0mma/ test makefile * baldm0mma/ add ent setup to coverage * baldm0mma/ rem backend test action * baldm0mma/ add wire and go steps to coverage job * baldm0mma/ remove make installation, as it is already present in the "ubuntu-latest" package * baldm0mma/ convert to matrix testing strategy * baldm0mma/ update separate test coverage to only a day * baldm0mma/ add setup-common-backend-testing-env action * baldm0mma/ add setup env * baldm0mma/ update naming * baldm0mma/ updade codeowners * baldm0mma/ rem ent * baldm0mma/ update naming * baldm0mma/ remove multiline syntax in report-coverage * baldm0mma/ make gen-go * baldm0mm/ remove integration tests * baldm0mma/ update coverage params * baldm0mma/ streamline workflow * baldm0mma/ update codeowners * baldm0mma/ update naming * baldm0mma/ simplify logic * baldm0mma/ remove uneeded trigger * baldm0mma/ remove conditional coverage step * baldm0mma/ debug coverage * baldm0mma/ update file name * baldm0mma/ remove artifact upload * baldm0mma/ update atrifact params in the workflow * baldm0mma/ simplify processing logicpull/101739/head
parent
c7b0bbd262
commit
ef3cb8596e
@ -1,60 +0,0 @@ |
||||
name: 'Report Coverage' |
||||
description: 'Processes and uploads coverage reports from Go tests' |
||||
|
||||
inputs: |
||||
unit-cov-path: |
||||
description: 'Path to unit test coverage file' |
||||
required: true |
||||
integration-cov-path: |
||||
description: 'Path to integration test coverage file' |
||||
required: true |
||||
codecov-token: |
||||
description: 'Token for CodeCov' |
||||
required: true |
||||
|
||||
runs: |
||||
using: "composite" |
||||
steps: |
||||
- name: Join coverage outputs |
||||
shell: bash |
||||
run: | |
||||
cp ${{ inputs.unit-cov-path }} backend.cov |
||||
tail -n+2 ${{ inputs.integration-cov-path }} >> backend.cov |
||||
|
||||
- name: Convert coverage info to per-func stats |
||||
shell: bash |
||||
run: go tool cover -func backend.cov > backend-funcs.log |
||||
|
||||
- name: Convert coverage info to HTML |
||||
shell: bash |
||||
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 |
||||
|
||||
- name: Set summary to total coverage |
||||
shell: bash |
||||
run: | |
||||
echo '# Coverage' >> $GITHUB_STEP_SUMMARY |
||||
echo '```' >> $GITHUB_STEP_SUMMARY |
||||
grep 'total:' backend-funcs.log | tr '\t' ' ' >> $GITHUB_STEP_SUMMARY |
||||
echo '```' >> $GITHUB_STEP_SUMMARY |
||||
|
||||
- name: Report coverage to CodeCov |
||||
uses: codecov/codecov-action@v5 |
||||
with: |
||||
files: backend.cov |
||||
flags: unified-backend |
||||
name: backend |
||||
slug: grafana/grafana |
||||
# This URL doesn't use the Google auth, but is much more locked down. As such, it requires OIDC or a CodeCov-provided token to do anything. |
||||
url: https://codecov-webhook.grafana-dev.net |
||||
token: ${{ inputs.codecov-token }} |
@ -1,24 +0,0 @@ |
||||
name: 'Run Backend Tests' |
||||
description: 'Runs Grafana backend test suites' |
||||
|
||||
inputs: |
||||
coverage-opts: |
||||
description: 'Coverage options to pass to the test command (empty for no coverage)' |
||||
required: false |
||||
default: '' |
||||
test-command: |
||||
description: 'The test command to run' |
||||
required: false |
||||
default: 'make gen-go test-go-unit' |
||||
|
||||
runs: |
||||
using: "composite" |
||||
steps: |
||||
- name: Run tests |
||||
shell: bash |
||||
run: | |
||||
if [ -n "${{ inputs.coverage-opts }}" ]; then |
||||
COVER_OPTS="${{ inputs.coverage-opts }}" ${{ inputs.test-command }} |
||||
else |
||||
${{ inputs.test-command }} |
||||
fi |
@ -1,48 +0,0 @@ |
||||
name: 'Setup Grafana Enterprise' |
||||
description: 'Clones and sets up Grafana Enterprise repository for testing' |
||||
|
||||
inputs: |
||||
github-app-name: |
||||
description: 'Name of the GitHub App in Vault' |
||||
required: false |
||||
default: 'grafana-ci-bot' |
||||
|
||||
runs: |
||||
using: "composite" |
||||
steps: |
||||
- name: Retrieve GitHub App secrets |
||||
id: get-secrets |
||||
uses: grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets-v1.0.1 |
||||
with: |
||||
repo_secrets: | |
||||
APP_ID=${{ inputs.github-app-name }}:app-id |
||||
APP_INSTALLATION_ID=${{ inputs.github-app-name }}:app-installation-id |
||||
PRIVATE_KEY=${{ inputs.github-app-name }}:private-key |
||||
|
||||
- name: Generate GitHub App token |
||||
id: generate_token |
||||
uses: actions/create-github-app-token@v1 |
||||
with: |
||||
app-id: ${{ env.APP_ID }} |
||||
private-key: ${{ env.PRIVATE_KEY }} |
||||
repositories: "grafana-enterprise" |
||||
owner: "grafana" |
||||
|
||||
- name: Setup Enterprise |
||||
shell: bash |
||||
env: |
||||
GH_TOKEN: ${{ steps.generate_token.outputs.token }} |
||||
run: | |
||||
git clone https://x-access-token:${GH_TOKEN}@github.com/grafana/grafana-enterprise.git ../grafana-enterprise; |
||||
|
||||
cd ../grafana-enterprise |
||||
|
||||
if git checkout ${GITHUB_HEAD_REF}; then |
||||
echo "checked out ${GITHUB_HEAD_REF}" |
||||
elif git checkout ${GITHUB_BASE_REF}; then |
||||
echo "checked out ${GITHUB_BASE_REF}" |
||||
else |
||||
git checkout main |
||||
fi |
||||
|
||||
./build.sh |
@ -0,0 +1,48 @@ |
||||
name: 'Go Coverage Processor' |
||||
description: 'Process Go test coverage files and generate reports' |
||||
|
||||
inputs: |
||||
test-type: |
||||
description: 'Type of test (e.g., be-unit, be-integration)' |
||||
required: true |
||||
type: string |
||||
coverage-file: |
||||
description: 'Path to the Go coverage file (.cov)' |
||||
required: true |
||||
type: string |
||||
codecov-token: |
||||
description: 'Token for CodeCov (required for CodeCov reporting)' |
||||
required: false |
||||
default: '' |
||||
codecov-flag: |
||||
description: 'Flag to categorize the upload to CodeCov' |
||||
required: false |
||||
default: '' |
||||
codecov-name: |
||||
description: 'Custom name for the upload to CodeCov' |
||||
required: false |
||||
default: '' |
||||
|
||||
runs: |
||||
using: 'composite' |
||||
steps: |
||||
- name: Process Go coverage output |
||||
shell: bash |
||||
run: | |
||||
# Ensure valid coverage file even if empty |
||||
if [ ! -s ${{ inputs.coverage-file }} ]; then |
||||
echo "Coverage file is empty, creating a minimal valid file" |
||||
echo "mode: set" > ${{ inputs.coverage-file }} |
||||
fi |
||||
|
||||
- name: Report coverage to CodeCov |
||||
uses: codecov/codecov-action@v5 |
||||
if: inputs.codecov-token != '' |
||||
with: |
||||
files: ${{ inputs.coverage-file }} |
||||
flags: ${{ inputs.codecov-flag || inputs.test-type }} |
||||
name: ${{ inputs.codecov-name || inputs.test-type }} |
||||
slug: grafana/grafana |
||||
# This URL doesn't use the Google auth, but is much more locked down. As such, it requires OIDC or a CodeCov-provided token to do anything. |
||||
url: https://codecov-webhook.grafana-dev.net |
||||
token: ${{ inputs.codecov-token }} |
@ -0,0 +1,66 @@ |
||||
name: Backend Unit Tests |
||||
|
||||
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' |
||||
WIRE_TAGS: 'oss' |
||||
|
||||
jobs: |
||||
backend-testing-coverage: |
||||
name: Backend Testing & Coverage |
||||
runs-on: ubuntu-latest |
||||
steps: |
||||
- name: Checkout code |
||||
uses: actions/checkout@v4 |
||||
|
||||
- name: Setup Go |
||||
uses: actions/setup-go@v5 |
||||
with: |
||||
go-version-file: go.mod |
||||
cache: true |
||||
|
||||
- name: Install dependencies |
||||
run: | |
||||
sudo apt-get update |
||||
sudo apt-get install -y build-essential shared-mime-info |
||||
|
||||
- name: Verify code generation |
||||
run: | |
||||
CODEGEN_VERIFY=1 make gen-cue |
||||
CODEGEN_VERIFY=1 make gen-jsonnet |
||||
|
||||
- name: Generate Go code |
||||
run: make gen-go |
||||
|
||||
- name: Run unit tests |
||||
run: COVER_OPTS="-coverprofile=be-unit.cov -coverpkg=github.com/grafana/grafana/..." make test-go-unit |
||||
|
||||
- name: Process and upload coverage |
||||
uses: ./.github/actions/test-coverage-processor |
||||
with: |
||||
test-type: 'be-unit' |
||||
# Needs to be named 'unit.cov' based on the Makefile command `make test-go-unit` |
||||
coverage-file: 'unit.cov' |
||||
codecov-token: ${{ secrets.CODECOV_TOKEN }} |
||||
codecov-flag: 'be-unit' |
||||
codecov-name: 'be-unit' |
||||
|
||||
concurrency: |
||||
group: ${{ github.workflow }}-${{ github.ref }} |
||||
cancel-in-progress: true |
@ -1,107 +0,0 @@ |
||||
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.7' |
||||
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 |
||||
codecov-token: ${{ secrets.CODECOV_TOKEN }} |
||||
|
||||
concurrency: |
||||
group: ${{ github.workflow }}-${{ github.ref }} |
||||
cancel-in-progress: true |
Loading…
Reference in new issue