Skip to content

Commit

Permalink
prep build 03/09
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Mar 9, 2022
2 parents 243890a + e9994b4 commit c1fce40
Show file tree
Hide file tree
Showing 56 changed files with 1,149 additions and 995 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/upload-release-to-plugin-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,45 @@ jobs:
name: changelog ${{ matrix.label }}
path: ./changelog.txt

npm-publish:
name: Publish WordPress packages to npm
runs-on: ubuntu-latest
needs: update-changelog
if: ${{ github.event.release.prerelease && endsWith( github.event.release.tag_name, '-rc.1' ) && github.event.release.assets[0] }}
steps:
- name: Checkout (for CLI)
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
with:
path: main
ref: trunk

- name: Checkout (for publishing)
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
with:
path: publish
ref: trunk
token: ${{ secrets.GUTENBERG_TOKEN }}

- name: Configure git user name and email (for publishing)
run: |
cd publish
git config user.name "Gutenberg Repository Automation"
git config user.email [email protected]
- name: Setup Node
uses: actions/setup-node@38d90ce44d5275ad62cc48384b3d8a58c500bb5f # v2.2.2
with:
node-version: 14
registry-url: 'https://registry.npmjs.org'

- name: Publish packages to npm ("next" dist-tag)
run: |
cd main
npm ci
./bin/plugin/cli.js npm-next --semver minor --ci --repository-path ../publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

upload:
name: Upload Gutenberg Plugin
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions bin/plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ const { runPerformanceTests } = require( './commands/performance' );

const semverOption = [ '--semver <semver>', 'Semantic Versioning', 'patch' ];
const ciOption = [ '-c, --ci', 'Run in CI (non interactive)' ];
const repositoryPathOption = [
'--repository-path <repository-path>',
'Relative path to the git repository.',
];

program
.command( 'publish-npm-packages-latest' )
.alias( 'npm-latest' )
.option( ...semverOption )
.option( ...ciOption )
.option( ...repositoryPathOption )
.description(
'Publishes packages to npm (latest dist-tag, production version)'
)
Expand All @@ -45,6 +50,7 @@ program
.alias( 'npm-bugfix' )
.option( ...semverOption )
.option( ...ciOption )
.option( ...repositoryPathOption )
.description(
'Publishes bugfixes for packages to npm (latest dist-tag, production version)'
)
Expand All @@ -55,6 +61,7 @@ program
.alias( 'npm-next' )
.option( ...semverOption )
.option( ...ciOption )
.option( ...repositoryPathOption )
.description(
'Publishes packages to npm (next dist-tag, prerelease version)'
)
Expand Down
55 changes: 37 additions & 18 deletions bin/plugin/commands/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
runCleanLocalFoldersStep,
} = require( './common' );
const git = require( '../lib/git' );
const { join } = require( 'path' );

/**
* Release type names.
Expand All @@ -36,8 +37,9 @@ const git = require( '../lib/git' );
/**
* @typedef WPPackagesCommandOptions
*
* @property {SemVer} [semver] The selected semantic versioning. Defaults to `patch`.
* @property {boolean} [ci] Disables interactive mode when executed in CI mode.
* @property {boolean} [ci] Disables interactive mode when executed in CI mode.
* @property {string} [repositoryPath] Relative path to the git repository.
* @property {SemVer} [semver] The selected semantic versioning. Defaults to `patch`.
*/

/**
Expand Down Expand Up @@ -331,11 +333,18 @@ async function publishPackagesToNpm( {
cwd: gitWorkingDirectoryPath,
} );

log( '>> Current npm user:' );
await command( 'npm whoami', {
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
} );

const beforeCommitHash = await git.getLastCommitHash(
gitWorkingDirectoryPath
);

const yesFlag = interactive ? '' : '--yes';
const noVerifyAccessFlag = interactive ? '' : '--no-verify-access';
if ( releaseType === 'next' ) {
log(
'>> Bumping version of public packages changed since the last release.'
Expand All @@ -351,7 +360,7 @@ async function publishPackagesToNpm( {

log( '>> Publishing modified packages to npm.' );
await command(
`npx lerna publish from-package --dist-tag next ${ yesFlag }`,
`npx lerna publish from-package --dist-tag next ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
Expand All @@ -360,7 +369,7 @@ async function publishPackagesToNpm( {
} else if ( releaseType === 'bugfix' ) {
log( '>> Publishing modified packages to npm.' );
await command(
`npx lerna publish ${ minimumVersionBump } --no-private ${ yesFlag }`,
`npx lerna publish ${ minimumVersionBump } --no-private ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
Expand All @@ -379,10 +388,13 @@ async function publishPackagesToNpm( {
);

log( '>> Publishing modified packages to npm.' );
await command( `npx lerna publish from-package ${ yesFlag }`, {
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
} );
await command(
`npx lerna publish from-package ${ yesFlag } ${ noVerifyAccessFlag }`,
{
cwd: gitWorkingDirectoryPath,
stdio: 'inherit',
}
);
}

const afterCommitHash = await git.getLastCommitHash(
Expand Down Expand Up @@ -458,17 +470,23 @@ async function runPackagesRelease( config, customMessages ) {
await askForConfirmation( 'Ready to go?' );
}

// Cloning the Git repository.
config.gitWorkingDirectoryPath = await runGitRepositoryCloneStep(
config.abortMessage
);
const temporaryFolders = [ config.gitWorkingDirectoryPath ];
const temporaryFolders = [];
if ( ! config.gitWorkingDirectoryPath ) {
// Cloning the Git repository.
config.gitWorkingDirectoryPath = await runGitRepositoryCloneStep(
config.abortMessage
);
temporaryFolders.push( config.gitWorkingDirectoryPath );
}

let pluginReleaseBranch;
if ( [ 'latest', 'next' ].includes( config.releaseType ) ) {
pluginReleaseBranch = await findPluginReleaseBranchName(
config.gitWorkingDirectoryPath
);
pluginReleaseBranch =
config.releaseType === 'next'
? 'trunk'
: await findPluginReleaseBranchName(
config.gitWorkingDirectoryPath
);
await runNpmReleaseBranchSyncStep( pluginReleaseBranch, config );
} else {
await checkoutNpmReleaseBranch( config );
Expand Down Expand Up @@ -510,10 +528,11 @@ async function runPackagesRelease( config, customMessages ) {
*
* @return {WPPackagesConfig} The config object.
*/
function getConfig( releaseType, { ci, semver } ) {
function getConfig( releaseType, { ci, repositoryPath, semver } ) {
return {
abortMessage: 'Aborting!',
gitWorkingDirectoryPath: process.cwd(),
gitWorkingDirectoryPath:
repositoryPath && join( process.cwd(), repositoryPath ),
interactive: ! ci,
minimumVersionBump: semver,
npmReleaseBranch: releaseType === 'next' ? 'wp/next' : 'wp/trunk',
Expand Down
Loading

0 comments on commit c1fce40

Please sign in to comment.