Skip to content
Closed
Show file tree
Hide file tree
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
82 changes: 65 additions & 17 deletions .github/setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,102 @@
name: 'Setup Node.js and install npm dependencies'
description: 'Configure Node.js and install npm dependencies while managing all aspects of caching.'
name: 'Setup Node.js and install dependencies'
description: 'Configure Node.js and install npm/pnpm dependencies while managing all aspects of caching.'
inputs:
node-version:
description: 'Optional. The Node.js version to use. When not specified, the version specified in .nvmrc will be used.'
required: false
type: string
outputs:
package-manager:
description: 'The detected package manager (npm or pnpm)'
value: ${{ steps.detect-pm.outputs.manager }}

runs:
using: 'composite'
steps:
- name: Detect package manager
id: detect-pm
run: |
if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> "$GITHUB_OUTPUT"
else
echo "manager=npm" >> "$GITHUB_OUTPUT"
fi
shell: bash

- name: Install pnpm
if: steps.detect-pm.outputs.manager == 'pnpm'
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Use desired version of Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: ${{ inputs.node-version == '' && '.nvmrc' || '' }}
node-version: ${{ inputs.node-version }}
check-latest: true
cache: npm
cache: ${{ steps.detect-pm.outputs.manager }}

- name: Get Node.js and npm version
- name: Get Node.js version
id: node-version
run: |
echo "NODE_VERSION=$(node -v)" >> "$GITHUB_OUTPUT"
run: echo "NODE_VERSION=$(node -v)" >> "$GITHUB_OUTPUT"
shell: bash

# pnpm caching
- name: Get pnpm store directory
if: steps.detect-pm.outputs.manager == 'pnpm'
id: pnpm-cache
run: echo "STORE_PATH=$(pnpm store path)" >> "$GITHUB_OUTPUT"
shell: bash

- name: Cache pnpm store
if: steps.detect-pm.outputs.manager == 'pnpm'
id: cache-pnpm-store
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: pnpm-store-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.NODE_VERSION }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-store-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.NODE_VERSION }}-

- name: Install pnpm dependencies
if: steps.detect-pm.outputs.manager == 'pnpm'
run: pnpm install
shell: bash

# npm caching
- name: Cache node_modules
if: steps.detect-pm.outputs.manager == 'npm'
id: cache-node_modules
uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
with:
path: '**/node_modules'
key: node_modules-${{ runner.os }}-${{ runner.arch }}-${{ steps.node-version.outputs.NODE_VERSION }}-${{ hashFiles('package-lock.json', 'patches/**') }}

- name: Install npm dependencies
if: ${{ steps.cache-node_modules.outputs.cache-hit != 'true' }}
run: |
npm ci
if: steps.detect-pm.outputs.manager == 'npm' && steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
shell: bash
- name: Upload npm logs as an artifact on failure
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
if: failure()
with:
name: npm-logs
path: C:\npm\cache\_logs

# On cache hit, we run the post-install script to match the native `npm ci` behavior.
# An example of this is to patch `node_modules` using patch-package.
- name: Post-install
if: ${{ steps.cache-node_modules.outputs.cache-hit == 'true' }}
- name: Post-install (npm)
if: steps.detect-pm.outputs.manager == 'npm' && steps.cache-node_modules.outputs.cache-hit == 'true'
run: |
# Run the post-install script for the root project.
npm run postinstall
# Run the post-install scripts for workspaces.
npx lerna run postinstall
shell: bash

- name: Upload pnpm logs as an artifact on failure
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
if: failure() && steps.detect-pm.outputs.manager == 'pnpm'
with:
name: pnpm-logs
path: ~/.local/share/pnpm/store

- name: Upload npm logs as an artifact on failure
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
if: failure() && steps.detect-pm.outputs.manager == 'npm'
with:
name: npm-logs
path: C:\npm\cache\_logs
19 changes: 14 additions & 5 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ jobs:
run: |
jq --tab --arg version "${VERSION}" '.version = $version' package.json > package.json.tmp
mv package.json.tmp package.json
jq --tab --arg version "${VERSION}" '.version = $version | .packages[""].version = $version' package-lock.json > package-lock.json.tmp
mv package-lock.json.tmp package-lock.json
sed -i "s/${OLD_VERSION}/${VERSION}/g" gutenberg.php

- name: Commit the version bump to the release branch
Expand All @@ -154,7 +152,7 @@ jobs:
TARGET_BRANCH: ${{ steps.get_version.outputs.release_branch }}
VERSION: ${{ steps.get_version.outputs.new_version }}
run: |
git add gutenberg.php package.json package-lock.json
git add gutenberg.php package.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will changes to the pnpm-lock.yaml file ever need to be committed?

git commit -m "Bump plugin version to ${VERSION}"
git push --set-upstream origin "$TARGET_BRANCH"
echo "version_bump_commit=$(git rev-parse --verify --short HEAD)" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -201,11 +199,15 @@ jobs:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false

- name: Install pnpm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to happen after configuring the desired version of Node.js to ensure it's installed & configured correctly?

Running it prior would result in the default version of Node.js on the Actions runner being used instead when installing, which could be problematic in some scenarios.

uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Use desired version of Node.js
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version-file: '.nvmrc'
check-latest: true
cache: pnpm

- name: Build Gutenberg plugin ZIP file
run: ./bin/build-plugin-zip.sh
Expand All @@ -225,7 +227,7 @@ jobs:
run: |
IFS='.' read -r -a VERSION_ARRAY <<< "${VERSION}"
MILESTONE="Gutenberg ${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}"
npm run other:changelog -- --milestone="$MILESTONE" --unreleased > release-notes.txt
pnpm run other:changelog --milestone="$MILESTONE" --unreleased > release-notes.txt
sed -ie '1,6d' release-notes.txt
if [[ "${VERSION}" != *"rc"* ]]; then
# Include previous RCs' release notes, if any
Expand Down Expand Up @@ -378,17 +380,24 @@ jobs:
git config user.name "Gutenberg Repository Automation"
git config user.email gutenberg@wordpress.org

- name: Install pnpm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here. Should this happen after setting up Node.js?

uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
with:
package_json_file: 'main/package.json'

- name: Setup Node.js
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version-file: 'main/.nvmrc'
registry-url: 'https://registry.npmjs.org'
check-latest: true
cache: pnpm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When building production assets, caches should never be used to avoid cache poisoning.

cache-dependency-path: 'main/pnpm-lock.yaml'

- name: Publish packages to npm ("latest" dist-tag)
run: |
cd main
npm ci
pnpm install
./bin/plugin/cli.js npm-latest --semver minor --ci --repository-path ../publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion .github/workflows/bundle-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ jobs:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false

- name: Install pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Use desired version of Node.js
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version-file: '.nvmrc'
check-latest: true
cache: npm
package-manager-cache: true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the documentation, this is what it says for package-manager-cache:

Controls automatic caching for npm. By default, caching for npm is enabled if either the devEngines.packageManager field or the top-level packageManager field in package.json specifies npm and no explicit cache input is provided.

The description makes it seem that this only controls caching for npm? I don't see any indication in the Action logs that it successfully detected pnpm and configured caching accorrdingly. It's possible that just cache: pnpm is required.


- uses: preactjs/compressed-size-action@946a292cd35bd1088e0d7eb92b69d1a8d5b5d76a # v2.8.0
with:
Expand Down
30 changes: 24 additions & 6 deletions .github/workflows/end2end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,33 @@ jobs:
- name: Setup Node.js and install dependencies
uses: ./.github/setup-node

- name: Npm build
run: npm run build -- --skip-types
- name: Detect package manager
id: detect-pm
run: |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if there is a way to handle this with a command instead of having to detect this within Action files.

If not, then this should be abstracted into a separate job and the output should be shared with every other job in the workflow instead of having to run it twice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I know that the goal here was to ensure a smooth transition.

But if there is a proposal published and a schedule announced after, everyone would be made aware of the change and the only impact should be that the GitHub Action workflows for each pull request would no longer pass. Wouldn't rebasing or updating the HEAD branch fix that?

I'm leaning towards not including this at all if we can help it. It could help contributors with the transition. But on the other hand, it could temporarily be a blocker for some.

if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> "$GITHUB_OUTPUT"
else
echo "manager=npm" >> "$GITHUB_OUTPUT"
fi

- name: Build
run: ${{ steps.detect-pm.outputs.manager }} run build -- --skip-types

- name: Install Playwright dependencies
run: |
npx playwright install chromium firefox webkit --with-deps

- name: Install WordPress and start the server
run: |
npm run wp-env-test start
${{ steps.detect-pm.outputs.manager }} run wp-env-test start

- name: Run the tests
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
SHARD_PART: ${{ matrix.part }}
SHARD_TOTAL: ${{ matrix.totalParts }}
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test:e2e -- --shard="${SHARD_PART}/${SHARD_TOTAL}"
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- ${{ steps.detect-pm.outputs.manager }} run test:e2e --shard="${SHARD_PART}/${SHARD_TOTAL}"

- name: Archive debug artifacts (screenshots, traces)
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
Expand Down Expand Up @@ -132,8 +141,17 @@ jobs:
- name: Setup Node.js and install dependencies
uses: ./.github/setup-node

- name: Npm build
run: npm run build -- --skip-types
- name: Detect package manager
id: detect-pm
run: |
if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> "$GITHUB_OUTPUT"
else
echo "manager=npm" >> "$GITHUB_OUTPUT"
fi

- name: Build
run: ${{ steps.detect-pm.outputs.manager }} run build -- --skip-types

- name: Report flaky tests
uses: ./packages/report-flaky-tests
Expand Down
26 changes: 21 additions & 5 deletions .github/workflows/publish-npm-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,27 @@ jobs:
git config user.name "Gutenberg Repository Automation"
git config user.email gutenberg@wordpress.org

- name: Install pnpm
if: ${{ github.event.inputs.release_type != 'wp' }}
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
with:
package_json_file: 'cli/package.json'

- name: Setup Node.js
if: ${{ github.event.inputs.release_type != 'wp' }}
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version-file: 'cli/.nvmrc'
registry-url: 'https://registry.npmjs.org'
check-latest: true
cache: pnpm
cache-dependency-path: 'cli/pnpm-lock.yaml'

- name: Install pnpm (for WP major version)
if: ${{ github.event.inputs.release_type == 'wp' && github.event.inputs.wp_version }}
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
with:
package_json_file: 'publish/package.json'

- name: Setup Node.js (for WP major version)
if: ${{ github.event.inputs.release_type == 'wp' && github.event.inputs.wp_version }}
Expand All @@ -90,12 +104,14 @@ jobs:
node-version-file: 'publish/.nvmrc'
registry-url: 'https://registry.npmjs.org'
check-latest: true
cache: pnpm
cache-dependency-path: 'publish/pnpm-lock.yaml'

- name: Publish development packages to npm ("next" dist-tag)
if: ${{ github.event.inputs.release_type == 'development' }}
run: |
cd cli
npm ci
pnpm install
./bin/plugin/cli.js npm-next --ci --repository-path ../publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -104,7 +120,7 @@ jobs:
if: ${{ github.event.inputs.release_type == 'latest' }}
run: |
cd cli
npm ci
pnpm install
./bin/plugin/cli.js npm-latest --semver minor --ci --repository-path ../publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -113,7 +129,7 @@ jobs:
if: ${{ github.event.inputs.release_type == 'bugfix' }}
run: |
cd cli
npm ci
pnpm install
./bin/plugin/cli.js npm-bugfix --ci --repository-path ../publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -122,8 +138,8 @@ jobs:
if: ${{ github.event.inputs.release_type == 'wp' && github.event.inputs.wp_version }}
run: |
cd publish
npm ci
npx lerna publish patch --dist-tag "wp-$WP_VERSION" --no-private --yes --no-verify-access
pnpm install
pnpm exec lerna publish patch --dist-tag "wp-$WP_VERSION" --no-private --yes --no-verify-access
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
WP_VERSION: ${{ github.event.inputs.wp_version }}
6 changes: 3 additions & 3 deletions .github/workflows/rnmobile-android-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ jobs:
with:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both React Native workflows are currently disabled. I lean towards not making changes to these files because they currently cannot be tested.

I have been meaning to open an issue that suggests we should remove the RN-specific dependencies and workflows until there is a coordinated effort to support this going forward. They can always be restored through version control in the future.

path: |
~/.appium
key: ${{ runner.os }}-tests-setup-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-tests-setup-${{ hashFiles('pnpm-lock.yaml') }}

- name: Prepare tests setup
run: npm run native test:e2e:setup
run: pnpm run native test:e2e:setup

- name: Gradle cache
uses: gradle/actions/setup-gradle@0bdd871935719febd78681f197cd39af5b6e16a6 # v4.2.2
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
disable-animations: true
arch: x86_64
profile: Nexus 6
script: npm run native test:e2e:android:local "$NATIVE_TEST_NAME"
script: pnpm run native test:e2e:android:local "$NATIVE_TEST_NAME"

- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
if: always()
Expand Down
Loading
Loading