-
Notifications
You must be signed in to change notification settings - Fork 24
ci: update status when action triggered by issue comment #262
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: linux-system-roles/postfix
Length of output: 18396
🤖 get_repo_knowledge executed:
get_repo_knowledge linux-system-roles/postfix /tmp/coderabbit-repo-knowledge/linux-system-roles-postfix-7a48cbc9/conventionsLength of output: 5492
🌐 Web query:
GitHub Actions issue_comment event github.sha default branch commit documentation💡 Result:
When a GitHub Actions workflow is triggered by the issue_comment event, the GITHUB_SHA environment variable (and the github.sha context property) defaults to the commit SHA of the default branch of the repository, rather than the tip of the pull request branch associated with the comment [1][2]. This behavior occurs because the issue_comment event is triggered by the repository's activity, and the workflow itself must exist on the default branch to execute [3][4][5]. Since there is no inherent "pull request commit" context tied to a comment in the same way there is for a push or pull_request event, GitHub defaults to the head commit of the base branch [1]. To work with the correct commit SHA of a pull request when triggered by an issue_comment event, you must manually resolve it using the GitHub API [1][4]: 1. Use the github.event.issue.pull_request.url property (available in the event payload when the comment is on a pull request) to identify the associated pull request [3][5]. 2. Use the GitHub REST API or GraphQL API (often via actions/github-script) to fetch the pull request details, specifically the head.sha [4]. 3. Pass this resolved SHA to the actions/checkout step using the ref input [4]. Example of how to retrieve the PR head SHA: - name: Get PR head SHA id: get_pr_sha uses: actions/github-script@v7 with: script: | const { data: pull } = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.issue.number, }); return pull.head.sha; You can then use ${{ steps.get_pr_sha.outputs.result }} in subsequent steps, such as checking out the code [4].
Citations:
🌐 Web query:
myrotvorets/set-commit-status-action sha input action.yml commit status API💡 Result:
The myrotvorets/set-commit-status-action provides a
shainput to specify the SHA hash of the commit to be updated [1][2]. The behavior and default values for theshainput are as follows: - Purpose: It specifies the commit SHA hash for which the status should be set [1][3]. - Automatic Detection: The action can automatically determine the SHA for standard events [1][2]. It defaults to github.pull_request.head.sha for pull requests and github.sha for push events [1][4]. - Manual Override: For events where the SHA is not automatically detected (or if you wish to target a different commit), you must explicitly provide the SHA value via theshainput [1][3]. Usage in action.yml: You can provide theshainput in your workflow file within the with section of the action usage, as shown in the following example: - name: Set commit status uses: myrotvorets/set-commit-status-action@master with: sha: ${{ github.sha }} # Explicitly setting the SHA status: success context: My Context The action interacts with the GitHub Commit Status API to update the status of the specified commit [2][3]. Ensure the token provided (defaulting to github.token) has the required statuses: write permissions to successfully update the commit status [1][5].Citations:
Do not use
github.shaas the final-status fallback.If
Get PR head SHA and contextfails,always()still runs the final-status step. Onissue_comment,github.shaidentifies the default-branch commit, somyrotvorets/set-commit-status-actioncan post the result to the wrong commit.Require a nonempty
steps.head_sha_context.outputs.head_shain the final-step condition and pass that output directly asshain all four workflows.📍 Affects 4 files
.github/workflows/codespell.yml#L94-L94(this comment).github/workflows/markdownlint.yml#L115-L115.github/workflows/test_converting_readme.yml#L125-L125.github/workflows/woke.yml#L99-L99🤖 Prompt for AI Agents