-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(circleci-orb): rebase script not working on windows
Fixes that the rebase script is not working on Windows by using `spawnSync` with `shell: true`. Like we do in the ng-dev git client (which we cannot use here). Also fixes that the rebease command fails if there is no user configured. We always set a user as part of rebasing. The user may be overriden later by other scripts- like the publish snapshots script.
- Loading branch information
1 parent
3846e48
commit 87ac315
Showing
4 changed files
with
48 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {exec, getCommonAncestorSha, lookupSha} from './helpers'; | ||
import {execGit, getCommonAncestorSha, lookupSha} from './helpers'; | ||
|
||
// Parameter variables. | ||
const baseRevision = process.env.CIRCLE_GIT_BASE_REVISION!; | ||
|
@@ -32,6 +32,10 @@ if (!process.env.CIRCLE_PR_NUMBER) { | |
|
||
/** Rebase on the latest commit for the targeted branch. */ | ||
(async () => { | ||
// Rebasing requires a Git user set. | ||
execGit(['config', 'user.email', '[email protected]']); | ||
execGit(['config', 'user.name', 'Angular Robot']); | ||
|
||
const base = lookupSha(baseRevision, baseRepoOwner, baseRepoName, primaryBranchName); | ||
const head = lookupSha(headRevision, headRepoOwner, headRepoName, primaryBranchName); | ||
const commonAncestorSha = getCommonAncestorSha(base.sha, head.sha); | ||
|
@@ -46,14 +50,20 @@ if (!process.env.CIRCLE_PR_NUMBER) { | |
console.log(); | ||
|
||
// Get the count of commits between the latest commit from origin and the common ancestor SHA. | ||
const commitCount = exec(`git rev-list --count origin/${base.ref}...${commonAncestorSha}`); | ||
const commitCount = execGit(['rev-list', '--count', `origin/${base.ref}...${commonAncestorSha}`]); | ||
console.log(`Checking ${commitCount} commits for changes in the CircleCI config file.`); | ||
|
||
// Check if the files changed between the latest commit from origin and the common ancestor SHA | ||
// includes the CircleCI config. | ||
const circleCIConfigChanged = exec( | ||
`git diff --name-only origin/${base.ref} ${commonAncestorSha} -- .circleci/config.yml`, | ||
); | ||
const circleCIConfigChanged = execGit([ | ||
'diff', | ||
'--name-only', | ||
`origin/${base.ref}`, | ||
commonAncestorSha, | ||
'--', | ||
'.circleci/config.yml', | ||
]); | ||
|
||
if (!!circleCIConfigChanged) { | ||
throw Error(` | ||
CircleCI config on ${base.ref} has been modified since commit | ||
|
@@ -77,7 +87,7 @@ if (!process.env.CIRCLE_PR_NUMBER) { | |
console.log(); | ||
|
||
// Rebase the PR. | ||
exec(`git rebase origin/${base.ref}`); | ||
execGit(['rebase', `origin/${base.ref}`]); | ||
console.log(`Rebased current branch onto ${base.ref}.`); | ||
})().catch((err: unknown) => { | ||
console.error('Failed to rebase on top of target branch.'); | ||
|
This file contains 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