Skip to content

Commit 2e16120

Browse files
fix(update-schema): use Github Token to generate PR containing schema changes (#2260)
* fix(update-schema): add app configuration * fix: remove temporary fix * fix: add hash * test: use GITHUB_TOKEN * test: change provider schema * test: fix workflow * chore: update provider schema and issue templates Auto-generated by schema consistency workflow * fix: run workflow on specific path filters * fix: make action generate a new PR for schema update * test: test run workflow * fix: run on PR * fix: run on PR * fix: revert testing changes * fix: docs --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 4857e40 commit 2e16120

File tree

5 files changed

+40
-72
lines changed

5 files changed

+40
-72
lines changed
Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
name: enforce schema consistency
1+
name: create schema update PR
22

33
on:
4-
pull_request:
4+
push:
5+
branches:
6+
- main
57
paths:
68
- 'internal/**'
79
- 'pkg/**'
810
- 'go.mod'
911
- 'go.sum'
1012

1113
jobs:
12-
enforce-schema-consistency:
14+
create-schema-update-pr:
1315
runs-on: ubuntu-latest
1416
permissions:
15-
pull-requests: write
16-
contents: read
17+
contents: write # Required to commit changes
18+
pull-requests: write # Required to create PRs
1719
steps:
1820
- name: Checkout
1921
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2022
with:
21-
persist-credentials: false
23+
token: ${{ secrets.GITHUB_TOKEN }}
2224

2325
- name: Set up Go
2426
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
@@ -27,8 +29,6 @@ jobs:
2729

2830
- name: Set up Terraform
2931
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
30-
with:
31-
terraform_version: "1.12.2" # Ensure to use the same in generate_schema.sh
3232

3333
- name: Generate current schema
3434
run: |
@@ -52,46 +52,43 @@ jobs:
5252
echo "Required provider_schema.json file not found"
5353
fi
5454
55-
- name: Update templates
55+
- name: Update schema and templates
5656
if: steps.schema-check.outputs.schema_changed == 'true'
5757
run: |
58+
# Update the provider schema
59+
cp current_schema.json provider_schema.json
60+
61+
# Update templates
5862
go run scripts/generate_issue_template.go --update-schema
5963
60-
- name: Comment on PR
64+
- name: Create Pull Request with schema updates
6165
if: steps.schema-check.outputs.schema_changed == 'true'
62-
uses: actions/github-script@v7
66+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
6367
with:
64-
script: |
65-
const comment = `## 🔧 Schema Update Required
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
commit-message: |
70+
chore: update provider schema and issue templates
6671
67-
This PR introduces changes that affect the Terraform provider schema. The issue templates need to be updated.
72+
Auto-generated by schema consistency workflow
73+
title: 'chore: update provider schema and issue templates'
74+
body: |
75+
## Automated Schema Update
6876
69-
### 📋 Required Action
77+
This PR was automatically created because recent changes to the codebase affected the Terraform provider schema.
7078
71-
Please run the generator to update templates:
79+
### Changes Made:
80+
- Updated `provider_schema.json` with latest schema definitions
81+
- Updated `.github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml` with new schema options
7282
73-
\`\`\`bash
74-
make generate-templates
75-
\`\`\`
76-
77-
Then commit the updated files:
78-
- \`provider_schema.json\`
79-
- \`.github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml\`
83+
### Triggered By:
84+
- **Commit**: ${{ github.sha }}
85+
- **Message**: ${{ github.event.head_commit.message }}
86+
- **Author**: ${{ github.event.head_commit.author.name }}
8087
8188
---
82-
*This comment was generated automatically because schema changes were detected.*`;
83-
84-
github.rest.issues.createComment({
85-
issue_number: context.issue.number,
86-
owner: context.repo.owner,
87-
repo: context.repo.repo,
88-
body: comment
89-
});
90-
91-
- name: Fail if schema changes detected
92-
if: steps.schema-check.outputs.schema_changed == 'true'
93-
run: |
94-
echo "❌ Schema changes detected - blocking merge until templates are updated"
95-
echo "Run: make generate-templates"
96-
echo "Then commit the updated files"
97-
exit 1
89+
🤖 *This PR was created automatically by the schema consistency workflow. Please review the changes before merging.*
90+
branch: 'automated/update-schema'
91+
delete-branch: true
92+
base: main
93+
committer: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>'
94+
author: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>'

docs/resources/slo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: |-
99

1010
# grafana_slo (Resource)
1111

12-
Resource manages Grafana SLOs.
12+
Resource manages Grafana SLOs.
1313

1414
* [Official documentation](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/)
1515
* [API documentation](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/api/)

internal/resources/slo/resource_slo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var resourceSloID = common.NewResourceID(common.StringIDField("uuid"))
2828
func resourceSlo() *common.Resource {
2929
schema := &schema.Resource{
3030
Description: `
31-
Resource manages Grafana SLOs.
31+
Resource manages Grafana SLOs.
3232
3333
* [Official documentation](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/)
3434
* [API documentation](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/api/)

provider_schema.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

scripts/generate_schema.sh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,6 @@ CURRENTDIR=$(realpath $(dirname $0))
44
REPODIR="${CURRENTDIR}"/..
55
WORKDIR=$(mktemp -d)
66

7-
TERRAFORM_VERSION="1.12.2"
8-
INSTALL_DIR="${REPODIR}"/testdata/terraform_"${TERRAFORM_VERSION}"
9-
10-
OS="$(uname | tr '[:upper:]' '[:lower:]')"
11-
case "$OS" in
12-
linux*) OS="linux" ;;
13-
darwin*) OS="darwin" ;;
14-
msys*|cygwin*|mingw*) OS="windows" ;;
15-
*) echo "Unknown OS: $OS"; exit 1 ;;
16-
esac
17-
18-
ARCH="$(uname -m)"
19-
case "$ARCH" in
20-
x86_64) ARCH="amd64" ;;
21-
i386|i686) ARCH="386" ;;
22-
armv6l|armv7l) ARCH="arm" ;;
23-
aarch64|arm64) ARCH="arm64" ;;
24-
*) echo "Unknown Arch: $ARCH"; exit 1 ;;
25-
esac
26-
27-
FILENAME=terraform_"${TERRAFORM_VERSION}"_"${OS}"_"${ARCH}".zip
28-
297
function finish {
308
rm -rf "${WORKDIR}"
319
}
@@ -52,11 +30,4 @@ echo '{"terraform":[{"required_providers":[{"provider":{"source":"grafana/grafan
5230

5331
export TF_CLI_CONFIG_FILE=terraform.rc
5432

55-
if [ ! -d "${INSTALL_DIR}" ]; then
56-
mkdir -p "${INSTALL_DIR}"
57-
58-
curl -o "${FILENAME}" https://releases.hashicorp.com/terraform/"${TERRAFORM_VERSION}"/"${FILENAME}"
59-
unzip -qq -o "${FILENAME}" -d "${INSTALL_DIR}"
60-
fi
61-
62-
"${INSTALL_DIR}/terraform" providers schema -json=true
33+
terraform providers schema -json=true

0 commit comments

Comments
 (0)