Files
grafana/.github/workflows/backend-unit-tests.yml
T
2025-05-14 21:18:34 -05:00

120 lines
4.0 KiB
YAML

name: Backend Unit Tests
on:
pull_request:
paths-ignore:
- 'docs/**'
- '**/*.md'
push:
branches:
- main
- release-*.*.*
paths-ignore:
- 'docs/**'
- '**/*.md'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
permissions: {}
jobs:
grafana:
# Run this workflow only for PRs from forks
# the `pr-backend-unit-tests-enterprise` workflow will run instead
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true
strategy:
matrix:
shard: [
1/8, 2/8, 3/8, 4/8,
5/8, 6/8, 7/8, 8/8,
]
fail-fast: false
name: Grafana (${{ matrix.shard }})
runs-on: ubuntu-latest-8-cores
continue-on-error: true
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Generate Go code
run: make gen-go
- name: Run unit tests
env:
SHARD: ${{ matrix.shard }}
run: |
readarray -t PACKAGES <<< "$(./scripts/ci/backend-tests/shard.sh -N"$SHARD")"
go test -short -timeout=30m "${PACKAGES[@]}"
grafana-enterprise:
# Run this workflow for non-PR events (like pushes to `main` or `release-*`) OR for internal PRs (PRs not from forks)
# If it gets merged into `main` or `release-*`, then a junit test result is uploaded to GCS.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
strategy:
matrix:
shard: [
1/8, 2/8, 3/8, 4/8,
5/8, 6/8, 7/8, 8/8,
]
fail-fast: false
name: Grafana Enterprise (${{ matrix.shard }})
runs-on: ubuntu-latest-8-cores
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Setup Enterprise
uses: ./.github/actions/setup-enterprise
with:
github-app-name: 'grafana-ci-bot'
- run: echo "RESULTS_FILE=$(date --rfc-3339=seconds --utc | sed -s 's/ /-/g')_${SHARD/\//_}.xml" >> "$GITHUB_ENV"
env:
SHARD: ${{ matrix.shard }}
- run: go install github.com/jstemmer/go-junit-report/v2@85bf4716ac1f025f2925510a9f5e9f5bb347c009
- name: Generate Go code
run: make gen-go
- name: Run unit tests
env:
SHARD: ${{ matrix.shard }}
run: |
readarray -t PACKAGES <<< "$(./scripts/ci/backend-tests/shard.sh -N"$SHARD")"
go test -short -v -timeout=30m "${PACKAGES[@]}" | tee >(go-junit-report -set-exit-code > "$RESULTS_FILE")
- name: Log in to GCS
if: github.repository == 'grafana/grafana' && (success() || failure())
uses: grafana/shared-workflows/actions/login-to-gcs@login-to-gcs-v0.2.0
with:
service_account: github-junit-uploader@grafanalabs-workload-identity.iam.gserviceaccount.com
bucket: grafana-test-results
- if: github.repository == 'grafana/grafana' && (success() || failure())
run: echo "BUCKET_PATH=go-unit-tests/$(echo ${REF_NAME} | sed 's/\//-/g')" >> "$GITHUB_ENV"
env:
REF_NAME: ${{ github.ref_name }}
- name: Upload test results
if: github.repository == 'grafana/grafana' && (success() || failure())
uses: grafana/shared-workflows/actions/push-to-gcs@push-to-gcs-v0.2.0
with:
bucket: grafana-test-results
service_account: github-junit-uploader@grafanalabs-workload-identity.iam.gserviceaccount.com
environment: "dev" # Can be dev/prod (defaults to dev)
path: ${{ env.RESULTS_FILE }}
bucket_path: ${{ env.BUCKET_PATH }}