Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
81 changes: 81 additions & 0 deletions .github/workflows/codelab-watchdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Codelab Parameter Watchdog

on:
pull_request:
types: [opened, synchronize, reopened, edited]
paths:
- '**/SourceDbToSpannerOptions.java'
- '**/DataStreamToSpanner.java'
- '**/SpannerToSourceDb.java'

jobs:
enforce-codelab-bug:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Validate Parameter Changes and PR Description
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
echo "Checking PR diff for template parameter changes..."
gh pr diff "$PR_NUMBER" --repo "$REPO" > pr_diff.txt

# Check if added (+) or removed (-) lines contain the parameter annotations
HAS_PARAM_CHANGES=false
if grep -E '^[+-].*(TemplateParameter|description|helpText|Validation\.Required)' pr_diff.txt | grep -v '^[+-]\{3\}' > /dev/null; then
HAS_PARAM_CHANGES=true
fi

if [ "$HAS_PARAM_CHANGES" = false ]; then
echo "✅ No template parameter definitions were modified. Skipping codelab bug requirement."
exit 0
fi

echo "⚠️ Template parameter changes detected."
MARKER="<!-- codelab-watchdog-comment -->"
COMMENT_URL=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" -q ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$MARKER\"))) | .url" | head -n 1)

if printf "%s\n" "$PR_BODY" | grep -E -q 'CODELAB_BUG=b/[0-9]+'; then
echo "✅ Found CODELAB_BUG tag in PR description. Workflow unblocked."

# If we previously left a warning comment, gracefully update it to green.
if [ -n "$COMMENT_URL" ]; then
echo "$MARKER" > comment.md
echo "✅ **Codelab Update Reminder Assured**" >> comment.md
echo "A \`CODELAB_BUG\` reference was found. Thank you for tracking the DevSite Codelab documentation updates!" >> comment.md
echo "" >> comment.md
echo "Please follow the step-by-step instructions in [go/update-migrations-codelabs](http://go/update-migrations-codelabs) to update the codelabs with your changes." >> comment.md
gh api -X PATCH "$COMMENT_URL" -F body=@comment.md || true
fi
exit 0
fi

# If CODELAB_BUG is missing, post the warning and fail
echo "❌ Missing CODELAB_BUG=b/XXXX in PR description."
echo "$MARKER" > comment.md
echo "🚨 **Codelab Update Required** 🚨" >> comment.md
echo "This PR modifies pipeline parameters documented in the Spanner Migration Codelabs." >> comment.md
echo "" >> comment.md
echo "**Action Required:**" >> comment.md
echo "To unblock this PR, please add a bug tracker reference to the PR description (e.g., \`CODELAB_BUG=b/12345678\`) confirming there is a ticket to update the codelabs." >> comment.md
echo "" >> comment.md
echo "Please follow the step-by-step instructions in [go/update-migrations-codelabs](http://go/update-migrations-codelabs) to update the codelabs with your changes." >> comment.md

# If the COMMENT_URL variable is not empty, it means we found an existing comment created by this bot.
# We PATCH (update) the existing comment to avoid spamming the PR with duplicate comments.
# If it is empty, we use 'gh pr comment' to create a brand new comment.
if [ -n "$COMMENT_URL" ]; then
gh api -X PATCH "$COMMENT_URL" -F body=@comment.md || true
else
gh pr comment "$PR_NUMBER" --body-file comment.md --repo "$REPO" || true
fi

echo "::error title=Codelab Update Required::This PR modifies pipeline parameters. To unblock this PR, add a bug tracker reference to the PR description (e.g., CODELAB_BUG=b/123456). Follow instructions in go/update-migrations-codelabs to update the documentation."
exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ public interface SourceDbToSpannerOptions extends CommonTemplateOptions {

void setSourceDbDialect(String sourceDatabaseDialect);

@TemplateParameter.Text(
order = 2,
optional = true,
regexes = {"^.+$"},
description = "Comma-separated Cloud Storage path(s) of the JDBC driver(s)",
helpText = "The comma-separated list of driver JAR files.",
example = "gs://your-bucket/driver_jar1.jar,gs://your-bucket/driver_jar2.jar")
@Default.String("")
String getJdbcDriverJars();

void setJdbcDriverJars(String driverJar);

@TemplateParameter.Text(
order = 3,
optional = true,
Expand Down
Loading