mirror of https://github.com/grafana/grafana.git
158 lines
5.2 KiB
YAML
158 lines
5.2 KiB
YAML
name: "Go Workspace Check"
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
detect-changes:
|
|
name: Detect whether code changed
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
outputs:
|
|
changed: ${{ steps.detect-changes.outputs.backend }}
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
with:
|
|
persist-credentials: true # required to get more history in the changed-files action
|
|
fetch-depth: 2
|
|
- name: Detect changes
|
|
id: detect-changes
|
|
uses: ./.github/actions/change-detection
|
|
with:
|
|
self: .github/workflows/pr-go-workspace-check.yml
|
|
|
|
check-workspace:
|
|
needs: detect-changes
|
|
if: needs.detect-changes.outputs.changed == 'true'
|
|
name: Go Workspace Check
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Set go version
|
|
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00
|
|
with:
|
|
cache: false
|
|
go-version-file: go.mod
|
|
|
|
- name: Update workspace
|
|
run: make update-workspace
|
|
|
|
- name: Check for go mod & workspace changes
|
|
run: |
|
|
if ! git diff --exit-code --quiet; then
|
|
echo "Changes detected:"
|
|
git diff
|
|
echo "Please run 'make update-workspace' and commit the changes."
|
|
echo "If there is a change in enterprise dependencies, please update pkg/extensions/main.go."
|
|
exit 1
|
|
fi
|
|
- name: Ensure Dockerfile contains submodule COPY commands
|
|
run: ./scripts/go-workspace/validate-dockerfile.sh
|
|
|
|
check-wire:
|
|
needs: detect-changes
|
|
if: needs.detect-changes.outputs.changed == 'true'
|
|
name: Check Wire Changes
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Set go version
|
|
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00
|
|
with:
|
|
cache: false
|
|
go-version-file: go.mod
|
|
|
|
- name: Setup Enterprise
|
|
if: github.event.pull_request.head.repo.fork == false
|
|
uses: ./.github/actions/setup-enterprise
|
|
|
|
- name: Calculate generated wire checksums
|
|
id: pre_gen_oss
|
|
run: |
|
|
OSS_WIRE_CHECKSUM="$(sha256sum pkg/server/wire_gen.go | cut -d' ' -f1)"
|
|
echo "wire_checksum=$OSS_WIRE_CHECKSUM" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Calculate generated enterprise wire checksums
|
|
id: pre_gen_enterprise
|
|
if: github.event.pull_request.head.repo.fork == false
|
|
run: |
|
|
ENTERPRISE_WIRE_CHECKSUM="$(sha256sum pkg/server/enterprise_wire_gen.go | cut -d' ' -f1)"
|
|
echo "wire_checksum=$ENTERPRISE_WIRE_CHECKSUM" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Generate Go files
|
|
run: make gen-go
|
|
|
|
- name: Check for generated file changes
|
|
run: |
|
|
OSS_WIRE_CHANGED=false
|
|
CURRENT_OSS_WIRE_CHECKSUM=$(sha256sum pkg/server/wire_gen.go | cut -d' ' -f1)
|
|
if [ "$CURRENT_OSS_WIRE_CHECKSUM" != "${{ steps.pre_gen_oss.outputs.wire_checksum }}" ]; then
|
|
OSS_WIRE_CHANGED=true
|
|
echo "Uncomitted changes detected in pkg/server/wire_gen.go"
|
|
fi
|
|
|
|
ENTERPRISE_WIRE_CHANGED=false
|
|
if [ -f "pkg/server/enterprise_wire_gen.go" ]; then
|
|
CURRENT_ENTERPRISE_WIRE_CHECKSUM=$(sha256sum pkg/server/enterprise_wire_gen.go | cut -d' ' -f1)
|
|
if [ "$CURRENT_ENTERPRISE_WIRE_CHECKSUM" != "${{ steps.pre_gen_enterprise.outputs.wire_checksum }}" ]; then
|
|
ENTERPRISE_WIRE_CHANGED=true
|
|
echo "Uncomitted changes detected in pkg/server/enterprise_wire_gen.go"
|
|
fi
|
|
fi
|
|
|
|
if [ "$OSS_WIRE_CHANGED" = "false" ] && [ "$ENTERPRISE_WIRE_CHANGED" = "false" ]; then
|
|
echo "No changes in generated Go files"
|
|
else
|
|
if [[ "${{ github.event.pull_request.head.repo.fork }}" == "false" ]]; then
|
|
echo "> !!! Please synchronize the grafana OSS and grafana enterprise code bases as defined in the enterprise readme, then run 'make gen-go' in the OSS folder and commit the changes to both repositories."
|
|
else
|
|
echo "> !!! Please run 'make gen-go' and commit the changes."
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
# This is the job that is actually required by rulesets.
|
|
# We want to only require one job instead of all the individual tests.
|
|
# Future work also allows us to start skipping some tests based on changed files.
|
|
required-go-workspace-check:
|
|
needs:
|
|
- check-workspace
|
|
- check-wire
|
|
# always() is the best function here.
|
|
# success() || failure() will skip this function if any need is also skipped.
|
|
# That means conditional jobs will fail the entire requirement check.
|
|
if: always()
|
|
|
|
name: All Go Workspace Checks complete
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check the checks
|
|
env:
|
|
NEEDS: ${{ toJson(needs) }}
|
|
run: |
|
|
FAILURES="$(echo "$NEEDS" | jq 'with_entries(select(.value.result == "failure")) | map_values(.result)')"
|
|
echo "$FAILURES"
|
|
if [ "$(echo "$FAILURES" | jq '. | length')" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
echo "All OK!"
|