From c91312bf266c5293393bf24dd0bf095bba90838e Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Fri, 22 Jul 2022 12:08:11 +1200 Subject: [PATCH] Packages Release: Add manual workflow (#33922) --- .github/workflows/package-release.yml | 33 +++++++++-- tools/package-release/README.md | 59 +++++++++++++++++++ tools/package-release/src/changelogger.ts | 2 +- .../src/commands/prepare/index.ts | 7 ++- tools/package-release/src/validate.ts | 2 +- 5 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 tools/package-release/README.md diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index f54c5cf4b20..189f37feacd 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -7,9 +7,34 @@ on: required: false default: '-a' jobs: - prepare: - name: Run the prepare script + release: + name: Run packages release script runs-on: ubuntu-20.04 steps: - - name: Run - run: echo "hello world" + - uses: actions/checkout@v3 + - uses: ./.github/actions/cache-deps + with: + workflow_name: package-release + workflow_cache: ${{ secrets.WORKFLOW_CACHE }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '16' + registry-url: 'https://registry.npmjs.org' + + - name: Install PNPM + run: npm install -g pnpm@^6.24.2 + + - name: Install dependencies + run: pnpm install + + - name: Execute script + run: ./tools/package-release/bin/dev publish ${{ github.event.inputs.packages }} --branch=${{ github.ref_name }} --skip-install + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/tools/package-release/README.md b/tools/package-release/README.md new file mode 100644 index 00000000000..b50b3f17aa9 --- /dev/null +++ b/tools/package-release/README.md @@ -0,0 +1,59 @@ +# Releasing Javascript packages + +When a package contains sufficient changes to justify a release to [NPM](https://www.npmjs.com/), follow these instructions to create a new release from the monorepo. + +## Release packages using Github Workflows (recommended) + +### Prepare packages + +In order to prepare a package for release, a changelog will need to be compiled along with an appropriate version bump. + +1. Visit the monorepo Action [Prepare Package Release workflow](https://github.com/woocommerce/woocommerce/actions/workflows/prepare-package-release.yml). Click the "Run workflow" button. + +![image](https://user-images.githubusercontent.com/1922453/179434424-f08af974-5597-4c6f-955b-43faf062c7a7.png) + +2. Select the branch you'd like to release from. Typically, this would be `trunk`. You can also choose which packages to prepare for release by supplying them as comma separated values in the input box. To loop through all packages, simply leave the `-a` flag. Packages that don't have any changes will be skipped and left as is. + +![image](https://user-images.githubusercontent.com/1922453/179434508-8f44fcca-0f01-47f2-8b9e-f5ef5ff3a577.png) + +3. Once the action has finished, check [open pull requests](https://github.com/woocommerce/woocommerce/pulls) for a pull request generated by Github Actions Bot. This pull request should include version bumps and changelog changes for applicable packages. Approve and merge the pull request once checks pass. + +### Release Packages + +1. Release the packages to NPM by kicking off another workflow. The [Packages Release workflow](https://github.com/woocommerce/woocommerce/actions/workflows/package-release.yml) has the same inputs as the prepare workflow. Be sure to release from the same branch and select the same packages to release. + +![image](https://user-images.githubusercontent.com/1922453/179435048-ad2cd168-55b1-471a-b05f-3aed4a9e499b.png) + +2. Confirm the package has been updated by visiting NPM. For example see https://www.npmjs.com/package/@woocommerce/components. + +## Release packages using the command line + +### Prepare packages + +1. At monorepo root, run the following command to prepare all packages. Instead of the `-a` flag, you can pass in a list of packages separated by commas. + +``` +./tools/package-release/bin/dev prepare -a +``` + +2. Create a pull request with the resulting changes and merge it. + +See more about the prepare script using `./tools/package-release/bin/dev publish --help`. + +### Release Packages + +1. Pull down the latest commits from Github. + +2. Run the release script from monorepo root, first as a dry run. + +``` +./tools/package-release/bin/dev publish -a --dry-run +``` + +3. Run the release for real this time. + +``` +./tools/package-release/bin/dev publish -a +``` + +See more about the publish script using `./tools/package-release/bin/dev publish --help`. diff --git a/tools/package-release/src/changelogger.ts b/tools/package-release/src/changelogger.ts index 747bba6d64a..92d80a35380 100644 --- a/tools/package-release/src/changelogger.ts +++ b/tools/package-release/src/changelogger.ts @@ -60,7 +60,7 @@ export const validateChangelogEntries = ( name: string ) => { export const writeChangelog = ( name: string ) => { try { const cwd = getFilepathFromPackageName( name ); - execSync( './vendor/bin/changelogger write', { + execSync( './vendor/bin/changelogger write --add-pr-num', { cwd, encoding: 'utf-8', } ); diff --git a/tools/package-release/src/commands/prepare/index.ts b/tools/package-release/src/commands/prepare/index.ts index 01de7c278a4..3cb16e9ced0 100644 --- a/tools/package-release/src/commands/prepare/index.ts +++ b/tools/package-release/src/commands/prepare/index.ts @@ -92,16 +92,17 @@ export default class PackagePrepare extends Command { if ( nextVersion ) { this.bumpPackageVersion( name, nextVersion ); } + CliUx.ux.action.stop(); } else { - this.log( `Skipping ${ name }, no changelogs available.` ); + CliUx.ux.action.stop( + `Skipping ${ name }. No changes available for a release.` + ); } } catch ( e ) { if ( e instanceof Error ) { this.error( e.message ); } } - - CliUx.ux.action.stop(); } ); } diff --git a/tools/package-release/src/validate.ts b/tools/package-release/src/validate.ts index 989f0c45c9b..26c0355de5a 100644 --- a/tools/package-release/src/validate.ts +++ b/tools/package-release/src/validate.ts @@ -146,7 +146,7 @@ export const isValidUpdate = ( name: string ): boolean => { return false; } - const npmVersion = execSync( 'pnpm view @woocommerce/number version', { + const npmVersion = execSync( `pnpm view ${ name } version`, { encoding: 'utf-8', } );