Skip to content

Commit 9ecf901

Browse files
authored
Fix publish script for a specific package (#3430)
It failed when committing a temporary commit because there was no git user.name and user.email set yet.
1 parent 49d0a17 commit 9ecf901

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ jobs:
8484
- name: Setup Ubuntu Machine
8585
uses: "./.github/actions/setup_ubuntu"
8686

87+
# Running `git commit`, for example, requires these user.name and user.email to be set
88+
- name: Configure Git
89+
run: |-
90+
git config --global user.name ${{ secrets.GIT_CONFIG_USERNAME }}
91+
git config --global user.email ${{ secrets.GIT_CONFIG_EMAIL }}
92+
8793
- name: Run unit tests
8894
uses: "./.github/actions/unit_tests"
8995

scripts/publish-to-npm.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,26 @@ const publishPackages = (packages = [], isNightly = false) => {
7070
})
7171

7272
sh.exec('git add .', {silent: true})
73-
sh.exec('git commit -m "temporary commit to have clean working tree"', {silent: true})
73+
const commitResult = sh.exec(
74+
'git commit -m "temporary commit to have clean working tree"',
75+
{silent: true}
76+
)
77+
78+
if (commitResult.code !== 0) {
79+
console.error(
80+
'Failed to create temporary commit. Git user.name and user.email might not be configured.'
81+
)
82+
console.error('Commit error:', commitResult.stderr)
83+
84+
// Clean up the package.json changes before exiting
85+
packagesToIgnore.forEach((pkg) => {
86+
sh.exec('npm pkg delete private', {cwd: pkg.location})
87+
})
88+
// Unstage the files that were staged with 'git add .' above
89+
sh.exec('git reset HEAD', {silent: true})
90+
91+
process.exit(1)
92+
}
7493
}
7594

7695
// Why do we still want `lerna publish`? It turns out that we do need it. Sometimes we wanted some behaviour that's unique to Lerna.

0 commit comments

Comments
 (0)