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

KAFKA-17628 New workflows for automating run approvals #17290

Merged
merged 7 commits into from
Sep 27, 2024

Conversation

mumrah
Copy link
Contributor

@mumrah mumrah commented Sep 26, 2024

This patch allows workflow runs to be controlled by the ci-approved label on Pull Requests. Rather than manually approving each workflow run explicitly, committers can now add the appropriate label and the new "CI Requested" and "PR Labeled" workflows will auto-approve the requested run.

@github-actions github-actions bot added the build Related to the Github or Jenkins builds label Sep 26, 2024
@chia7712
Copy link
Contributor

The build error is related to #17165 (comment)

@mumrah
Copy link
Contributor Author

mumrah commented Sep 26, 2024

Here's a demo from my fork. Thanks to @apoorvmittal10 for testing this out :)

PR: mumrah#22
CI: https://github.com/mumrah/kafka/actions/runs/11059371528 (ignore that it failed, unrelated)
CI Requested: https://github.com/mumrah/kafka/actions/runs/11059372000

When the PR was updated, the CI workflow run is created but needs approval. The CI Requested workflow the runs, examines the PR for the "ci-approval" label, then approves the run.

@lianetm
Copy link
Collaborator

lianetm commented Sep 26, 2024

The build error is fixed now, so getting the latest changes here should do.

@chia7712
Copy link
Contributor

@mumrah should we consider dropping approve-workflows.py since this PR offers a better solution?

@github-actions github-actions bot added the tools label Sep 26, 2024
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@mumrah thanks for this great patch!

.github/workflows/ci-requested.yml Outdated Show resolved Hide resolved
.github/workflows/ci-requested.yml Outdated Show resolved Hide resolved
.github/workflows/pr-labeled.yml Outdated Show resolved Hide resolved
.github/workflows/pr-labeled.yml Outdated Show resolved Hide resolved
RUN_ID: ${{ github.event.workflow_run.id }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_REPO: ${{ github.event.workflow_run.head_repository.owner.login }}
# Caution! This is a bit hacky. The GH documentation shows that the workflow_run event should include a list
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we switch to using pull_request_target along with the synchronize type to access github.event.number from the GitHub context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this might cause a race between the PR getting updated and the CI workflow being requested. By using "workflow_run" action "requested", we ensure the pending workflow exists.

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 this might cause a race between the PR getting updated and the CI workflow being requested. By using "workflow_run" action "requested", we ensure the pending workflow exists.

you are right

.github/workflows/pr-labeled.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM, but I left a small question in the comments

run: printenv
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Checkout code
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this job need to check out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did try it without and the gh command throws an error

run: printenv
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Checkout code
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@mumrah mumrah merged commit 00b1b1a into apache:trunk Sep 27, 2024
7 checks passed
@mumrah mumrah deleted the KAFKA-17628-automate-workflow-approvals branch September 27, 2024 00:17
bbejeck pushed a commit to bbejeck/kafka that referenced this pull request Sep 28, 2024
This patch allows workflow runs to be controlled by the ci-approved label on Pull Requests. Rather than manually approving each workflow run explicitly, committers can now add the appropriate label and the new "CI Requested" and "PR Labeled" workflows will auto-approve the requested run.

Reviewers: Chia-Ping Tsai <[email protected]>
airlock-confluentinc bot pushed a commit to confluentinc/kafka that referenced this pull request Sep 30, 2024
This patch allows workflow runs to be controlled by the ci-approved label on Pull Requests. Rather than manually approving each workflow run explicitly, committers can now add the appropriate label and the new "CI Requested" and "PR Labeled" workflows will auto-approve the requested run.

Reviewers: Chia-Ping Tsai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to the Github or Jenkins builds tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants