2023-11-17 02:23:08 +00:00
|
|
|
name: 'Setup WooCommerce Monorepo'
|
|
|
|
description: 'A composite action bundling together the setup of dependencies and optional installation and building of projects.'
|
2022-09-13 01:55:03 +00:00
|
|
|
inputs:
|
2024-02-29 22:58:28 +00:00
|
|
|
php-version:
|
|
|
|
description: 'The PHP version that should be installed. Use "false" to skip PHP installation.'
|
|
|
|
default: '7.4'
|
|
|
|
install:
|
|
|
|
description: 'Given a boolean or PNPM filter, runs the install command for monorepo project(s).'
|
|
|
|
default: false
|
|
|
|
build:
|
|
|
|
description: 'Given a boolean or PNPM filter, runs the build command for monorepo project(s).'
|
|
|
|
default: false
|
2024-07-08 06:39:39 +00:00
|
|
|
build-type:
|
|
|
|
description: 'Given "full" or "backend" will perform optimized build steps.'
|
|
|
|
default: 'full'
|
2024-07-04 04:55:24 +00:00
|
|
|
pull-playwright-cache:
|
|
|
|
description: 'Given a boolean value, invokes Playwright dependencies caching.'
|
|
|
|
default: false
|
2024-07-10 12:39:49 +00:00
|
|
|
pull-package-deps:
|
|
|
|
description: 'Given a string value, will pull the package specific dependencies cache.'
|
|
|
|
default: false
|
2022-09-13 01:55:03 +00:00
|
|
|
runs:
|
2024-02-29 22:58:28 +00:00
|
|
|
using: 'composite'
|
|
|
|
steps:
|
|
|
|
- name: 'Setup PNPM'
|
|
|
|
uses: 'pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d'
|
2024-08-07 07:04:24 +00:00
|
|
|
# Next step is rudimentary - fixes a know composite action bug during post-actions:
|
|
|
|
# Error: Index was out of range. Must be non-negative and less than the size of the collection.
|
|
|
|
- name: 'Read PNPM version'
|
|
|
|
id: 'read-pnpm-version'
|
|
|
|
shell: 'bash'
|
|
|
|
run: 'echo "version=$(pnpm --version)" >> $GITHUB_OUTPUT'
|
2024-02-29 22:58:28 +00:00
|
|
|
- name: 'Setup Node'
|
|
|
|
uses: 'actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65'
|
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
2024-07-10 12:39:49 +00:00
|
|
|
# The built-in caching is not fit to per-package caching we are aiming.
|
|
|
|
cache: ''
|
2024-02-29 22:58:28 +00:00
|
|
|
- name: 'Setup PHP'
|
|
|
|
if: ${{ inputs.php-version != 'false' }}
|
|
|
|
uses: 'shivammathur/setup-php@a36e1e52ff4a1c9e9c9be31551ee4712a6cb6bd0'
|
|
|
|
with:
|
|
|
|
php-version: '${{ inputs.php-version }}'
|
|
|
|
coverage: 'none'
|
2024-07-10 12:39:49 +00:00
|
|
|
- name: 'Cache: identify pnpm caching directory'
|
|
|
|
if: ${{ inputs.pull-package-deps != 'false' }}
|
|
|
|
shell: 'bash'
|
|
|
|
run: |
|
|
|
|
echo "PNPM_STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
|
|
- name: 'Cache: pnpm downloads'
|
|
|
|
if: ${{ inputs.pull-package-deps != 'false' }}
|
|
|
|
uses: 'actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319'
|
|
|
|
with:
|
|
|
|
path: "${{ env.PNPM_STORE_PATH }}"
|
2024-07-29 11:01:58 +00:00
|
|
|
key: "${{ runner.os }}-pnpm-${{ inputs.pull-package-deps }}-build:${{ inputs.build-type }}-${{ hashFiles( 'pnpm-lock.yaml' ) }}"
|
|
|
|
restore-keys: '${{ runner.os }}-pnpm-${{ inputs.pull-package-deps }}-build:${{ inputs.build-type }}-'
|
2024-07-19 07:40:01 +00:00
|
|
|
- name: 'Cache: node cache'
|
|
|
|
if: ${{ inputs.pull-package-deps != 'false' }}
|
|
|
|
uses: 'actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319'
|
|
|
|
with:
|
|
|
|
path: './node_modules/.cache'
|
|
|
|
key: "${{ runner.os }}-node-cache-${{ inputs.pull-package-deps }}-${{ hashFiles( 'pnpm-lock.yaml' ) }}"
|
|
|
|
restore-keys: '${{ runner.os }}-node-cache-${{ inputs.pull-package-deps }}-'
|
2024-02-29 22:58:28 +00:00
|
|
|
- name: 'Cache Composer Dependencies'
|
2024-07-10 12:39:49 +00:00
|
|
|
if: ${{ inputs.pull-package-deps != 'false' }}
|
2024-02-29 22:58:28 +00:00
|
|
|
uses: 'actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319'
|
|
|
|
with:
|
|
|
|
path: '~/.cache/composer/files'
|
2024-07-10 12:39:49 +00:00
|
|
|
key: "${{ runner.os }}-composer-${{ inputs.pull-package-deps }}-${{ hashFiles( 'packages/*/*/composer.lock', 'plugins/*/composer.lock' ) }}"
|
|
|
|
restore-keys: '${{ runner.os }}-composer-${{ inputs.pull-package-deps }}-'
|
2024-07-04 04:55:24 +00:00
|
|
|
- name: 'Cache: playwright downloads'
|
|
|
|
if: ${{ inputs.pull-playwright-cache != 'false' }}
|
|
|
|
uses: 'actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319'
|
|
|
|
with:
|
|
|
|
path: '~/.cache/ms-playwright/'
|
2024-07-10 12:39:49 +00:00
|
|
|
key: "${{ runner.os }}-playwright-${{ hashFiles( 'pnpm-lock.yaml' ) }}"
|
2024-07-04 04:55:24 +00:00
|
|
|
restore-keys: '${{ runner.os }}-playwright-'
|
2024-02-29 22:58:28 +00:00
|
|
|
- name: 'Parse Project Filters'
|
|
|
|
id: 'project-filters'
|
|
|
|
shell: 'bash'
|
|
|
|
run: |
|
|
|
|
echo "install=$(node ./.github/actions/setup-woocommerce-monorepo/scripts/parse-input-filter.js '${{ inputs.install }}')" >> $GITHUB_OUTPUT
|
|
|
|
echo "build=$(node ./.github/actions/setup-woocommerce-monorepo/scripts/parse-input-filter.js '${{ inputs.build }}')" >> $GITHUB_OUTPUT
|
|
|
|
- name: 'Install Project Dependencies'
|
|
|
|
# Boolean inputs aren't parsed into filters so it'll either be "true" or there will be a filter.
|
|
|
|
if: ${{ inputs.install == 'true' || steps.project-filters.outputs.install != '' }}
|
|
|
|
shell: 'bash'
|
2024-07-10 12:39:49 +00:00
|
|
|
# The installation command is a bit odd as it's a workaround for know bug - https://github.com/pnpm/pnpm/issues/6300.
|
2024-07-29 11:01:58 +00:00
|
|
|
run: |
|
|
|
|
if [[ '${{ inputs.install }}' == '@woocommerce/plugin-woocommerce...' && '${{ inputs.build-type }}' == 'backend' ]]; then
|
|
|
|
# PHPUnit/REST testing optimized installation of the deps: minimalistic and parallellized between PHP/JS.
|
|
|
|
# JS deps installation is abit hard-core, but all we need actually is wp-env and playwright - we are good at that regard.
|
|
|
|
composer install --working-dir=./plugins/woocommerce --quiet &
|
|
|
|
pnpm install --filter='@woocommerce/plugin-woocommerce' --frozen-lockfile --config.dedupe-peer-dependents=false --ignore-scripts
|
|
|
|
else
|
|
|
|
pnpm install ${{ steps.project-filters.outputs.install }} --frozen-lockfile ${{ steps.project-filters.outputs.install != '' && '--config.dedupe-peer-dependents=false' || '' }}
|
|
|
|
fi
|
2024-02-29 22:58:28 +00:00
|
|
|
# We want to include an option to build projects using this action so that we can make
|
|
|
|
# sure that the build cache is always used when building projects.
|
|
|
|
- name: 'Cache Build Output'
|
|
|
|
# Boolean inputs aren't parsed into filters so it'll either be "true" or there will be a filter.
|
|
|
|
if: ${{ inputs.build == 'true' || steps.project-filters.outputs.build != '' }}
|
|
|
|
uses: 'google/wireit@4aad131006ea85c1e42af927534ebb13426dd730'
|
|
|
|
- name: 'Build'
|
|
|
|
# Boolean inputs aren't parsed into filters so it'll either be "true" or there will be a filter.
|
|
|
|
if: ${{ inputs.build == 'true' || steps.project-filters.outputs.build != '' }}
|
2024-07-10 12:39:49 +00:00
|
|
|
env:
|
|
|
|
BROWSERSLIST_IGNORE_OLD_DATA: true
|
2024-02-29 22:58:28 +00:00
|
|
|
shell: 'bash'
|
2024-07-08 06:39:39 +00:00
|
|
|
run: |
|
|
|
|
if [[ '${{ inputs.build-type }}' == 'backend' ]]; then
|
|
|
|
pnpm --filter="@woocommerce/admin-library" build:project:feature-config
|
|
|
|
fi
|
|
|
|
if [[ '${{ inputs.build-type }}' == 'full' ]]; then
|
|
|
|
pnpm ${{ steps.project-filters.outputs.build }} build
|
|
|
|
fi
|