Skip to content

Commit c70a82f

Browse files
authored
Merge pull request #41 from github/fork-outputs
Fork Outputs
2 parents cdbf8ae + 285df1e commit c70a82f

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
263263
| comment_id | The comment id which triggered this deployment |
264264
| type | The type of trigger that was detected (examples: deploy, lock, unlock) |
265265
| continue | The string "true" if the deployment should continue, otherwise empty - Use this to conditionally control if your deployment should proceed or not |
266+
| fork | The string "true" if the pull request is a fork, otherwise "false" |
267+
| fork_ref | The true ref of the fork |
268+
| fork_label | The API label field returned for the fork |
269+
| fork_checkout | The console command presented in the GitHub UI to checkout a given fork locally |
266270

267271
## Custom Deployment Messages ✏️
268272

__tests__/functions/prechecks.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import dedent from 'dedent-js'
55
beforeEach(() => {
66
// jest.resetAllMocks()
77
jest.spyOn(core, 'info').mockImplementation(() => {})
8+
jest.spyOn(core, 'debug').mockImplementation(() => {})
9+
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
810
})
911

1012
// Globals for testing
@@ -430,6 +432,7 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch d
430432
head: {
431433
sha: 'abcde12345',
432434
ref: 'test-ref',
435+
label: 'test-repo:test-ref',
433436
repo: {
434437
fork: true
435438
}

action.yml

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ outputs:
7676
description: "The type of trigger that was detected (examples: deploy, lock, unlock)"
7777
continue:
7878
description: 'The string "true" if the deployment should continue, otherwise empty - Use this to conditionally control if your deployment should proceed or not'
79+
fork:
80+
description: 'The string "true" if the pull request is a fork, otherwise "false"'
81+
fork_ref:
82+
description: 'The true ref of the fork'
83+
fork_label:
84+
description: 'The API label field returned for the fork'
85+
fork_checkout:
86+
description: 'The console command presented in the GitHub UI to checkout a given fork locally'
7987
runs:
8088
using: "node16"
8189
main: "dist/index.js"

dist/index.js

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/prechecks.js

+13
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,30 @@ export async function prechecks(
4949
// Determine whether to use the ref or sha depending on if the PR is from a fork or not
5050
if (pr.data.head.repo?.fork === true) {
5151
core.info(`PR is from a fork, using sha instead of ref`)
52+
core.setOutput('fork', 'true')
5253

5354
// If this Action's inputs have been configured to explicitly prevent forks, exit
5455
if (allowForks === false) {
5556
message = `### ⚠️ Cannot proceed with deployment\n\nThis Action has been explicity configured to prevent deployments from forks. You can change this via this Action's inputs if needed`
5657
return {message: message, status: false}
5758
}
5859

60+
// Set some outputs specific to forks
61+
const label = pr.data.head.label
62+
const forkRef = pr.data.head.ref
63+
const forkCheckout = `${label.replace(':', '-')} ${forkRef}`
64+
core.setOutput('fork_ref', forkRef)
65+
core.setOutput('fork_label', label)
66+
core.setOutput('fork_checkout', forkCheckout)
67+
core.debug(`fork_ref: ${forkRef}`)
68+
core.debug(`fork_label: ${label}`)
69+
core.debug(`fork_checkout: ${forkCheckout}`)
70+
5971
// If this pull request is a fork, use the exact SHA rather than the branch name
6072
ref = pr.data.head.sha
6173
} else {
6274
// If this PR is NOT a fork, we can safely use the branch name
75+
core.setOutput('fork', 'false')
6376
ref = pr.data.head.ref
6477
}
6578

0 commit comments

Comments
 (0)