2023-10-19 18:24:20 +00:00
|
|
|
name: 'CI'
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- 'trunk'
|
|
|
|
- 'release/*'
|
2023-04-26 20:41:31 +00:00
|
|
|
concurrency:
|
2023-10-19 18:24:20 +00:00
|
|
|
group: '${{ github.workflow }}-${{ github.ref }}'
|
|
|
|
cancel-in-progress: true
|
2021-03-14 00:29:15 +00:00
|
|
|
jobs:
|
2024-01-13 04:32:14 +00:00
|
|
|
project-jobs:
|
2023-11-17 02:23:08 +00:00
|
|
|
# Since this is a monorepo, not every pull request or change is going to impact every project.
|
2024-01-13 04:32:14 +00:00
|
|
|
# Instead of running CI tasks on all projects indiscriminately, we use a command to detect
|
|
|
|
# which projects have changed and what kind of change occurred. This lets us build the
|
|
|
|
# matrices that we can use to run CI tasks only on the projects that need them.
|
|
|
|
name: 'Build Project Jobs'
|
2023-11-17 02:23:08 +00:00
|
|
|
runs-on: 'ubuntu-20.04'
|
|
|
|
outputs:
|
2024-01-13 04:32:14 +00:00
|
|
|
lint-jobs: ${{ steps.project-jobs.outputs.lint-jobs }}
|
|
|
|
test-jobs: ${{ steps.project-jobs.outputs.test-jobs }}
|
2023-11-17 02:23:08 +00:00
|
|
|
steps:
|
|
|
|
- uses: 'actions/checkout@v3'
|
|
|
|
name: 'Checkout'
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
- uses: './.github/actions/setup-woocommerce-monorepo'
|
2023-12-13 05:33:52 +00:00
|
|
|
name: 'Setup Monorepo'
|
2023-11-17 02:23:08 +00:00
|
|
|
with:
|
|
|
|
php-version: false # We don't want to waste time installing PHP since we aren't using it in this job.
|
|
|
|
- uses: actions/github-script@v6
|
|
|
|
name: 'Build Matrix'
|
2024-01-13 04:32:14 +00:00
|
|
|
id: 'project-jobs'
|
2023-11-17 02:23:08 +00:00
|
|
|
with:
|
|
|
|
script: |
|
|
|
|
let baseRef = ${{ toJson( github.base_ref ) }};
|
|
|
|
if ( baseRef ) {
|
|
|
|
baseRef = 'origin/' + baseRef;
|
|
|
|
}
|
2024-01-13 04:32:14 +00:00
|
|
|
const child_process = require( 'node:child_process' );
|
|
|
|
child_process.execSync( 'pnpm utils ci-jobs ' + baseRef );
|
|
|
|
project-lint-jobs:
|
|
|
|
name: 'Lint - ${{ matrix.projectName }}'
|
2023-11-17 02:23:08 +00:00
|
|
|
runs-on: 'ubuntu-20.04'
|
2024-01-13 04:32:14 +00:00
|
|
|
needs: 'project-jobs'
|
|
|
|
if: ${{ needs.project-jobs.outputs.lint-jobs != '[]' }}
|
2023-11-17 02:23:08 +00:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
2024-01-13 04:32:14 +00:00
|
|
|
include: ${{ fromJSON( needs.project-jobs.outputs.lint-jobs ) }}
|
2023-11-17 02:23:08 +00:00
|
|
|
steps:
|
|
|
|
- uses: 'actions/checkout@v3'
|
|
|
|
name: 'Checkout'
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
- uses: './.github/actions/setup-woocommerce-monorepo'
|
|
|
|
name: 'Setup Monorepo'
|
2023-12-13 05:33:52 +00:00
|
|
|
id: 'setup-monorepo'
|
2023-11-17 02:23:08 +00:00
|
|
|
with:
|
|
|
|
install: '${{ matrix.projectName }}...'
|
|
|
|
- name: 'Lint'
|
2024-01-13 04:32:14 +00:00
|
|
|
run: 'pnpm --filter="${{ matrix.projectName }}" ${{ matrix.command }}'
|
|
|
|
project-test-jobs:
|
|
|
|
name: 'Test - ${{ matrix.projectName }} - ${{ matrix.name }}'
|
|
|
|
runs-on: 'ubuntu-20.04'
|
|
|
|
needs: 'project-jobs'
|
|
|
|
if: ${{ needs.project-jobs.outputs.test-jobs != '[]' }}
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include: ${{ fromJSON( needs.project-jobs.outputs.test-jobs ) }}
|
|
|
|
steps:
|
|
|
|
- uses: 'actions/checkout@v3'
|
|
|
|
name: 'Checkout'
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
- uses: './.github/actions/setup-woocommerce-monorepo'
|
|
|
|
name: 'Setup Monorepo'
|
|
|
|
id: 'setup-monorepo'
|
|
|
|
with:
|
|
|
|
install: '${{ matrix.projectName }}...'
|
|
|
|
build: '${{ matrix.projectName }}'
|
2023-11-17 02:23:08 +00:00
|
|
|
- name: 'Prepare Test Environment'
|
|
|
|
id: 'prepare-test-environment'
|
2024-01-13 04:32:14 +00:00
|
|
|
if: ${{ matrix.testEnv.shouldCreate }}
|
|
|
|
env: ${{ matrix.testEnv.envVars }}
|
|
|
|
run: 'pnpm --filter="${{ matrix.projectName }}" ${{ matrix.testEnv.start }}'
|
|
|
|
- name: 'Test'
|
|
|
|
run: 'pnpm --filter="${{ matrix.projectName }}" ${{ matrix.command }}'
|
|
|
|
evaluate-project-jobs:
|
2023-11-17 02:23:08 +00:00
|
|
|
# In order to add a required status check we need a consistent job that we can grab onto.
|
2024-01-13 04:32:14 +00:00
|
|
|
# Since we are dynamically generating a matrix for the project jobs, however, we can't
|
|
|
|
# rely on on any specific job being present. We can get around this limitation by
|
|
|
|
# using a job that runs after all the others and either passes or fails based
|
|
|
|
# on the results of the other jobs in the workflow.
|
|
|
|
name: 'Evaluate Project Job Statuses'
|
2023-11-17 02:23:08 +00:00
|
|
|
runs-on: 'ubuntu-20.04'
|
|
|
|
needs: [
|
2024-01-13 04:32:14 +00:00
|
|
|
'project-jobs',
|
|
|
|
'project-lint-jobs',
|
|
|
|
'project-test-jobs'
|
2023-11-17 02:23:08 +00:00
|
|
|
]
|
|
|
|
if: ${{ always() }}
|
|
|
|
steps:
|
2024-01-13 04:32:14 +00:00
|
|
|
- name: 'Evaluation'
|
2023-11-17 02:23:08 +00:00
|
|
|
run: |
|
2024-01-13 04:32:14 +00:00
|
|
|
result="${{ needs.project-jobs.result }}"
|
|
|
|
if [[ $result != "success" && $result != "skipped" ]]; then
|
|
|
|
echo "An error occurred generating the CI jobs."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
result="${{ needs.project-lint-jobs.result }}"
|
2023-11-17 02:23:08 +00:00
|
|
|
if [[ $result != "success" && $result != "skipped" ]]; then
|
2024-01-13 04:32:14 +00:00
|
|
|
echo "One or more lint jobs have failed."
|
2023-11-17 02:23:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-01-13 04:32:14 +00:00
|
|
|
result="${{ needs.project-test-jobs.result }}"
|
2023-11-17 02:23:08 +00:00
|
|
|
if [[ $result != "success" && $result != "skipped" ]]; then
|
2024-01-13 04:32:14 +00:00
|
|
|
echo "One or more test jobs have failed."
|
2023-11-17 02:23:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-01-13 04:32:14 +00:00
|
|
|
echo "All jobs have completed successfully."
|