Skip to content

fix(workflow): fix DCO check #3512

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
merged 1 commit into from
Feb 4, 2025
Merged

Conversation

derekbit
Copy link
Member

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10193

What this PR does / why we need it:

Use head commit's author name and email as committer's information.

Special notes for your reviewer:

Additional documentation or context

@derekbit derekbit requested a review from innobead January 24, 2025 07:16
@derekbit derekbit self-assigned this Jan 24, 2025
Copy link

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request modifies the GitHub Actions workflow file for creating a pull request in the Longhorn repository. Two new steps are introduced to dynamically retrieve the head commit's author name and email. The "Create Pull Request" step is updated to use these dynamically obtained commit author details instead of hardcoded values, ensuring more accurate representation of the commit's authorship information.

Changes

File Change Summary
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml Added two new steps: "Get Head Commit Name" and "Get Head Commit Email" to dynamically retrieve commit author details. Modified "Create Pull Request" step to use these dynamic values for author and committer fields.

Assessment against linked issues

Objective Addressed Explanation
Automate CRDs and manifests patching PR creation [#10193] The PR does not address the automation of patching CRDs and manifests as specified in the issue.

Possibly related PRs

Suggested reviewers

  • innobead

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd68c49 and 947cd35.

📒 Files selected for processing (1)
  • .github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml

42-42: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)


46-46: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

⏰ 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)

57-58: LGTM! The changes correctly implement the DCO requirements.

The implementation properly uses the commit author's details for both author and committer fields, which aligns with the PR objective to fix the DCO check. The combination with sign-commits: true and signoff: true ensures proper commit signing.


Line range hint 3-7: Verify the security implications of using pull_request_target.

The workflow uses pull_request_target which runs with repository secrets. While this is necessary for creating PRs with tokens, please ensure that:

  1. The workflow doesn't execute any code from the PR
  2. The CRDs and manifests are fetched from the master branch of longhorn-manager, not the PR branch
✅ Verification successful

The workflow's security implementation for pull_request_target is correct

The workflow follows security best practices:

  • Only runs after PR is merged to master
  • Fetches CRDs directly from the master branch of longhorn-manager
  • Executes only trusted scripts from the base branch
  • Uses PR content only for metadata (PR number, title)
  • Properly scopes repository secrets for creating update PRs
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the workflow only uses trusted sources

# Check if the workflow fetches content from trusted sources
rg -l 'curl.*\$\{.*\}' .github/workflows/
rg -l 'wget.*\$\{.*\}' .github/workflows/

# Check if the workflow executes any potentially untrusted code
rg -l 'eval.*\$\{.*\}' .github/workflows/
rg -l 'source.*\$\{.*\}' .github/workflows/

Length of output: 177


Script:

#!/bin/bash
# Get the complete workflow content
cat .github/workflows/create-crd-update-pr-in-longhorn-repo.yml

# Search for actions/checkout usage in the workflow
rg "uses: actions/checkout@" .github/workflows/create-crd-update-pr-in-longhorn-repo.yml -A 5

# Search for any references to PR context or SHA
rg "github\.(event|sha|ref)" .github/workflows/create-crd-update-pr-in-longhorn-repo.yml

Length of output: 3570

🧰 Tools
🪛 actionlint (1.7.4)

42-42: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)


46-46: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

@@ -46,9 +54,8 @@ jobs:
delete-branch: true
sign-commits: true
signoff: true
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
committer: Longhorn GitHub Bot <67932897+longhorn-io-github-bot@users.noreply.github.com>
Copy link
Member

Choose a reason for hiding this comment

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

Do we know why the bot account with sign is not valid for DCO check?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea for now. Although I set the committer and author to Longhorn bot, the longhorn/longhorn PR will be created by the author of the longhorn/longhorn-manager PR rather than the Longhorn bot when triggering the workflow by pull_request_target. However, using the author of the longhorn/longhorn-manager PR might make sense.

Longhorn 10193

Signed-off-by: Derek Su <derek.su@suse.com>
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0427098 and d74b713.

📒 Files selected for processing (1)
  • .github/workflows/create-crd-update-pr-in-longhorn-repo.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/create-crd-update-pr-in-longhorn-repo.yml

42-42: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)


46-46: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

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

57-58: Dynamic Author and Committer Assignment

The "Create Pull Request" step now successfully uses the dynamic outputs (commit_name and commit_email) for setting the author and committer fields. This aligns well with the PR’s objective to use the head commit’s metadata for DCO compliance. Ensure that once you update the output commands as suggested above, the output variable names remain consistent.

Comment on lines +40 to +47
- name: Get Head Commit Name
id: get_head_commit_name
run: echo "::set-output name=commit_name::$(git log -1 --pretty=format:'%an')"

- name: Get Head Commit Email
id: get_head_commit_email
run: echo "::set-output name=commit_email::$(git log -1 --pretty=format:'%ae')"

Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Deprecated set-output Usage Confirmed in Workflow

The search result confirms that the workflow file still uses the deprecated ::set-output command at the following lines:

  • Line 42: Uses ::set-output for the commit name.
  • Line 46: Uses ::set-output for the commit email.

Please update these steps to use the $GITHUB_OUTPUT mechanism as detailed in the review comment to comply with the updated GitHub Actions guidelines.

🔗 Analysis chain

Update Deprecated set-output Commands

The steps "Get Head Commit Name" (line 42) and "Get Head Commit Email" (line 46) still use the deprecated ::set-output command. To comply with the current GitHub Actions guidelines, update these commands to use the $GITHUB_OUTPUT mechanism. For example, you could replace the current implementation with:

-      run: echo "::set-output name=commit_name::$(git log -1 --pretty=format:'%an')"
+      run: |
+        if ! commit_name=$(git log -1 --pretty=format:'%an'); then
+          echo "Failed to get commit author name" >&2
+          exit 1
+        fi
+        echo "commit_name=$commit_name" >> $GITHUB_OUTPUT

and similarly for the commit email:

-      run: echo "::set-output name=commit_email::$(git log -1 --pretty=format:'%ae')"
+      run: |
+        if ! commit_email=$(git log -1 --pretty=format:'%ae'); then
+          echo "Failed to get commit author email" >&2
+          exit 1
+        fi
+        echo "commit_email=$commit_email" >> $GITHUB_OUTPUT

This change aligns with the updated GitHub Actions syntax and resolves warnings from static analysis tools.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts or web queries found


Script:

#!/bin/bash
# Verify deprecated set-output commands in the workflow file
rg --line-number "::set-output" .github/workflows/create-crd-update-pr-in-longhorn-repo.yml

Length of output: 268

🧰 Tools
🪛 actionlint (1.7.4)

42-42: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)


46-46: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

@innobead innobead merged commit 469a446 into longhorn:master Feb 4, 2025
9 checks passed
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