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

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

Merged
merged 3 commits into from
Feb 1, 2021

Conversation

alvin-huang
Copy link
Collaborator

#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
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 on lines 1119 to 1120
- changelog-check:
context: team-consul
Copy link
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 on lines 31 to 32
base_branch=$(echo "$resp" | jq -r '.base.ref')
labels=$(echo "$resp" | jq --raw-output '.labels[] | .name')
Copy link
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.

exit 0
fi

changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "$base_branch")" -- .changelog/)
Copy link
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
Collaborator 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
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

.github/workflows/changelog-check.yml Outdated Show resolved Hide resolved
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
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
Collaborator 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
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
Collaborator 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
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