Added monthly scheduling and automation of container image tag#1658
Added monthly scheduling and automation of container image tag#1658aayushchouhan09 merged 1 commit intonoobaa:masterfrom
Conversation
WalkthroughWorkflow updated to auto-generate a container image tag using yesterday’s date, remove the manual tag input, add a monthly cron trigger, change the token secret, update branch/commit/PR references to the generated tag, and add an always-run cleanup step to delete the remote branch on failure. Changes
Sequence Diagram(s)sequenceDiagram
participant Scheduler as GitHub Scheduler
participant Workflow as update-noobaa-core-tag.yml
participant Repo as Git Repository
Scheduler->>Workflow: Trigger (monthly cron) / Manual dispatch
Workflow->>Workflow: Generate tag "master-YYYYMMDD" (yesterday) -> output container_image_tag
Workflow->>Repo: Create branch "update-core-tag-<container_image_tag>"
Workflow->>Repo: Commit & push changes using generated tag (uses GHACTION_TOKEN_PR_PERMS)
Workflow->>Repo: Create PR referencing generated tag (title/body/head use generated tag)
alt Always
Workflow->>Repo: On failure or completion - Cleanup: delete remote branch if exists
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
.github/workflows/update-noobaa-core-tag.yml (1)
41-47: Workflow continues after self-cancellationAfter invoking
gh run cancel, the script proceeds to later steps. Add an explicit exit to prevent wasted minutes and side-effects.- gh run cancel ${{ github.run_id }} + gh run cancel ${{ github.run_id }} + echo "Run canceled – exiting" + exit 0
🧹 Nitpick comments (2)
.github/workflows/update-noobaa-core-tag.yml (2)
4-6: Specify timezone for deterministic schedulingGitHub Actions cron schedules run in UTC by default. If “midnight on the first day of each month” is intended for a specific timezone (e.g., IST, PST), add
timezone:underschedule:to avoid accidental day-shifts.Example:
on: schedule: - cron: '0 0 1 * *' timezone: 'Asia/Kolkata'
53-57: Handle existing branch gracefully
git checkout -bfails if the branch already exists (e.g., re-run on the same day). Use-B(force) or fallback logic to reuse the branch.- git checkout -b update-core-tag-${{ steps.generate_tag.outputs.container_image_tag }} + git checkout -B update-core-tag-${{ steps.generate_tag.outputs.container_image_tag }}
54ff6ee to
a67846b
Compare
a67846b to
9a10d40
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🔭 Outside diff range comments (1)
.github/workflows/update-noobaa-core-tag.yml (1)
41-47: No-op cancellation: the job continues after gh run cancelCalling gh run cancel does not terminate the current job immediately; subsequent steps may still execute. Explicitly exit to prevent commits/PRs when no changes are detected.
if git diff --quiet pkg/options/options.go; then echo "Noobaa Core image tag is already up to date" echo "No changes needed - canceling workflow" gh run cancel ${{ github.run_id }} + # Ensure the job stops here to avoid creating branches/PRs + exit 0 fi
♻️ Duplicate comments (1)
.github/workflows/update-noobaa-core-tag.yml (1)
37-37: Critical: Expression is not interpolated due to single-quoted YAML stringInside single quotes, GitHub does not evaluate ${{ … }} expressions. The literal text will be written into options.go. Switch to double quotes and escape inner quotes.
- replace: 'ContainerImageTag = "${{ steps.generate_tag.outputs.container_image_tag }}"' + replace: "ContainerImageTag = \"${{ steps.generate_tag.outputs.container_image_tag }}\""
🧹 Nitpick comments (2)
.github/workflows/update-noobaa-core-tag.yml (2)
69-79: Consider avoiding --admin and add a safety timeout for checks--admin requires elevated privileges; if not strictly needed, omit it. Also, gh pr checks --watch can hang on stuck checks; consider adding a loop with a max wait or using --interval/--fail-fast if available in your gh version.
- gh pr checks "${{ steps.create_pr.outputs.pr_url }}" --watch + gh pr checks "${{ steps.create_pr.outputs.pr_url }}" --watch echo "Rebasing and merging PR..." - gh pr merge "${{ steps.create_pr.outputs.pr_url }}" --rebase --admin --delete-branch + gh pr merge "${{ steps.create_pr.outputs.pr_url }}" --rebase --delete-branch
26-32: Nit: Make timezone explicit to avoid edge casesRunners are UTC, but being explicit helps future-proofing and manual runs.
- tag="master-$(date -d 'yesterday' +%Y%m%d)" # using yesterday's date to ensure the image is available + TZ=UTC + tag="master-$(date -d 'yesterday' +%Y%m%d)" # using yesterday's date (UTC) to ensure the image is available
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/update-noobaa-core-tag.yml(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: run-azure-vault-test
- GitHub Check: run-kms-dev-test
- GitHub Check: run-kms-tls-sa-test
- GitHub Check: run-cli-tests
- GitHub Check: run-hac-test
- GitHub Check: cnpg-deployment-test
- GitHub Check: run-kms-kmip-test
- GitHub Check: run-core-config-map-tests
- GitHub Check: run-kms-tls-token-test
- GitHub Check: run-operator-tests
- GitHub Check: run-kms-key-rotate-test
- GitHub Check: run-admission-test
- GitHub Check: golangci-lint
🔇 Additional comments (3)
.github/workflows/update-noobaa-core-tag.yml (3)
26-32: LGTM: Deterministic tag generation using yesterday’s dateUsing master-$(date -d 'yesterday' +%Y%m%d) reduces flakiness when images lag publication.
4-6: LGTM: Monthly schedule trigger is appropriateThe cron trigger aligns with the monthly refresh goal and removes manual overhead.
17-19: Avoid overriding GITHUB_TOKEN; inject your PAT into GH_TOKEN instead
Overriding GITHUB_TOKEN replaces the job-scoped token (contents: write, pull-requests: write, actions: write) used by checkout and other actions. By moving your PAT to GH_TOKEN, you preserve the default GITHUB_TOKEN for built-in permissions.• File: .github/workflows/update-noobaa-core-tag.yml
• Location: job-levelenvblock- env: - GITHUB_TOKEN: ${{ secrets.GHACTION_TOKEN_PR_PERMS }} + env: + GH_TOKEN: ${{ secrets.GHACTION_TOKEN_PR_PERMS }}• We haven’t overridden
persist-credentials, so checkout will continue using the default GITHUB_TOKEN once the override is removed.Action items:
- Verify that
secrets.GHACTION_TOKEN_PR_PERMShas at least repo and workflow scopes (needed if you ever runghCLI commands).- Confirm that commits/pushes still succeed via the default runner-provided GITHUB_TOKEN.
Signed-off-by: Aayush <aayush@li-2392f9cc-287a-11b2-a85c-9fcc04b05da6.ibm.com>
9a10d40 to
c9ed6a2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
.github/workflows/update-noobaa-core-tag.yml (1)
69-79: Remove--adminto respect branch protection rulesThe
--adminflag ingh pr mergecan bypass branch protection requirements unless your protection rules explicitly apply to admins. Since this workflow already waits for all checks, it’s safer to remove--adminand rely on standard merges.Files to update:
- .github/workflows/update-noobaa-core-tag.yml (around lines 69–79)
Suggested diff:
- echo "Rebasing and merging PR..." - gh pr merge "${{ steps.create_pr.outputs.pr_url }}" --rebase --admin --delete-branch + echo "Merging PR after checks pass..." + gh pr merge "${{ steps.create_pr.outputs.pr_url }}" --rebase --delete-branchAction items:
- Remove the
--adminflag to prevent unintended bypass of protections.- Confirm whether your org’s branch protection settings already enforce rules for admins.
- If your policy discourages rebasing, consider switching to
--mergeinstead of--rebase.
♻️ Duplicate comments (3)
.github/workflows/update-noobaa-core-tag.yml (3)
36-38: Fix string interpolation in replace input (use double-quoted YAML string)Single-quoted YAML may pass the literal text without evaluating the expression. Use double quotes so ${{ ... }} is interpolated at runtime, and escape the inner quotes.
Apply this diff:
- replace: 'ContainerImageTag = "${{ steps.generate_tag.outputs.container_image_tag }}"' + replace: "ContainerImageTag = \"${{ steps.generate_tag.outputs.container_image_tag }}\""
61-66: Make PR creation idempotent (avoid failure when PR already exists)gh pr create fails if a PR for the head branch already exists, causing an unnecessary job failure and cleanup. Use a view-or-create flow.
Apply this diff:
- PR_URL=$(gh pr create \ - --title "Update ContainerImageTag to ${{ steps.generate_tag.outputs.container_image_tag }}" \ - --body "Automated update of ContainerImageTag to ${{ steps.generate_tag.outputs.container_image_tag }} in options.go" \ - --head update-core-tag-${{ steps.generate_tag.outputs.container_image_tag }} \ - --base master) + set -e + HEAD_BRANCH="update-core-tag-${{ steps.generate_tag.outputs.container_image_tag }}" + PR_URL=$(gh pr view --head "$HEAD_BRANCH" --json url -q .url 2>/dev/null || true) + if [ -z "$PR_URL" ]; then + PR_URL=$(gh pr create \ + --title "Update ContainerImageTag to ${{ steps.generate_tag.outputs.container_image_tag }}" \ + --body "Automated update of ContainerImageTag to ${{ steps.generate_tag.outputs.container_image_tag }} in options.go" \ + --head "$HEAD_BRANCH" \ + --base master) + fi
81-88: Scope cleanup to failures and skip deletion when a PR existsalways() risks deleting a branch even on success or when PR already exists (e.g., create step failed due to “PR exists”). Restrict to failure() and guard on PR existence.
Apply this diff:
- - name: Cleanup branch on failure - if: always() + - name: Cleanup branch on failure + if: failure() run: | branch_name="update-core-tag-${{ steps.generate_tag.outputs.container_image_tag }}" - if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then - echo "Branch $branch_name still exists, deleting..." - git push origin --delete "$branch_name" - fi + if gh pr view --head "$branch_name" >/dev/null 2>&1; then + echo "PR exists for $branch_name; skipping deletion." + exit 0 + fi + if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then + echo "Branch $branch_name still exists, deleting..." + git push origin --delete "$branch_name" || true + fi
🧹 Nitpick comments (5)
.github/workflows/update-noobaa-core-tag.yml (5)
41-47: Short-circuit the job after “no changes” and make cancel robustIf gh run cancel fails (token/perm), the job continues. Also, explicitly exit to avoid racing on cancellation.
Apply this diff:
if git diff --quiet pkg/options/options.go; then echo "Noobaa Core image tag is already up to date" echo "No changes needed - canceling workflow" - gh run cancel ${{ github.run_id }} + gh run cancel ${{ github.run_id }} || echo "Warning: failed to cancel run (insufficient permissions?)" + echo "Exiting job cleanly." + exit 0 fi
18-18: Verify secret scope; consider avoiding long-lived PAT if possibleYou’re overriding GITHUB_TOKEN with secrets.GHACTION_TOKEN_PR_PERMS for the entire job. Ensure it has only the minimum scopes needed (repo, pull_request; avoid admin:org, workflow unless required). If you drop --admin, you can likely switch to the built-in GITHUB_TOKEN with explicit permissions block and remove the custom PAT, reducing risk.
Would you like a follow-up patch that removes the PAT and relies on GITHUB_TOKEN safely?
26-31: Date offset: confirm that “yesterday” aligns with available images on schedule and manual runsUsing date -d 'yesterday' is fine on ubuntu-latest, but:
- On the monthly schedule at 00:00 UTC on the 1st, this targets the last day of the previous month—confirm that’s the intended image.
- On manual runs, “yesterday” depends on when someone runs it; consider parameterizing the offset for workflow_dispatch.
If you want deterministic monthly behavior while allowing overrides on manual runs, I can propose a flag for “days_offset” with a default of 1.
33-40: Constrain the regex to reduce accidental matchesThe find: 'ContainerImageTag = "[^"]*"' will match any similar assignment in the file. If options.go ever grows, anchor the match to the exact line to avoid unintended replacements.
Example tighter pattern (if the line starts exactly with the field):
- Use start-of-line anchor and optional whitespace:
find: '^\sContainerImageTag = "[^"]"'
Note: The action supports regex: true; ensure it is multiline-aware (it is by default).
8-12: Permissions: actions: write likely unnecessaryYou request actions: write, but this job doesn’t modify workflow files or dispatch other workflows. Drop it unless you need it, tightening least-privilege.
Proposed change outside this hunk:
- Remove the actions: write line from permissions if not strictly required.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/update-noobaa-core-tag.yml(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: run-cli-tests
- GitHub Check: run-kms-tls-token-test
- GitHub Check: run-kms-tls-sa-test
- GitHub Check: cnpg-deployment-test
- GitHub Check: run-kms-dev-test
- GitHub Check: run-kms-kmip-test
- GitHub Check: run-operator-tests
- GitHub Check: run-core-config-map-tests
- GitHub Check: golangci-lint
- GitHub Check: run-hac-test
- GitHub Check: run-admission-test
- GitHub Check: run-kms-key-rotate-test
- GitHub Check: run-azure-vault-test
Explain the changes
Automation: Replaced manual trigger with monthly cron schedule (0 0 1 * *) and auto-generated master-YYYYMMDD tags using $(date +%Y%m%d).Cleanup: Addedif: always()cleanup step that automatically removes orphaned branch if PR merge fails.GHACTIOIN_TOKEN_PR_PERMSIssues: Fixed #xxx / Gap #xxx
Testing Instructions:
noobaa-coreimage tag.Summary by CodeRabbit