Skip to content

PR Validation

PR Validation #4506

Workflow file for this run

name: PR Validation
on:
pull_request:
merge_group:
# Helps to cut execution time in PRs and the merge queue by generating pre-commit/go/trivy cache (branches inherit cache from master)
push:
branches:
- master
permissions:
contents: read
jobs:
docs-only-check:
name: Check for docs-only change
runs-on: ubuntu-latest
outputs:
docs_only: ${{ steps.docs_only_check.outputs.docs_only }}
steps:
- name: Check out code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
fetch-depth: 0
persist-credentials: false
- id: changed-files
name: Get changed files
uses: step-security/changed-files@95b56dadb92a30ca9036f16423fd3c088a71ee94 # v46.0.5
with:
files_ignore: |
**/*.md
**/*.html
media/**
hugo/**
docs/**
examples/**
- id: docs_only_check
if: steps.changed-files.outputs.any_changed != 'true'
name: Check for docs-only changes
run: echo "docs_only=true" >> $GITHUB_OUTPUT
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
persist-credentials: false
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6
with:
python-version: "3.13"
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
test:
runs-on: ubuntu-latest
needs:
- docs-only-check
if: (needs.docs-only-check.outputs.docs_only != 'true')
steps:
- name: Clone repo
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
persist-credentials: false
- name: Pre-pull Grafana test image
run: |
make test-image-pre-pull
- name: Setup go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
with:
go-version-file: "go.mod"
- name: Run test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
make test
- name: Check if working tree is dirty
run: |
if [[ $(git status --porcelain) ]]; then
git diff
echo '::error::run make test and commit changes'
exit 1
fi
trivy:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
persist-credentials: false
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
with:
scan-type: "fs"
scan-ref: "."
format: "table"
exit-code: "1"
ignore-unfixed: true
severity: "CRITICAL,HIGH"
e2e-tests:
name: E2E on kind ${{ matrix.version }}
runs-on: ubuntu-latest
needs:
- docs-only-check
if: (needs.docs-only-check.outputs.docs_only != 'true' && github.event_name != 'push')
env:
KUBECONFIG: /home/runner/.kube/kind-grafana-operator-e2e
strategy:
matrix:
version:
- v1.31.9
- v1.32.8
- v1.33.4
- v1.34.0
steps:
- name: Pre-pull kind image
run: |
docker pull kindest/node:${{ matrix.version }} > /dev/null 2>&1 &
- name: Clone repo and checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
persist-credentials: false
- name: Install go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
with:
go-version-file: "go.mod"
cache: true
- name: Create KinD cluster ${{ matrix.version }}
id: kind
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KIND_NODE_VERSION: "${{ matrix.version }}"
run: |
make e2e-kind
- name: Install kubectl
uses: azure/setup-kubectl@776406bce94f63e41d621b960d78ee25c8b76ede # v4
with:
version: ${{ matrix.version }}
- name: Build and load images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KO_DOCKER_REPO: ko.local/grafana/grafana-operator
run: |
make ko-build-kind
- name: Run e2e tests
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Run e2e
VERSION=latest make e2e
- name: Debug failure
if: failure()
env:
NAMESPACE: default
run: |
set -e
kubectl version
kubectl get all -A
kubectl get grafanas -A
kubectl get crd
POD=$(kubectl get pods -n $NAMESPACE -l app.kubernetes.io/name=grafana-operator --output='jsonpath={.items[].metadata.name}')
echo "pod logs"
kubectl logs -n $NAMESPACE $POD -c manager
echo "previous pod logs (if any)"
kubectl logs -p -n $NAMESPACE $POD -c manager || true
end-to-end:
runs-on: ubuntu-latest
needs:
- e2e-tests
steps:
- run: |
echo "All E2E tests ran successfully"