Optimize Workflow Caching (#34607)

* Added Monorepo Setup Action

This action will handle the installation, building, and caching for all
projects within the monorepo. It has inputs for skipping builds and
filtering so that only specific packages are installed and built.

* Removed Test Caching

Caching the results of tests, while an interesting way to avoid
unnecessary execution, seems error-prone. We can't adequately
capture the environment such that we can rely on this working.
For instance, changes in PHP version might break PHPUnit tests,
but, cached runs will be shared across different workflows.

It seems better to just not cache it and rely on people only testing
code that has actually changed in the pull request.

* Added Input Parsing

This SHOULD allow for passing multiple filters as an array argument.

* Updated Workflows

This fully utilizes the new action across all of the workflows.

* Always Cache Build Output

Since there may be other commands run that populate the cache, we
should make sure that we are always caching just in case.
This commit is contained in:
Christopher Allford 2022-09-12 18:55:03 -07:00 committed by GitHub
parent e3ca9364a4
commit a49f23abfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 164 additions and 387 deletions

View File

@ -1,22 +0,0 @@
name: Cache Dependencies (Composite)
description: Creates and restores caches for dependencies.
inputs:
workflow_cache:
required: true
description: The workflow cache key.
workflow_name:
required: true
description: The name of the workflow.
runs:
using: "composite"
steps:
- name: Dependency caching
uses: actions/cache@v3
id: cache-deps
with:
path: |
~/.pnpm-store
~/.local/share/pnpm/store
~/.cache/composer/files
key: ${{ runner.os }}-${{ inputs.workflow_name }}-${{ inputs.workflow_cache }}-${{ hashFiles('**/composer.lock', '**/pnpm-lock.yaml') }}

View File

@ -1,29 +0,0 @@
name: Install and Build (Composite)
description: Installs and builds WooCommerce.
inputs:
working_directory:
required: false
description: The directory to target.
default: ./
composer_no_dev:
required: false
description: COMPOSER_NO_DEV option.
default: 1
runs:
using: "composite"
steps:
- name: Install PNPM
shell: bash
working-directory: ${{ inputs.working_directory }}
run: npm install -g pnpm@^6.24.2
- name: Install dependencies
shell: bash
working-directory: ${{ inputs.working_directory }}
run: COMPOSER_NO_DEV=${{ inputs.composer_no_dev }} pnpm install
- name: Run build
shell: bash
working-directory: ${{ inputs.working_directory }}
run: pnpm run build --filter="${{ inputs.working_directory }}" --color

View File

@ -0,0 +1,7 @@
# GitHub Action: Setup WooCommerce Monorepo
This action will prime the plugins, packages, and tools in the monorepo for other workflows. This includes support for installing dependencies, building projects, and caching the output of both.
## Usage
See [`action.yml`](action.yml) for information about all of the inputs the action supports.

View File

@ -0,0 +1,66 @@
name: Setup WooCommerce Monorepo
description: Handles the installation, building, and caching of the projects within the monorepo.
inputs:
install-filters:
description: The PNPM filter used to decide what projects to install. Supports multiline strings for multiple filters.
default: ""
build:
description: Indicates whether or not the action should build any projects.
default: "true"
build-filters:
description: The PNPM filter used to decide what projects to build. Supports multiline strings for multiple filters.
default: ""
php-version:
description: The version of PHP that the action should set up.
default: "7.2"
runs:
using: composite
steps:
- name: Parse Action Input
id: parse-input
shell: bash
run: |
echo "::set-output name=INSTALL_FILTERS::$(node ./.github/actions/setup-woocommerce-monorepo/scripts/parse-input-filter.js '${{ inputs.install-filters }}')"
echo "::set-output name=BUILD_FILTERS::$(node ./.github/actions/setup-woocommerce-monorepo/scripts/parse-input-filter.js '${{ inputs.build-filters }}')"
- name: Setup PNPM
uses: pnpm/action-setup@10693b3829bf86eb2572aef5f3571dcf5ca9287d
with:
version: 6
- name: Setup Node
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93
with:
node-version-file: .nvmrc
cache: pnpm
- name: Setup PHP
uses: shivammathur/setup-php@e04e1d97f0c0481c6e1ba40f8a538454fe5d7709
with:
php-version: ${{ inputs.php-version }}
coverage: none
- name: Cache Composer Dependencies
uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77
with:
path: ~/.cache/composer/files
key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-
- name: Install Node and PHP Dependencies
shell: bash
run: pnpm install ${{ steps.parse-input.outputs.INSTALL_FILTERS }}
- name: Cache Build Output
uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77
with:
path: node_modules/.cache/turbo
key: ${{ runner.os }}-build-output-${{ hashFiles('node_modules/.cache/turbo/*-meta.json') }}
restore-keys: ${{ runner.os }}-build-output-
- name: Build
if: ${{ inputs.build == 'true' }}
shell: bash
run: pnpm -w exec turbo run turbo:build ${{ steps.parse-input.outputs.BUILD_FILTERS }}

View File

@ -0,0 +1,22 @@
const args = process.argv.slice(2);
if (args.length != 1) {
console.error('Filters must be passed as a single string!');
process.exit(-1);
}
// Read all of the given filters and return the full filter options string.
const filterLines = args[0].split("\n");
let output = '';
for (const line of filterLines) {
if (line === '') {
continue;
}
if (output !== '') {
output += ' ';
}
output += "--filter='" + line + "'";
}
console.log(output);
process.exit(0);

View File

@ -13,18 +13,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: build-release-zip-file
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
build: false
- name: Build zip
working-directory: plugins/woocommerce

View File

@ -8,18 +8,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: build-release
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
php-version: '7.4'
build: false
- name: Build zip
working-directory: plugins/woocommerce

View File

@ -41,29 +41,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: ci
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
extensions: mysql
coverage: none
build-filters: woocommerce
- name: Tool versions
run: |
php --version
composer --version
- name: Install and Build
uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Build Admin feature config
run: pnpm build:feature-config --filter=woocommerce

View File

@ -12,18 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: mirrors
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
build: false
- name: Build zip
working-directory: plugins/woocommerce

View File

@ -17,18 +17,10 @@ jobs:
with:
ref: ${{ matrix.build }}
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: nightly-builds
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
build: false
- name: Build zip
working-directory: plugins/woocommerce

View File

@ -12,27 +12,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- 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: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Execute script
run: ./tools/package-release/bin/dev publish ${{ github.event.inputs.packages }} --branch=${{ github.ref_name }} --skip-install

View File

@ -13,18 +13,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-build-and-e2e-tests
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Load docker images and start containers.
working-directory: plugins/woocommerce
@ -73,18 +64,9 @@ jobs:
API_TEST_REPORT_DIR: ${{ github.workspace }}/api-test-report
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-build-and-e2e-tests
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Load docker images and start containers.
working-directory: plugins/woocommerce
@ -113,18 +95,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-build-and-e2e-tests
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Load docker images and start containers.
working-directory: plugins/woocommerce

View File

@ -26,29 +26,16 @@ jobs:
with:
fetch-depth: 100
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
php-version: 7.4
tools: composer
extensions: mysql
coverage: none
- name: Tool versions
run: |
php --version
composer --version
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-code-coverage
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install and Build
uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Build Admin feature config
run: |
pnpm build:feature-config --filter=woocommerce

View File

@ -17,27 +17,16 @@ jobs:
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
php-version: 7.4
tools: composer
build: false
- name: Tool versions
run: |
php --version
composer --version
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-code-sniff
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install and Build
uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Run code sniffer
uses: thenabeel/action-phpcs@v8
with:

View File

@ -17,11 +17,10 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
php-version: '7.4'
tools: composer
build: false
- name: Check change files are touched for touched projects
env:
@ -29,11 +28,5 @@ jobs:
HEAD: ${{ github.event.pull_request.head.sha }}
run: php tools/monorepo/check-changelogger-use.php --debug "$BASE" "$HEAD"
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Install dependencies
run: pnpm install
- name: Run changelog validation
run: pnpm changelog --filter=* -- validate

View File

@ -12,22 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
node-version: '16'
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-lint-test-js
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
install-filters: 'woocommerce/client/admin...'
- name: Lint
run: pnpm run lint --filter='woocommerce/client/admin...' --filter='!@woocommerce/e2e*' --filter='!@woocommerce/api' --color

View File

@ -17,22 +17,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-smoke-test
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Install Jest
run: pnpm install -g jest
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
- name: Run smoke test.
working-directory: plugins/woocommerce
if: always()

View File

@ -37,33 +37,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: pr-unit-tests
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
php-version: ${{ matrix.php }}
tools: composer
extensions: mysql
coverage: none
- name: Tool versions
run: |
php --version
composer --version
- name: Install and Build
uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Build Admin feature config
run: |
pnpm build:feature-config --filter=woocommerce
- name: Add PHP8 Compatibility.
run: |
if [ "$(php -r "echo version_compare(PHP_VERSION,'8.0','>=');")" ]; then

View File

@ -12,21 +12,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: prepare-package-release
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Install dependencies
run: pnpm install
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Execute script
run: ./tools/package-release/bin/dev prepare ${{ github.event.inputs.packages }}

View File

@ -13,17 +13,8 @@ jobs:
prime:
name: Prime cache
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
workflow: [ 'pr-unit-tests', 'pr-build-and-e2e-tests', 'pr-code-coverage', 'pr-code-sniff', 'pr-lint-test-js', 'pr-smoke-test' ]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
with:
workflow_name: ${{ matrix.workflow }}
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install and Build
uses: ./.github/actions/install-build
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo

View File

@ -24,14 +24,10 @@ jobs:
with:
fetch-depth: 0
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: "Install PHP"
uses: shivammathur/setup-php@v2
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
php-version: '7.4'
tools: composer
build: false
- name: "Git fetch the release branch"
run: git fetch origin ${{ inputs.releaseBranch }}
@ -42,9 +38,6 @@ jobs:
- name: "Create a new branch for the changelog update PR"
run: git checkout -b ${{ format( 'update/{0}-changelog', inputs.releaseVersion ) }}
- name: Install dependencies
run: pnpm install
- name: "Generate the changelog file"
run: pnpm changelog --filter=woocommerce -- write --add-pr-num -n -vvv --use-version ${{ inputs.releaseVersion }}

View File

@ -65,22 +65,10 @@ jobs:
with:
fetch-depth: 100
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: release-code-freeze
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer
- name: Install dependencies
run: pnpm install
build: false
- name: "Run the script to enforce the code freeze"
id: freeze

View File

@ -17,18 +17,8 @@ jobs:
with:
ref: trunk
- uses: ./.github/actions/cache-deps
with:
workflow_name: smoke-test-daily
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Install Jest
run: npm install -g jest
@ -130,18 +120,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: smoke-test-daily
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Install PNPM
run: npm install -g pnpm@^6.24.2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
build: false
- name: Build zip
working-directory: plugins/woocommerce
@ -187,21 +169,6 @@ jobs:
with:
path: package/woocommerce
- uses: ./package/woocommerce/.github/actions/cache-deps
with:
workflow_name: smoke-test-daily
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./package/woocommerce/.github/actions/install-build
with:
working_directory: package/woocommerce
- name: Download WooCommerce ZIP.
uses: actions/download-artifact@v3
with:

View File

@ -14,18 +14,10 @@ jobs:
with:
ref: trunk
- uses: ./.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: smoke-test-release
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./.github/actions/install-build
build-filters: woocommerce
- name: Install Jest
run: npm install -g jest
@ -70,10 +62,10 @@ jobs:
with:
path: package/woocommerce
- uses: ./package/woocommerce/.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: smoke-test-release
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
build-filters: woocommerce
- name: Fetch Asset ID
id: fetch_asset_id
@ -87,16 +79,6 @@ jobs:
const script = require( './package/woocommerce/.github/workflows/scripts/fetch-asset-id.js' )
await script({github, context, core})
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./package/woocommerce/.github/actions/install-build
with:
working_directory: package/woocommerce
- name: Download WooCommerce release zip
working-directory: tmp
run: |
@ -149,10 +131,10 @@ jobs:
with:
path: package/woocommerce
- uses: ./package/woocommerce/.github/actions/cache-deps
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
workflow_name: smoke-test-release
workflow_cache: ${{ secrets.WORKFLOW_CACHE }}
build-filters: woocommerce
- name: Fetch Asset ID
id: fetch_asset_id
@ -166,16 +148,6 @@ jobs:
const script = require( './package/woocommerce/.github/workflows/scripts/fetch-asset-id.js' )
await script({github, context, core})
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install and Build
uses: ./package/woocommerce/.github/actions/install-build
with:
working_directory: package/woocommerce
- name: Download WooCommerce release zip
working-directory: tmp
run: |

View File

@ -73,15 +73,8 @@
},
"turbo:test": {
"cache": false,
"dependsOn": [ "turbo:build" ],
"inputs": [
"src/**/*.js",
"src/**/*.jsx",
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.php",
"includes/**/*.php"
],
"outputs": []
}
}