-
Notifications
You must be signed in to change notification settings - Fork 12
chore(ci/deploy): run on contributors PR #373
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f1d2d81
draft
DarianM 1afa3f5
Merge branch 'main' into deploy-flow
DarianM b18305c
deployment permission check
DarianM 47d1130
github-script v8
DarianM 89b862b
Merge branch 'main' into deploy-flow
DarianM 0ed576b
types; improve check
DarianM 3b4ef0a
build: rmv skip-deploy check unnecessary build
DarianM 31b885d
Merge remote-tracking branch 'origin/main' into deploy-flow
DarianM 74d0714
update event name
DarianM 0e400ad
custom git diff for review events; dorny/paths-filter for normal PR e…
DarianM 97f6f34
revert
DarianM 0caa2db
one more try at run get diffs
DarianM 5e3b3bf
add comments
DarianM 73a2439
try remote install see if complains
DarianM cfb15f2
main
DarianM 99498b2
small conflict...
DarianM 62a6386
Merge branch 'main' into deploy-flow
DarianM 37ce61d
use `github-script` types
sidvishnoi d4d2097
pnpm approve-builds
sidvishnoi d1c5e07
simpler grep create var
DarianM c53f77e
merge workflow and shared
DarianM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import type * as core from '@actions/core'; | ||
| import type { Context } from '@actions/github/lib/context'; | ||
| import type { PullRequestEvent, PullRequestReviewEvent } from '@octokit/webhooks-types'; | ||
|
|
||
| interface Params { | ||
| core: typeof core; | ||
| context: Context & { | ||
| payload: PullRequestEvent | PullRequestReviewEvent; | ||
| }; | ||
| } | ||
|
|
||
| export default async function checkDeployPermissions({ core, context }: Params): Promise<void> { | ||
| if (context.eventName === 'pull_request_review') { | ||
| const event = context.payload as PullRequestReviewEvent; | ||
| const reviewerAssociation = event.review.author_association; | ||
|
|
||
| if (!isAllowedAuthor(reviewerAssociation)) { | ||
| await skipDeployment(core, 'Not authorized to trigger deployments.'); | ||
| return; | ||
| } | ||
|
|
||
| if (event.review.body === 'ok-to-deploy') { | ||
| core.setOutput('should-deploy', 'true'); | ||
| core.info('Deployment allowed: Triggered by maintainer review comment'); | ||
| return; | ||
| } | ||
|
|
||
| core.setOutput('should-deploy', 'false'); | ||
| core.info('No deployment command found in review'); | ||
| return; | ||
| } | ||
|
|
||
| if (context.eventName === 'pull_request') { | ||
| const event = context.payload as PullRequestEvent; | ||
| const authorAssociation = event.pull_request.author_association; | ||
|
|
||
| if (!isAllowedAuthor(authorAssociation)) { | ||
| await skipDeployment( | ||
| core, | ||
| 'The PR author is not authorized to run deployments. Maintainers can trigger a deployment by submitting a review with "pull-request-review" in the comment.' | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| core.setOutput('should-deploy', 'true'); | ||
| core.info('Deployment allowed: Authorized contributor'); | ||
| return; | ||
| } | ||
|
|
||
| // no deployment for other events | ||
| core.setOutput('should-deploy', 'false'); | ||
| core.info('Deployment not triggered for this event type'); | ||
| } | ||
|
|
||
| function isAllowedAuthor(authorAssociation: string): boolean { | ||
| return ( | ||
| authorAssociation === 'OWNER' || | ||
| authorAssociation === 'MEMBER' || | ||
| authorAssociation === 'COLLABORATOR' | ||
| ); | ||
| } | ||
|
|
||
| async function skipDeployment(coreApi: Params['core'], reason: string): Promise<void> { | ||
| coreApi.info('Skipping deployment for security reasons.'); | ||
| coreApi.setOutput('should-deploy', 'false'); | ||
| await coreApi.summary | ||
| .addQuote(`🚫 Deployment skipped: ${reason}`) | ||
| .addDetails( | ||
| 'Security Notice', | ||
| `Deployments are restricted to organization members, collaborators, and repository owners. | ||
| External contributors can still run builds and tests. | ||
| Maintainers can trigger deployments by reviewing the PR with "pull-request-review" in the comment.` | ||
| ) | ||
| .write(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.