From 4ccbe809685b03b8028dd046a3beaa49b521b704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Zi=C3=B3=C5=82kowski?= Date: Fri, 11 Aug 2023 12:47:23 +0200 Subject: [PATCH 1/3] Workflows: Fix issues with the npm publishing workflow when using locally --- bin/plugin/commands/packages.js | 73 +++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/bin/plugin/commands/packages.js b/bin/plugin/commands/packages.js index c085201a23500..5356488a26126 100644 --- a/bin/plugin/commands/packages.js +++ b/bin/plugin/commands/packages.js @@ -25,6 +25,7 @@ const { findPluginReleaseBranchName, } = require( './common' ); const { join } = require( 'path' ); +const pluginConfig = require( '../config' ); /** * Release type names. @@ -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 ' + @@ -371,6 +372,16 @@ async function publishPackagesToNpm( { minimumVersionBump, releaseType, } ) { + const { stdout: nodeVersion } = await command( 'node -v', { + cwd: gitWorkingDirectoryPath, + } ); + log( `>> Current node version: ${ nodeVersion }.` ); + + const { stdout: npmVersion } = await command( 'npm -v', { + cwd: gitWorkingDirectoryPath, + } ); + log( `>> Current node version: ${ npmVersion }.` ); + log( '>> Installing npm packages.' ); await command( 'npm ci', { cwd: gitWorkingDirectoryPath, @@ -411,13 +422,26 @@ 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 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.' @@ -431,13 +455,26 @@ 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 command( + `npx lerna publish from-package ${ yesFlag } ${ noVerifyAccessFlag }`, + { + cwd: gitWorkingDirectoryPath, + stdio: 'inherit', + } + ); + } } const afterCommitHash = await SimpleGit( gitWorkingDirectoryPath ).revparse( @@ -530,7 +567,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 }` ); } ); From 4a32d3138b2f064e18d1a62d6af10cb11f21b32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Mon, 14 Aug 2023 12:11:09 +0200 Subject: [PATCH 2/3] Update bin/plugin/commands/packages.js --- bin/plugin/commands/packages.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/bin/plugin/commands/packages.js b/bin/plugin/commands/packages.js index 5356488a26126..67ace67bc1904 100644 --- a/bin/plugin/commands/packages.js +++ b/bin/plugin/commands/packages.js @@ -372,16 +372,6 @@ async function publishPackagesToNpm( { minimumVersionBump, releaseType, } ) { - const { stdout: nodeVersion } = await command( 'node -v', { - cwd: gitWorkingDirectoryPath, - } ); - log( `>> Current node version: ${ nodeVersion }.` ); - - const { stdout: npmVersion } = await command( 'npm -v', { - cwd: gitWorkingDirectoryPath, - } ); - log( `>> Current node version: ${ npmVersion }.` ); - log( '>> Installing npm packages.' ); await command( 'npm ci', { cwd: gitWorkingDirectoryPath, From a6356c84e937ca5516b1af0182e293436c142cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Zi=C3=B3=C5=82kowski?= Date: Thu, 17 Aug 2023 12:04:47 +0200 Subject: [PATCH 3/3] Remove uncommitted changes before re-trying publishing --- bin/plugin/commands/packages.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/plugin/commands/packages.js b/bin/plugin/commands/packages.js index 67ace67bc1904..87ecc6eb89cfc 100644 --- a/bin/plugin/commands/packages.js +++ b/bin/plugin/commands/packages.js @@ -424,6 +424,7 @@ async function publishPackagesToNpm( { 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 }`, { @@ -457,6 +458,7 @@ async function publishPackagesToNpm( { log( '>> Trying to finish failed publishing of modified npm packages.' ); + await SimpleGit( gitWorkingDirectoryPath ).reset( 'hard' ); await command( `npx lerna publish from-package ${ yesFlag } ${ noVerifyAccessFlag }`, {