Skip to content

ci(pingcap-qe/ci): add PR content policy check#4476

Merged
ti-chi-bot[bot] merged 4 commits intomainfrom
fix/update-replay-jenkins-controller-address
Apr 7, 2026
Merged

ci(pingcap-qe/ci): add PR content policy check#4476
ti-chi-bot[bot] merged 4 commits intomainfrom
fix/update-replay-jenkins-controller-address

Conversation

@wuhuizuo
Copy link
Copy Markdown
Contributor

@wuhuizuo wuhuizuo commented Apr 7, 2026

This pull request introduces a new content policy check for pull requests, updates Jenkins URLs to a new domain, and improves container image management and security in CI pipelines. The major changes include adding a script and Prow job to enforce PR content rules, updating Jenkins references from the old to the new domain, enhancing Renovate configuration to update container images in YAML files, and upgrading the flux-cli container image for better security and features.

Pull Request Content Policy Enforcement:

  • Added .ci/check-pr-content-policy.sh, a script to check added lines in pull requests for forbidden substrings and unauthorized pingcap.net hosts, with reporting and usage instructions.
  • Integrated the new content policy check as a required presubmit job pull-verify-pr-content-policy in prow-jobs/pingcap-qe/ci/presubmits.yaml, ensuring all PRs to main are validated.

Jenkins URL Migration:

  • Updated all references to the Jenkins root URL from https://do.pingcap.net/jenkins to https://prow.tidb.net/jenkins in scripts, documentation, and usage examples (.ci/replay-jenkins-build.sh, .agents/skills/test-jenkins-pipeline-changes-in-pr-by-replaying/SKILL.md). [1] [2] [3] [4] [5]

Container Image Management Improvements:

  • Enhanced .github/renovate.json with a custom manager to automatically update container images referenced in pipelines/ and prow-jobs/ YAML files.

CI Pipeline Security and Maintenance:

  • Upgraded flux-cli container images in multiple Prow job configurations to version v2.2.3 for improved security and features (prow-jobs/pingcap-qe/ci/presubmits.yaml, prow-jobs/ti-community-infra/configs/presubmits.yaml). [1] [2] [3]

The job is short-term for migration, it will be deprecated in future.

wuhuizuo added 4 commits April 7, 2026 16:16
Update flux-cli image from v2.0.0-rc.4 to v2.2.3 in presubmit jobs for
pingcap-qe/ci and ti-community-infra/configs repositories.
Add a new presubmit job `pull-verify-pr-content-policy` that runs the
newly added `.ci/check-pr-content-policy.sh` script. The script scans
added lines in PRs for policy violations, currently checking for
forbidden literal substrings and unauthorized pingcap.net hosts.
Copy link
Copy Markdown

@ti-chi-bot ti-chi-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already done a preliminary review for you, and I hope to help you do a better job.

Summary

This pull request introduces a new content policy check for PRs, enforces it via a presubmit Prow job, migrates Jenkins URLs to a new domain, and improves container image management and security in CI pipelines. The approach is well-structured, with a clear separation of responsibilities across scripts and configuration updates. The overall quality is good, but there are opportunities for improvement in error handling, testing coverage, and edge case handling in the policy check script.


Critical Issues

  1. Error Handling in check-pr-content-policy.sh (Lines 171-173)

    • Issue: The script fails silently if grep doesn't match any patterns during host validation (grep returns a non-zero exit code which is ignored). This could lead to missing important violations.
    • File: .ci/check-pr-content-policy.sh
    • Suggestion:
      Replace the pipeline with an explicit check to handle grep's exit code:
      while IFS= read -r host; do
          [[ -z "$host" ]] && continue
          lower_host="${host,,}"
          if ! is_allowed_pingcap_host "$lower_host"; then
              append_unique_value "contains forbidden host ${lower_host}" "$reasons_name"
          fi
      done < <(grep -ioE "$PINGCAP_HOST_PATTERN" <<<"$content" || true)
      Add a test case to verify behavior when no matches occur.
  2. Memory Resource Allocation for the New Prow Job

    • Issue: The memory limit for the pull-verify-pr-content-policy job is set to 128Mi, which may be insufficient for larger diffs with many violations.
    • File: prow-jobs/pingcap-qe/ci/presubmits.yaml (Line 18)
    • Suggestion: Increase the memory limit to 256Mi to accommodate larger diffs and avoid potential OOM errors during policy checks.

Code Improvements

  1. Edge Case Handling in check-pr-content-policy.sh (Lines 83-88)

    • Issue: The script doesn't account for situations where no BASE_SHA is provided but a diff is generated anyway (e.g., an empty repository state or invalid SHA).
    • File: .ci/check-pr-content-policy.sh
    • Suggestion:
      Add an explicit check for a valid BASE_SHA:
      if [[ "$(git diff --name-only "$BASE_SHA" HEAD | wc -l)" -eq 0 ]]; then
          fatal "No changes detected between $BASE_SHA and HEAD. Ensure the base SHA is correct."
      fi
  2. Regex Manager in Renovate Configuration

    • Issue: The managerFilePatterns property in .github/renovate.json is overly broad and may unintentionally attempt updates in unrelated YAML files.
    • File: .github/renovate.json (Lines 7-17)
    • Suggestion: Narrow the pattern to exclude non-CI YAML files:
      "managerFilePatterns": ["/^pipelines/.*\\.ya?ml$/", "/^prow-jobs/.*\\.ya?ml$/"]

Best Practices

  1. Testing Coverage for check-pr-content-policy.sh

    • Issue: The script lacks unit tests for critical functions like is_allowed_pingcap_host and collect_policy_reasons.
    • File: .ci/check-pr-content-policy.sh
    • Suggestion: Add a suite of test cases using bats or another Bash testing framework. Include tests for:
      • Valid and invalid hosts
      • Content with forbidden substrings
      • Multiple violations in a single line
  2. Documentation for New Presubmit Job

    • Issue: No documentation exists for the new pull-verify-pr-content-policy job.
    • File: prow-jobs/pingcap-qe/ci/presubmits.yaml
    • Suggestion:
      Add a comment block at the top of the YAML file explaining the purpose of the job and how violations are reported. Example:
      # pull-verify-pr-content-policy:
      # Ensures PRs comply with repository content policy by checking added lines for forbidden substrings and hosts.
      # Violations are reported in the job logs.
  3. Consistency in Security Context Defaults

    • Issue: Security context definitions for upgraded flux-cli containers are inconsistent across presubmit jobs.
    • Files: prow-jobs/pingcap-qe/ci/presubmits.yaml (Line 131), prow-jobs/ti-community-infra/configs/presubmits.yaml (Lines 84, 112)
    • Suggestion:
      Define shared security context properties globally or ensure consistency across jobs:
      securityContext:
        runAsUser: 0
        allowPrivilegeEscalation: false

Summary of Action Items

  • Improve error handling and edge case validation in check-pr-content-policy.sh.
  • Adjust memory limits for the new presubmit job.
  • Narrow Renovate regex patterns to avoid unintended updates.
  • Add unit tests for the new script.
  • Document the new CI job and ensure consistent security configurations.

These changes will improve robustness, maintainability, and security of the CI pipeline and related scripts.

Copy link
Copy Markdown
Contributor

@dillon-zheng dillon-zheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 7, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dillon-zheng

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the lgtm label Apr 7, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 7, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-07 09:14:39.991859463 +0000 UTC m=+861285.197219520: ☑️ agreed by dillon-zheng.

@ti-chi-bot ti-chi-bot bot added the approved label Apr 7, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request transitions the default Jenkins URL to prow.tidb.net/jenkins, introduces a script and Prow job to enforce PR content policies, and adds a Renovate custom manager for container image updates. It also bumps the flux-cli version in CI configurations. Review feedback suggests correcting a directory path in the Renovate config and improving the regex in the content policy script to handle word boundaries and the root domain correctly.

"customType": "regex",
"datasourceTemplate": "docker",
"versioningTemplate": "docker",
"managerFilePatterns": ["/(^|/)(jobs/pipelines|prow-jobs)/.+\\.ya?ml$/"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The managerFilePatterns for the custom Renovate manager seems to have a typo. It uses jobs/pipelines, but based on the repository structure and other CI configurations, the directory for pipeline Groovy and pod YAML files is simply pipelines/. This will cause Renovate to miss container image updates in those files.

Suggested change
"managerFilePatterns": ["/(^|/)(jobs/pipelines|prow-jobs)/.+\\.ya?ml$/"],
"managerFilePatterns": ["/(^|/)(pipelines|prow-jobs)/.+\\.ya?ml$/"],

continue
fi
append_unique_value "contains forbidden host ${lower_host}" "$reasons_name"
done < <(printf '%s\n' "$content" | grep -ioE "$PINGCAP_HOST_PATTERN" || true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current regex for matching pingcap.net hosts might lead to false positives if the pattern is part of a larger domain (e.g., foo.pingcap.net.example.com). Consider adding word boundaries to ensure it only matches full hostnames.

Suggested change
done < <(printf '%s\n' "$content" | grep -ioE "$PINGCAP_HOST_PATTERN" || true)
done < <(printf '%s\n' "$content" | grep -ioE "\\b$PINGCAP_HOST_PATTERN\\b" || true)


set -euo pipefail

readonly PINGCAP_HOST_PATTERN='([[:alnum:]-]+\.)+pingcap\.net'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PINGCAP_HOST_PATTERN regex requires at least one subdomain (e.g., foo.pingcap.net). If the policy is intended to also restrict the root domain pingcap.net (unless explicitly allowed), the pattern should be adjusted to make the subdomain part optional.

Suggested change
readonly PINGCAP_HOST_PATTERN='([[:alnum:]-]+\.)+pingcap\.net'
readonly PINGCAP_HOST_PATTERN='([[:alnum:]-]+\\.)*pingcap\\.net'

@ti-chi-bot ti-chi-bot bot merged commit f3d0a9c into main Apr 7, 2026
4 checks passed
@ti-chi-bot ti-chi-bot bot deleted the fix/update-replay-jenkins-controller-address branch April 7, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants