Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# NOTE: this template is automatically generated by scripts/generate_issue_template.go
# DO NOT EDIT MANUALLY - run 'go run scripts/generate_issue_template.go --update-schema' instead

name: Bug Report (Enhanced)
description: File a bug report with resource dropdown
type: "bug"
Expand Down Expand Up @@ -125,6 +128,7 @@ body:
- grafana_role_assignment (resource)
- grafana_role_assignment_item (resource)
- grafana_rule_group (resource)
- grafana_scim_config (resource)
- grafana_service_account (data source)
- grafana_service_account (resource)
- grafana_service_account_permission (resource)
Expand Down
101 changes: 78 additions & 23 deletions .github/workflows/update-schema.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,95 @@
name: update provider schema
name: enforce schema consistency

on:
push:
branches:
- main
pull_request:
paths:
- 'internal/**'
- 'pkg/**'
- 'go.mod'
- 'go.sum'
workflow_dispatch: {}

permissions:
contents: write

jobs:
update-schema:
name: update provider schema
enforce-schema-consistency:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Set up Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version-file: go.mod
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2

- name: build provider
run: go build .
- name: Set up Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2

- name: Generate current schema
run: |
go build .
./scripts/generate_schema.sh > current_schema.json

- name: Check for schema changes
id: schema-check
run: |
# Compare with committed schema if it exists
if [ -f "provider_schema.json" ]; then
if ! diff -q provider_schema.json current_schema.json > /dev/null; then
echo "schema_changed=true" >> $GITHUB_OUTPUT
echo "Schema changes detected!"
else
echo "schema_changed=false" >> $GITHUB_OUTPUT
echo "No schema changes detected."
fi
else
echo "schema_changed=true" >> $GITHUB_OUTPUT
echo "No existing schema file found."
fi

- name: Update templates
if: steps.schema-check.outputs.schema_changed == 'true'
run: |
go run scripts/generate_issue_template.go --update-schema

- name: Comment on PR
if: steps.schema-check.outputs.schema_changed == 'true'
uses: actions/github-script@v7
with:
script: |
const comment = `## 🔧 Schema Update Required

This PR introduces changes that affect the Terraform provider schema. The issue templates need to be updated.

### 📋 Required Action

Please run the generator to update templates:

\`\`\`bash
make generate-templates
\`\`\`

Then commit the updated files:
- \`provider_schema.json\`
- \`.github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml\`

---
*This comment was generated automatically because schema changes were detected.*`;

- name: update schema and generate template
run: go run scripts/generate_issue_template.go --update-schema
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});

- name: commit changes
- name: Fail if schema changes detected
if: steps.schema-check.outputs.schema_changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add provider_schema.json .github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml
git diff --cached --quiet || git commit -m "chore: update provider schema and issue template"
git push
echo "❌ Schema changes detected - blocking merge until templates are updated"
echo "Run: make generate-templates"
echo "Then commit the updated files"
exit 1
11 changes: 9 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ docs:
linkcheck:
docker run --rm --entrypoint sh -v "$$PWD:$$PWD" -w "$$PWD" python:3.11-alpine -c "pip3 install linkchecker && linkchecker --config .linkcheckerrc docs"

update-schema:
go run scripts/generate_issue_template.go --update-schema
update-schema: ## Update provider schema only
go build .
./scripts/generate_schema.sh > provider_schema.json

generate-issue-template:
go run scripts/generate_issue_template.go

generate-templates: ## Generate issue templates with schema update
go run scripts/generate_issue_template.go --update-schema

generate-templates-quick: ## Generate issue templates (using cached schema)
go run scripts/generate_issue_template.go
1 change: 1 addition & 0 deletions current_schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion provider_schema.json

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions scripts/generate_issue_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ func main() {

// Generate template
generateTemplate(resources)
fmt.Printf("Generated issue template with %d resources\n", len(resources))

// Output summary for workflows
resourceCount := len(grafanaProvider.ResourceSchemas)
dataSourceCount := len(grafanaProvider.DataSourceSchemas)
totalCount := len(resources) - 1 // Subtract "Other" option

fmt.Printf("Generated issue template with %d resources and %d data sources (%d total)\n",
resourceCount, dataSourceCount, totalCount)

// Output for GitHub Actions if running in CI
if os.Getenv("GITHUB_ACTIONS") == "true" {
fmt.Printf("RESOURCE_COUNT=%d\n", resourceCount)
fmt.Printf("DATASOURCE_COUNT=%d\n", dataSourceCount)
fmt.Printf("TOTAL_COUNT=%d\n", totalCount)
}
}

func loadSchema(update bool) ProviderSchema {
Expand Down Expand Up @@ -82,7 +96,9 @@ func loadSchema(update bool) ProviderSchema {
func generateTemplate(resources []string) {
os.MkdirAll(".github/ISSUE_TEMPLATE", 0755)

template := `# NOTE: this template is automatically generated
template := `# NOTE: this template is automatically generated by scripts/generate_issue_template.go
# DO NOT EDIT MANUALLY - run 'go run scripts/generate_issue_template.go --update-schema' instead

name: Bug Report (Enhanced)
description: File a bug report with resource dropdown
type: "bug"
Expand Down Expand Up @@ -146,5 +162,8 @@ body:
placeholder: |
- GH-1234`

os.WriteFile(".github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml", []byte(template), 0600)
filename := ".github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml"
if err := os.WriteFile(filename, []byte(template), 0600); err != nil {
panic(fmt.Sprintf("Failed to write template: %v", err))
}
}
Loading