Skip to content

ci: add script to check for .changelog file in PRs#9641

Merged
alvin-huang merged 3 commits into
masterfrom
ci/changelog-check
Feb 1, 2021
Merged

ci: add script to check for .changelog file in PRs#9641
alvin-huang merged 3 commits into
masterfrom
ci/changelog-check

Conversation

@alvin-huang
Copy link
Copy Markdown
Contributor

#8387 added go-changelog which generates changelog entries from the .changelog directory. This PR adds a small CI check to add a comment to any PR that does not have the pr/no-changelog label to remind the author to double check that the PR does not require a changelog entry.

@alvin-huang alvin-huang requested a review from a team January 26, 2021 18:56
@github-actions github-actions Bot added the type/ci Relating to continuous integration (CI) tooling for testing or releases label Jan 26, 2021
Copy link
Copy Markdown
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Nice! Thank you for working on this!

One suggestion for allowing this to work with fork PRs from external contributors.

Comment thread .circleci/config.yml Outdated
Comment on lines 1119 to 1120
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.

I guess this means that the check will only work for internal contributions, is that right?

I think it is equally important to have this check run on PRs from external contributors so that we don't have to ask them every time to add a changelog entry.

We should be able to accomplish that by using github actions to do this work instead of circleCI. If we use pull_request_target (https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target), which will run using the code from the master branch.

This should allow us to run the check for external contributions as well.

Comment thread .circleci/scripts/changelog-check.sh Outdated
Comment on lines 31 to 32
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.

I think by using github actions we can get this information without an API call by using the github context github.event.pull_request.base.ref and github.event.pull_request.labels.

Comment thread .circleci/scripts/changelog-check.sh Outdated
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.

I guess using github actions with pull_request_target would require a git checkout to get this list of changed files, since the available code will be of the target branch (master).

@alvin-huang
Copy link
Copy Markdown
Contributor Author

@dnephin Thanks for the review! Yes after looking over this, doing all the GitHub API calls to get the various pieces I need seems cumbersome. I also realized CIRCLE_PULL_REQUEST populates weirdly in that you push up a dev branch and then open a PR in the GitHub UI but by virtue of pushing up that dev branch, Circle will run that and not see that as part of a PR. When the PR is created, it doesn't rerun the tests since that commit already ran and therefore never sets CIRCLE_PULL_REQUEST unless you update the PR with another commit after the PR is created.

Will pivot to using GitHub actions to implement this logic instead. That should make the conditionals cleaner.

@vercel vercel Bot temporarily deployed to Preview – consul January 26, 2021 22:23 Inactive
@vercel vercel Bot temporarily deployed to Preview – consul-ui-staging January 26, 2021 22:23 Inactive
@vercel vercel Bot temporarily deployed to Preview – consul January 26, 2021 22:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – consul-ui-staging January 26, 2021 22:24 Inactive
Copy link
Copy Markdown
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM, couple small suggestions on wording

Comment thread .github/workflows/changelog-check.yml Outdated
if [ -z "$changelog_files" ]; then
# post PR comment to GitHub when no .changelog entry was found on PR
echo "changelog-check: Did not find a .changelog entry, posting a reminder in the PR"
github_message="🤔 Double check that this PR does not require a changelog entry in the .changelog directory. [Reference](https://github.com/hashicorp/consul/pull/8387)"
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.

In the future I guess we should try and document this under contributing/ and link to that instead. But since we don't have those docs yet, this seems good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'll keep this as unresolved so it's easier to find if we ever look at this PR again.

Comment on lines +2 to +4
# here: https://securitylab.github.com/research/github-actions-preventing-pwn-requests. But
# due to this workflow only running a git diff check and not building or publishing anything,
# there is no harm in checking out the PR HEAD code.
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.

I think the most likely risk here would be someone moving this logic into a script, and calling the script from this workflow.

I think it might help to clarify this point with something like this:

All the code checked out in this workflow should be considered untrusted. This workflow must never call any makefiles or scripts. It must never be changed to run any code from the checkout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's true. The only thing that gets 'written' back is a PR comment but the copied script on a PR wouldn't have access to the github token to do that.

That blurb is nice to have though, I'll add it!

Co-authored-by: Daniel Nephin <dnephin@hashicorp.com>
@vercel vercel Bot temporarily deployed to Preview – consul February 1, 2021 23:40 Inactive
@vercel vercel Bot temporarily deployed to Preview – consul-ui-staging February 1, 2021 23:40 Inactive
@vercel vercel Bot temporarily deployed to Preview – consul-ui-staging February 1, 2021 23:49 Inactive
@vercel vercel Bot temporarily deployed to Preview – consul February 1, 2021 23:49 Inactive
@alvin-huang alvin-huang merged commit d94c3b9 into master Feb 1, 2021
@alvin-huang alvin-huang deleted the ci/changelog-check branch February 1, 2021 23:51
@hashicorp-ci
Copy link
Copy Markdown
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/321216.

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

Labels

type/ci Relating to continuous integration (CI) tooling for testing or releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants