Skip to content

Commit ac1d655

Browse files
apatruddognogatesclaude
authored
Add build-terraform-provider CI step to detect breaking changes (DataDog#3894)
* moves CLI testing to Go library repo * Use PR description for terraform provider fix link instead of file * Remove file-based terraform-provider-pr cleanup from release.yml * Pass tf-provider-pr as input instead of re-parsing PR description * Remove PR description parsing from go-client; use tf-provider-pr input or master * Revert GO_CLIENT_BRANCH fallback, no longer needed without edited event * Improve build failure message with force rebuild option * Remove redundant explicit PR event types from test.yml Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix rebuild instruction — a new commit is always required to re-trigger CI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Restore inputs.target-branch fallback for GO_CLIENT_BRANCH When called from api-spec, github.event.pull_request.head.sha is the api-spec SHA, not a go-client SHA — the lookup fails. inputs.target-branch carries the correct go-client branch name in that path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: David Tapiador <david.tapiadordeldujo@datadoghq.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3f32dee commit ac1d655

3 files changed

Lines changed: 130 additions & 1 deletion

File tree

.github/workflows/reusable-ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ on:
88
required: false
99
type: string
1010
default: ''
11-
11+
tf-provider-pr:
12+
description: 'terraform-provider-datadog PR URL to test against (if already known, e.g. passed from ci-cd.yml)'
13+
required: false
14+
type: string
15+
default: ''
1216
secrets:
1317
PIPELINE_GITHUB_APP_ID:
1418
required: false
@@ -38,6 +42,10 @@ jobs:
3842
uses: ./.github/workflows/reusable-go-test.yml
3943
with:
4044
target-branch: ${{ inputs.target-branch }}
45+
tf-provider-pr: ${{ inputs.tf-provider-pr }}
46+
secrets:
47+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
48+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
4149

4250
examples:
4351
uses: ./.github/workflows/reusable-examples.yml

.github/workflows/reusable-go-test.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ on:
88
required: false
99
type: string
1010
default: ''
11+
tf-provider-pr:
12+
description: 'terraform-provider-datadog PR URL to test against (if already known, skips PR description parsing)'
13+
required: false
14+
type: string
15+
default: ''
16+
17+
secrets:
18+
PIPELINE_GITHUB_APP_ID:
19+
required: false
20+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
21+
required: false
1122

1223
jobs:
1324
test:
@@ -34,3 +45,110 @@ jobs:
3445
env:
3546
TESTARGS: ${{ matrix.go-build-tags }}
3647

48+
build-terraform-provider:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Get GitHub App token
52+
id: get_token
53+
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
54+
with:
55+
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
56+
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
57+
owner: DataDog
58+
59+
- name: Setup to use the GitHub token
60+
run: |-
61+
git config --global --add url."https://${APP_ID}:${APP_TOKEN}@github.com/".insteadOf "https://github.com/"
62+
env:
63+
APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
64+
APP_TOKEN: ${{ steps.get_token.outputs.token }}
65+
66+
- name: Detect linked terraform-provider-datadog PR
67+
id: detect_tf_pr
68+
env:
69+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
70+
TF_PROVIDER_PR_INPUT: ${{ inputs.tf-provider-pr }}
71+
run: |
72+
# The terraform fix PR URL is optionally passed in via the tf-provider-pr input
73+
# (set by datadog-api-spec's detect-tf-pr-change job). If not provided, fall back
74+
# to master — direct go-client PRs don't carry a terraform fix link.
75+
if [ -n "$TF_PROVIDER_PR_INPUT" ]; then
76+
tf_pr_number=$(echo "$TF_PROVIDER_PR_INPUT" | grep -oE '[0-9]+$')
77+
tf_state=$(gh pr view "$tf_pr_number" --repo DataDog/terraform-provider-datadog --json state --jq '.state')
78+
79+
if [ "$tf_state" = "OPEN" ]; then
80+
tf_branch=$(gh pr view "$tf_pr_number" --repo DataDog/terraform-provider-datadog --json headRefName --jq '.headRefName')
81+
echo "branch=${tf_branch}" >> $GITHUB_OUTPUT
82+
echo "✅ Using terraform-provider-datadog PR #${tf_pr_number} (branch: ${tf_branch})"
83+
else
84+
echo "branch=master" >> $GITHUB_OUTPUT
85+
echo "ℹ️ terraform-provider-datadog PR #${tf_pr_number} is ${tf_state} — using master"
86+
fi
87+
else
88+
echo "branch=master" >> $GITHUB_OUTPUT
89+
echo "ℹ️ No tf-provider-pr input provided, using master"
90+
fi
91+
92+
- name: Checkout terraform-provider-datadog
93+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
94+
with:
95+
repository: DataDog/terraform-provider-datadog
96+
ref: ${{ steps.detect_tf_pr.outputs.branch }}
97+
token: ${{ steps.get_token.outputs.token }}
98+
99+
- name: Set up Go
100+
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
101+
with:
102+
go-version-file: go.mod
103+
104+
- name: Resolve generated branch to commit SHA
105+
id: resolve_sha
106+
run: |
107+
# go get rejects branch names with slashes (e.g. datadog-api-spec/generated/1234),
108+
# so we resolve the branch to its commit SHA first.
109+
COMMIT_SHA=$(gh api "repos/DataDog/datadog-api-client-go/commits/${GO_CLIENT_BRANCH}" --jq '.sha')
110+
echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT
111+
env:
112+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
113+
# When called from api-spec via reusable-ci, inputs.target-branch is the go-client branch
114+
# name (e.g. datadog-api-spec/generated/1234). Without it, github.event.pull_request.head.sha
115+
# is the api-spec commit SHA, which doesn't exist in the go-client repo.
116+
GO_CLIENT_BRANCH: ${{ inputs.target-branch || github.event.pull_request.head.sha || github.sha }}
117+
118+
- name: Update datadog-api-client-go to generated commit
119+
run: |
120+
# GOPROXY=direct bypasses the module proxy, which won't have unreleased
121+
# commits from the private datadog-api-client-go repo.
122+
GOPROXY=direct go get "github.com/DataDog/datadog-api-client-go/v2@${COMMIT_SHA}"
123+
go mod tidy
124+
env:
125+
COMMIT_SHA: ${{ steps.resolve_sha.outputs.commit_sha }}
126+
127+
- name: Build terraform provider
128+
run: |
129+
if ! go build ./...; then
130+
echo ""
131+
echo "🚨 BUILD FAILED"
132+
echo "This Go client change breaks the terraform-provider-datadog build."
133+
echo ""
134+
if [ "${TF_BRANCH}" = "master" ]; then
135+
echo "The build was tested against the terraform-provider-datadog 'master' branch."
136+
echo ""
137+
echo "To fix this:"
138+
echo " 1. Create a PR on DataDog/terraform-provider-datadog with the necessary code changes"
139+
echo " 2. Add the following line to your PR description:"
140+
echo " Fix Terraform Provider PR: https://github.com/DataDog/terraform-provider-datadog/pull/1234"
141+
echo " 3. Save the PR description"
142+
echo " 4. Push a new commit to trigger the check:"
143+
echo " git commit --allow-empty -m \"force rebuild\""
144+
echo " or use the opportunity to update the branch with any other pending changes"
145+
else
146+
echo "The build was tested against the terraform-provider-datadog branch '${TF_BRANCH}'."
147+
echo "The linked PR also fails to build with the generated Go client — please fix it."
148+
fi
149+
exit 1
150+
fi
151+
echo ""
152+
echo "✅ Build succeeded — terraform-provider-datadog builds correctly with the generated Go client."
153+
env:
154+
TF_BRANCH: ${{ steps.detect_tf_pr.outputs.branch }}

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
4040
github.event_name == 'schedule'
4141
uses: ./.github/workflows/reusable-go-test.yml
42+
secrets:
43+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
44+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
4245

4346
examples:
4447
if: >

0 commit comments

Comments
 (0)