Skip to content
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

Workflows: Fix issues with the npm publishing workflow when using locally #53565

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions bin/plugin/commands/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
findPluginReleaseBranchName,
} = require( './common' );
const { join } = require( 'path' );
const pluginConfig = require( '../config' );

/**
* Release type names.
Expand Down Expand Up @@ -99,7 +100,7 @@ async function checkoutNpmReleaseBranch( {
* `trunk` commits from within the past week.
*/
await SimpleGit( gitWorkingDirectoryPath )
.fetch( npmReleaseBranch, [ '--depth=100' ] )
.fetch( 'origin', npmReleaseBranch, [ '--depth=100' ] )
.checkout( npmReleaseBranch );
log(
'>> The local npm release branch ' +
Expand Down Expand Up @@ -411,13 +412,27 @@ async function publishPackagesToNpm( {
);
} else if ( [ 'bugfix', 'wp' ].includes( releaseType ) ) {
log( '>> Publishing modified packages to npm.' );
await command(
`npx lerna publish ${ minimumVersionBump } --dist-tag ${ distTag } --no-private ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
try {
await command(
`npx lerna publish ${ minimumVersionBump } --dist-tag ${ distTag } --no-private ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
} catch {
log(
'>> Trying to finish failed publishing of modified npm packages.'
);
await SimpleGit( gitWorkingDirectoryPath ).reset( 'hard' );
await command(
`npx lerna publish from-package --dist-tag ${ distTag } ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
}
} else {
log(
'>> Bumping version of public packages changed since the last release.'
Expand All @@ -431,13 +446,27 @@ async function publishPackagesToNpm( {
);

log( '>> Publishing modified packages to npm.' );
await command(
`npx lerna publish from-package ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
try {
await command(
`npx lerna publish from-package ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
} catch {
log(
'>> Trying to finish failed publishing of modified npm packages.'
);
await SimpleGit( gitWorkingDirectoryPath ).reset( 'hard' );
await command(
gziolo marked this conversation as resolved.
Show resolved Hide resolved
`npx lerna publish from-package ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
}
}

const afterCommitHash = await SimpleGit( gitWorkingDirectoryPath ).revparse(
Expand Down Expand Up @@ -530,7 +559,11 @@ async function runPackagesRelease( config, customMessages ) {
config.abortMessage,
async () => {
log( '>> Cloning the Git repository' );
await SimpleGit( gitPath ).clone( config.gitRepositoryURL );
await SimpleGit().clone(
pluginConfig.gitRepositoryURL,
gitPath,
[ '--depth=1', '--no-single-branch' ]
);
log( ` >> successfully clone into: ${ gitPath }` );
}
);
Expand Down
Loading