Skip to content

Commit 2b5f3b0

Browse files
committed
feat: add option to set custom remote
1 parent 1b8620e commit 2b5f3b0

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@ jobs:
7272
```yaml
7373
- uses: nrwl/nx-set-shas@v4
7474
with:
75+
# The GitHub token used to perform git operations
76+
#
77+
# Default: ${ github.token }
78+
gh-token: ''
79+
7580
# The "main" branch of your repository (the base branch which you target with PRs).
7681
# Common names for this branch include main and master.
7782
#
78-
# Default: main
83+
# Default: "main"
7984
main-branch-name: ''
8085

86+
# The name of the remote to fetch from
87+
#
88+
# Default: "origin"
89+
remote: ''
90+
8191
# Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job.
8292
#
8393
# Default: true
@@ -89,18 +99,16 @@ jobs:
8999
error-on-no-successful-workflow: ''
90100

91101
# Fallback SHA to use if no successful workflow run is found. This can be useful in scenarios where you need a specific commit as a reference for comparison, especially in newly set up repositories or those with sparse workflow runs.
92-
#
93-
# Default: ""
94102
fallback-sha: ''
95103

96104
# The type of event to check for the last successful commit corresponding to that workflow-id, e.g. push, pull_request, release etc.
97105
#
98-
# Default: push
106+
# Default: "push"
99107
last-successful-event: ''
100108

101109
# The path where your repository is. This is only required for cases where the repository code is checked out or moved to a specific path.
102110
#
103-
# Default: .
111+
# Default: "."
104112
working-directory: ''
105113

106114
# The ID of the github action workflow to check for successful run or the name of the file name containing the workflow.

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
main-branch-name:
99
description: 'The name of the main branch in your repo, used as the target of PRs. E.g. main, master etc'
1010
default: 'main'
11+
remote:
12+
description: 'The name of the remote to fetch from'
13+
default: 'origin'
1114
set-environment-variables-for-job:
1215
description: 'Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job'
1316
default: 'true'

dist/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29941,6 +29941,7 @@ const lastSuccessfulEvent = core.getInput('last-successful-event');
2994129941
const workingDirectory = core.getInput('working-directory');
2994229942
const workflowId = core.getInput('workflow-id');
2994329943
const fallbackSHA = core.getInput('fallback-sha');
29944+
const remote = core.getInput('remote');
2994429945
const defaultWorkingDirectory = '.';
2994529946
let BASE_SHA;
2994629947
(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -29962,7 +29963,7 @@ let BASE_SHA;
2996229963
!github.context.payload.pull_request.merged) {
2996329964
const baseResult = (0, child_process_1.spawnSync)('git', [
2996429965
'merge-base',
29965-
`origin/${github.context.payload[eventName].base.ref}`,
29966+
`${remote}/${github.context.payload[eventName].base.ref}`,
2996629967
'HEAD',
2996729968
], { encoding: 'utf-8' });
2996829969
BASE_SHA = baseResult.stdout;
@@ -29988,14 +29989,14 @@ let BASE_SHA;
2998829989
}
2998929990
else {
2999029991
process.stdout.write('\n');
29991-
process.stdout.write(`WARNING: Unable to find a successful workflow run on 'origin/${mainBranchName}', or the latest successful workflow was connected to a commit which no longer exists on that branch (e.g. if that branch was rebased)\n`);
29992+
process.stdout.write(`WARNING: Unable to find a successful workflow run on '${remote}/${mainBranchName}', or the latest successful workflow was connected to a commit which no longer exists on that branch (e.g. if that branch was rebased)\n`);
2999229993
if (fallbackSHA) {
2999329994
BASE_SHA = fallbackSHA;
2999429995
process.stdout.write(`Using provided fallback SHA: ${fallbackSHA}\n`);
2999529996
}
2999629997
else {
2999729998
// Check if HEAD~1 exists, and if not, set BASE_SHA to the empty tree hash
29998-
const LAST_COMMIT_CMD = `origin/${mainBranchName}~1`;
29999+
const LAST_COMMIT_CMD = `${remote}/${mainBranchName}~1`;
2999930000
const baseRes = (0, child_process_1.spawnSync)('git', ['rev-parse', LAST_COMMIT_CMD], {
3000030001
encoding: 'utf-8',
3000130002
});
@@ -30009,7 +30010,7 @@ let BASE_SHA;
3000930010
process.stdout.write(`HEAD~1 does not exist. We are therefore defaulting to use the empty git tree hash as BASE.\n`);
3001030011
}
3001130012
else {
30012-
process.stdout.write(`We are therefore defaulting to use HEAD~1 on 'origin/${mainBranchName}'\n`);
30013+
process.stdout.write(`We are therefore defaulting to use HEAD~1 on '${remote}/${mainBranchName}'\n`);
3001330014
BASE_SHA = baseRes.stdout;
3001430015
}
3001530016
process.stdout.write('\n');
@@ -30021,7 +30022,7 @@ let BASE_SHA;
3002130022
}
3002230023
else {
3002330024
process.stdout.write('\n');
30024-
process.stdout.write(`Found the last successful workflow run on 'origin/${mainBranchName}'\n`);
30025+
process.stdout.write(`Found the last successful workflow run on '${remote}/${mainBranchName}'\n`);
3002530026
process.stdout.write(`Commit: ${BASE_SHA}\n`);
3002630027
}
3002730028
}
@@ -30046,10 +30047,10 @@ let BASE_SHA;
3004630047
}))();
3004730048
function reportFailure(branchName) {
3004830049
core.setFailed(`
30049-
Unable to find a successful workflow run on 'origin/${branchName}'
30050+
Unable to find a successful workflow run on '${remote}/${branchName}'
3005030051
NOTE: You have set 'error-on-no-successful-workflow' on the action so this is a hard error.
3005130052

30052-
Is it possible that you have no runs currently on 'origin/${branchName}'?
30053+
Is it possible that you have no runs currently on '${remote}/${branchName}'?
3005330054
- If yes, then you should run the workflow without this flag first.
3005430055
- If no, then you might have changed your git history and those commits no longer exist.`);
3005530056
}

find-successful-workflow.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const lastSuccessfulEvent = core.getInput('last-successful-event');
1818
const workingDirectory = core.getInput('working-directory');
1919
const workflowId = core.getInput('workflow-id');
2020
const fallbackSHA = core.getInput('fallback-sha');
21+
const remote = core.getInput('remote');
2122
const defaultWorkingDirectory = '.';
2223

2324
let BASE_SHA: string;
@@ -46,7 +47,7 @@ let BASE_SHA: string;
4647
'git',
4748
[
4849
'merge-base',
49-
`origin/${github.context.payload[eventName].base.ref}`,
50+
`${remote}/${github.context.payload[eventName].base.ref}`,
5051
'HEAD',
5152
],
5253
{ encoding: 'utf-8' },
@@ -79,14 +80,14 @@ let BASE_SHA: string;
7980
} else {
8081
process.stdout.write('\n');
8182
process.stdout.write(
82-
`WARNING: Unable to find a successful workflow run on 'origin/${mainBranchName}', or the latest successful workflow was connected to a commit which no longer exists on that branch (e.g. if that branch was rebased)\n`,
83+
`WARNING: Unable to find a successful workflow run on '${remote}/${mainBranchName}', or the latest successful workflow was connected to a commit which no longer exists on that branch (e.g. if that branch was rebased)\n`,
8384
);
8485
if (fallbackSHA) {
8586
BASE_SHA = fallbackSHA;
8687
process.stdout.write(`Using provided fallback SHA: ${fallbackSHA}\n`);
8788
} else {
8889
// Check if HEAD~1 exists, and if not, set BASE_SHA to the empty tree hash
89-
const LAST_COMMIT_CMD = `origin/${mainBranchName}~1`;
90+
const LAST_COMMIT_CMD = `${remote}/${mainBranchName}~1`;
9091

9192
const baseRes = spawnSync('git', ['rev-parse', LAST_COMMIT_CMD], {
9293
encoding: 'utf-8',
@@ -108,7 +109,7 @@ let BASE_SHA: string;
108109
);
109110
} else {
110111
process.stdout.write(
111-
`We are therefore defaulting to use HEAD~1 on 'origin/${mainBranchName}'\n`,
112+
`We are therefore defaulting to use HEAD~1 on '${remote}/${mainBranchName}'\n`,
112113
);
113114

114115
BASE_SHA = baseRes.stdout;
@@ -125,7 +126,7 @@ let BASE_SHA: string;
125126
} else {
126127
process.stdout.write('\n');
127128
process.stdout.write(
128-
`Found the last successful workflow run on 'origin/${mainBranchName}'\n`,
129+
`Found the last successful workflow run on '${remote}/${mainBranchName}'\n`,
129130
);
130131
process.stdout.write(`Commit: ${BASE_SHA}\n`);
131132
}
@@ -158,10 +159,10 @@ let BASE_SHA: string;
158159

159160
function reportFailure(branchName: string): void {
160161
core.setFailed(`
161-
Unable to find a successful workflow run on 'origin/${branchName}'
162+
Unable to find a successful workflow run on '${remote}/${branchName}'
162163
NOTE: You have set 'error-on-no-successful-workflow' on the action so this is a hard error.
163164
164-
Is it possible that you have no runs currently on 'origin/${branchName}'?
165+
Is it possible that you have no runs currently on '${remote}/${branchName}'?
165166
- If yes, then you should run the workflow without this flag first.
166167
- If no, then you might have changed your git history and those commits no longer exist.`);
167168
}

0 commit comments

Comments
 (0)