-
Notifications
You must be signed in to change notification settings - Fork 328
Add workflow to prevent new Groovy test files #10730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 5 commits into
master
from
sarahchen6/workflow-to-enforce-no-groovy
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8164b95
Add workflow to prevent new Groovy test files
sarahchen6 909a40d
Address review comments
sarahchen6 84233f3
Update comment
sarahchen6 9c781e1
Merge branch 'master' into sarahchen6/workflow-to-enforce-no-groovy
sarahchen6 70c34b6
Merge branch 'master' into sarahchen6/workflow-to-enforce-no-groovy
sarahchen6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # This file lists modules that have been migrated from Groovy to Java / JUnit 5. | ||
| # New *.groovy files under any src/<*test*>/groovy/ path | ||
| # in these modules will fail the 'enforce-groovy-migration' PR check. | ||
| # | ||
| # After a module is migrated, add it on a new line here. | ||
| # Use the filesystem path prefix as seen below. | ||
|
|
||
| buildSrc/call-site-instrumentation-plugin | ||
| components/json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| name: Enforce Groovy Migration | ||
| on: | ||
| pull_request: | ||
| types: [opened, edited, ready_for_review, labeled, unlabeled, synchronize] | ||
| branches: | ||
| - master | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| enforce_groovy_migration: | ||
| name: Enforce Groovy migration | ||
| permissions: | ||
| issues: write # Required to create a comment on the pull request | ||
| pull-requests: write # Required to create a comment on the pull request | ||
| contents: read # Required to read migrated modules file | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check for Groovy regressions | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # 8.0.0 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| // Skip draft pull requests | ||
| if (context.payload.pull_request.draft) { | ||
| return | ||
| } | ||
|
|
||
| // Check for override label — skip all checks if label present | ||
| const labels = context.payload.pull_request.labels.map(l => l.name) | ||
| if (labels.includes('tag: override-groovy-enforcement')) { | ||
| console.log('tag: override-groovy-enforcement label detected — skipping all checks.') | ||
| return | ||
| } | ||
|
|
||
| // Read migrated modules list from master | ||
| const migratedMods = await github.rest.repos.getContent({ | ||
sarahchen6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| path: '.github/g2j-migrated-modules.txt', | ||
| ref: 'master' | ||
| }) | ||
| const migratedPrefixes = Buffer.from(migratedMods.data.content, 'base64') | ||
| .toString() | ||
| .split('\n') | ||
| .map(l => l.trim()) | ||
| .filter(l => l && !l.startsWith('#')) | ||
|
|
||
| // Get all files changed in this PR | ||
| const allFiles = await github.paginate(github.rest.pulls.listFiles, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.payload.pull_request.number | ||
| }) | ||
|
|
||
| // Filter these changed files to newly added Groovy files in any test source set | ||
| const addedGroovy = allFiles.filter(f => | ||
| f.status === 'added' && | ||
| /\/src\/[^/]*[tT]est[^/]*\/groovy\/.*\.groovy$/.test(f.filename) | ||
| ) | ||
|
|
||
| // Extract module prefix from file path (everything before /src/(test|testFixtures)/groovy/) | ||
| const moduleOf = path => { | ||
| const m = path.match(/^(.*?)\/src\/(test|testFixtures)\/groovy\//) | ||
| return m ? m[1] : null | ||
| } | ||
|
|
||
| // Classify each added Groovy file | ||
| const regressions = [] | ||
| const warnings = [] | ||
| for (const file of addedGroovy) { | ||
| const path = file.filename | ||
| const mod = moduleOf(path) | ||
| if (migratedPrefixes.some(prefix => path.startsWith(prefix + '/'))) { | ||
| regressions.push({ path, mod }) | ||
| } else if ( | ||
| path.startsWith('dd-java-agent/instrumentation/') || | ||
| path.startsWith('dd-smoke-tests/') | ||
| ) { | ||
| // ignore Groovy file additions to instrumentations and smoke-tests for now | ||
| } else { | ||
| warnings.push({ path, mod }) | ||
| } | ||
| } | ||
|
|
||
| // Fetch existing comments once | ||
| const comments = await github.rest.issues.listComments({ | ||
| issue_number: context.payload.pull_request.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }) | ||
|
|
||
| const regressionMarker = '<!-- dd-trace-java-groovy-regression -->' | ||
| const warningMarker = '<!-- dd-trace-java-groovy-warning -->' | ||
| const existingRegressionComment = comments.data.find(c => c.body.includes(regressionMarker)) | ||
| const existingWarningComment = comments.data.find(c => c.body.includes(warningMarker)) | ||
|
|
||
| // Handle regression comment | ||
| if (regressions.length > 0) { | ||
| const fileList = regressions | ||
| .map(({ path, mod }) => `- \`${path}\` (module: \`${mod}\`)`) | ||
| .join('\n') | ||
| const body = `**❌ Groovy Test Regression Detected**\n\n` + | ||
| `The following files add Groovy tests to modules that have been fully migrated to Java / JUnit 5:\n\n` + | ||
| `${fileList}\n\n` + | ||
| `These modules no longer accept Groovy test files. Please rewrite the test in Java / JUnit 5 instead.\n\n` + | ||
| regressionMarker | ||
| if (existingRegressionComment) { | ||
| await github.rest.issues.updateComment({ | ||
| comment_id: existingRegressionComment.id, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body | ||
| }) | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| issue_number: context.payload.pull_request.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body | ||
| }) | ||
| } | ||
| } else if (existingRegressionComment) { | ||
| await github.rest.issues.deleteComment({ | ||
| comment_id: existingRegressionComment.id, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }) | ||
| } | ||
|
|
||
| // Handle warning comment | ||
| if (warnings.length > 0) { | ||
| const fileList = warnings | ||
| .map(({ path, mod }) => `- \`${path}\` (module: \`${mod}\`)`) | ||
| .join('\n') | ||
| const body = `**⚠️ New Groovy Test Files Added**\n\n` + | ||
| `The following files add Groovy tests to modules that are candidates for migration to Java / JUnit 5:\n\n` + | ||
| `${fileList}\n\n` + | ||
| `Consider writing these tests in Java / JUnit 5 instead to help with the ongoing migration effort.\n\n` + | ||
| warningMarker | ||
| if (existingWarningComment) { | ||
| await github.rest.issues.updateComment({ | ||
| comment_id: existingWarningComment.id, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body | ||
| }) | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| issue_number: context.payload.pull_request.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body | ||
| }) | ||
| } | ||
| } else if (existingWarningComment) { | ||
| await github.rest.issues.deleteComment({ | ||
| comment_id: existingWarningComment.id, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }) | ||
| } | ||
|
|
||
| // Fail the check if there are regressions | ||
| if (regressions.length > 0) { | ||
| core.setFailed(`${regressions.length} Groovy regression(s) detected in migrated module(s). See PR comment for details. To skip this check entirely, add the 'tag: override-groovy-enforcement' label.`) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.