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

Label PRs with change type according to changelog #1769

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lmolkova
Copy link
Contributor

@lmolkova lmolkova commented Jan 19, 2025

This allows to label PRs as "breaking" simplifying filtering and querying breaking changes before they are released.

Tested here lmolkova#6

Merge requirement checklist

@lmolkova lmolkova added the Skip Changelog Label to skip the changelog check label Jan 19, 2025
@lmolkova lmolkova requested review from a team as code owners January 19, 2025 21:35
.github/workflows/prepare-new-pr.yml Outdated Show resolved Hide resolved
Comment on lines 9 to 10
permissions:
pull-requests: write
Copy link
Member

Choose a reason for hiding this comment

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

I suspect this only worked in your test because the PR wasn't from a forked repo:

https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflows-in-forked-repositories

The GITHUB_TOKEN has read-only permissions in pull requests from forked repositories.

this kind of automation probably requires pull_request_target, which brings security considerations

Copy link
Contributor Author

@lmolkova lmolkova Jan 20, 2025

Choose a reason for hiding this comment

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

It was necessary in my fork and failed without it.
`I assume it should not even be necessary in the original repo since

gh issue edit "${ISSUE}" --add-label "${LABELS}" || true
runs perfectly fine without any permissions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! yeah, you're right.

So the pull_request_target executes workflows from the target branch (main) where the GH_TOKEN will be exposed to the version of this script checked into main. Is there any security concern with it?

I believe it's used today by collector and .net and in the https://github.com/open-telemetry/assign-reviewers-action, so I assume it's considered to be safe and ok to use

Copy link
Member

Choose a reason for hiding this comment

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

I believe it's used today by collector and .net and in the https://github.com/open-telemetry/assign-reviewers-action

these don't also check out the PR branch though, which is where things get tricky

e.g. you don't want to run a build on the PR branch, since PR could modify the build steps and print out secrets

your automation only needs to read a file, which sounds safe, but I'm not sure if the checkout alone could be compromised, e.g. by a post-checkout hook that prints out secrets (I'll test this... now I'm curious...)

Copy link
Member

@trask trask Jan 20, 2025

Choose a reason for hiding this comment

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

ah, git hooks have to be explicitly enabled after checkout, e.g. git config --local core.hooksPath .githooks/, so that seems safe

I'm good with pursuing this, just want to be careful about it

pull-requests: write
if: ${{ github.repository_owner == 'open-telemetry' }}
steps:
- uses: actions/checkout@v4
Copy link
Member

Choose a reason for hiding this comment

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

I think this defaults to checking out main after switching to pull_request_target (I suspect due to the security concerns), I think need:

Suggested change
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

echo "Change log file(s): ${CHLOG}"

if [ -z "$CHLOG" ]; then
echo "No changelog found in the PR. Ignoring this change."
Copy link
Member

@joaopgrassi joaopgrassi Jan 20, 2025

Choose a reason for hiding this comment

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

Trick here, because people may forget to add the changelog and this will only run on PR open. Once they add it later no label will be there. Maybe we also have to run it on push?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Label to skip the changelog check
Projects
Development

Successfully merging this pull request may close these issues.

3 participants