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

Incorrect branch and sha sent to Code Climate when workflow triggered by pull_request_target event #627

Closed
mattseddon opened this issue Oct 20, 2022 · 2 comments · Fixed by #628, #746, #756 or #757
Assignees
Labels
bug Something isn't working released

Comments

@mattseddon
Copy link

Describe the bug

When a PR workflow is triggered by the pull_request_target event (required for sending secrets to forked repositories) the action sends the incorrect SHA + Branch details to Code Climate, which results in the coverage being posted on the target branch PR. It seems like the issue is here:

if (process.env.GITHUB_EVENT_NAME === 'pull_request') {

The line needs to be extended to include pull_request_trigger:

  if (
    process.env.GITHUB_EVENT_NAME &&
    ['pull_request', 'pull_request_target'].includes(
      process.env.GITHUB_EVENT_NAME
    )
  ) {
    env.GIT_BRANCH = process.env.GITHUB_HEAD_REF || env.GIT_BRANCH; // Report correct branch for PRs (See https://github.com/paambaati/codeclimate-action/issues/86)
    env.GIT_COMMIT_SHA = context.payload.pull_request?.['head']?.['sha']; // Report correct SHA for the head branch (See https://github.com/paambaati/codeclimate-action/issues/140)
  }

Version of codeclimate-action you're using
v3.1.1

Example links

Coverage for this PR: iterative/vscode-dvc#2645
Reported here: iterative/vscode-dvc#2644 (comment)

Expected behavior
A clear and concise description of what you expected to happen.

Coverage is reported on the correct PR for workflows triggered by pull_request_target.

Additional context
Seems related to the exact problems shown in #86 & See #140

I have forked the repository and made the appropriate changes locally. Would be happy to raise a PR if you let me know the basics of contributing to this repository (do I need to update the changelog, semver, etc?) 🙏🏻.

@mattseddon mattseddon added the bug Something isn't working label Oct 20, 2022
paambaati added a commit that referenced this issue Oct 21, 2022
github-actions bot pushed a commit that referenced this issue Oct 21, 2022
# [3.2.0](v3.1.0...v3.2.0) (2022-10-21)

### Bug Fixes

* **ci:** rebuild and republish to use new branch and workflows ([0c99fb3](0c99fb3))
* **ci:** use the un-broken latest version of the workflow ([0fe0643](0fe0643))

### Features

* **core:** support fork PRs. ([70a75ac](70a75ac)), closes [#627](#627)
@paambaati
Copy link
Owner

🎉 This issue has been resolved in version 3.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Apr 23, 2023
# [4.0.0](v3.1.0...v4.0.0) (2023-04-23)

### Bug Fixes

* **ci:** debug outputs ([11ed927](11ed927))
* **ci:** fix invalid YAML ([8f95f43](8f95f43))
* **ci:** fix the tag detection logic for new releases ([f787a56](f787a56))
* **ci:** rebuild and republish to use new branch and workflows ([0c99fb3](0c99fb3))
* **ci:** republish so latest changes get applied ([8f00eaa](8f00eaa))
* **ci:** republish so latest changes get applied ([fa71c1f](fa71c1f))
* **ci:** set up correct (?) condition to trigger publish ([3e9c9ce](3e9c9ce))
* **ci:** try once again to publish new version ([bcd27f6](bcd27f6))
* **ci:** use the un-broken latest version of the workflow ([0fe0643](0fe0643))
* **ci:** validate empty new release version ([2b9684a](2b9684a))
* **core:** support ARM 64-bit environments ([ea13673](ea13673))
* **core:** support ARM 64-bit environments ([99e22b3](99e22b3))

### Features

* **core:** cleanup downloaded artifacts ([f331896](f331896)), closes [#639](#639)
* **core:** support fork PRs. ([70a75ac](70a75ac)), closes [#627](#627)

### BREAKING CHANGES

* **ci:** semantic-release and its process is fundamentally broken when the repo moved from master to main for its main branch. This is an attempt to try to unfuck the git log/ref notes
@paambaati
Copy link
Owner

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment