Revert "Update ci.yml to be dispatchable and skippable" (#49442)

This commit is contained in:
Adrian Moldovan 2024-07-12 10:52:16 +01:00 committed by GitHub
parent 892c44a27a
commit b9d6439b9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 76 deletions

View File

@ -14,12 +14,6 @@ on:
required: true required: true
default: 'default' default: 'default'
type: string type: string
workflow_dispatch:
inputs:
pr_simulate:
description: 'Would you like to run CI on a pull request? If so, enter the PR number here. If blank, the entire suite will be run.'
type: string
default: ''
concurrency: concurrency:
group: '${{ github.workflow }}-${{ github.ref }}' group: '${{ github.workflow }}-${{ github.ref }}'
@ -29,33 +23,6 @@ env:
FORCE_COLOR: 1 FORCE_COLOR: 1
jobs: jobs:
dispatch-handler:
name: 'Handle dispatched workflow'
runs-on: 'ubuntu-20.04'
if: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_simulate }}
outputs:
head: ${{ steps.pr-info.outputs.head }}
base: ${{ steps.pr-info.outputs.base }}
steps:
- uses: actions/github-script@v7
name: 'Grab PR info.'
id: 'pr-info'
env:
PR: ${{ inputs.pr_simulate }}
with:
retries: 3
script: |
if ( ! process.env.PR ) {
return;
}
const PR = await github.rest.pulls.get( {
pull_number: process.env.PR,
repo: context.repo.repo,
owner: context.repo.owner,
} );
core.setOutput( 'head', PR.data.head.ref );
core.setOutput( 'base', PR.data.base.ref );
project-jobs: project-jobs:
# Since this is a monorepo, not every pull request or change is going to impact every project. # Since this is a monorepo, not every pull request or change is going to impact every project.
# Instead of running CI tasks on all projects indiscriminately, we use a command to detect # Instead of running CI tasks on all projects indiscriminately, we use a command to detect
@ -63,12 +30,6 @@ jobs:
# matrices that we can use to run CI tasks only on the projects that need them. # matrices that we can use to run CI tasks only on the projects that need them.
name: 'Build Project Jobs' name: 'Build Project Jobs'
runs-on: 'ubuntu-20.04' runs-on: 'ubuntu-20.04'
needs: 'dispatch-handler'
# Because forks of this repository may want to skip running this CI automatically, but still
# be able to run it via workflow_dispatch, if the SKIP_CI variable is truthy, and we're not
# running from a workflow_dispatch, we'll skip generating the project matrix and any jobs.
# Because dispatch-handler may be skipped, we need the always() here.
if: ${{ always() && ( github.event_name == 'workflow_dispatch' || ! vars.SKIP_CI ) }}
outputs: outputs:
lint-jobs: ${{ steps.project-jobs.outputs.lint-jobs }} lint-jobs: ${{ steps.project-jobs.outputs.lint-jobs }}
test-jobs: ${{ steps.project-jobs.outputs.test-jobs }} test-jobs: ${{ steps.project-jobs.outputs.test-jobs }}
@ -78,24 +39,16 @@ jobs:
name: 'Checkout' name: 'Checkout'
with: with:
fetch-depth: 0 fetch-depth: 0
# If the workflow wasn't triggered by dispatch, this will be empty and use defaults.
ref: ${{ needs.dispatch-handler.outputs.head }}
- uses: './.github/actions/setup-woocommerce-monorepo' - uses: './.github/actions/setup-woocommerce-monorepo'
name: 'Setup Monorepo' name: 'Setup Monorepo'
with: with:
php-version: false # We don't want to waste time installing PHP since we aren't using it in this job. 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@v7 - uses: actions/github-script@v7
name: 'Build Matrix' name: 'Build Matrix'
id: 'project-jobs' id: 'project-jobs'
env:
PR_SIM: ${{ needs.dispatch-handler.outputs.base }}
with: with:
script: | script: |
const prSim = process.env.PR_SIM; let baseRef = ${{ toJson( github.base_ref ) }};
let baseRef = prSim || ${{ toJson( github.base_ref ) }};
if ( baseRef ) { if ( baseRef ) {
baseRef = `--base-ref origin/${ baseRef }`; baseRef = `--base-ref origin/${ baseRef }`;
} }
@ -118,35 +71,23 @@ jobs:
githubEvent = trigger; githubEvent = trigger;
} }
// Override the event 'workflow_dispatch' event type if we're simulating a PR.
if ( prSim ) {
githubEvent = 'pull_request';
}
const child_process = require( 'node:child_process' ); const child_process = require( 'node:child_process' );
child_process.execSync( `pnpm utils ci-jobs ${ baseRef } --event ${ githubEvent }` ); child_process.execSync( `pnpm utils ci-jobs ${ baseRef } --event ${ githubEvent }` );
project-lint-jobs: project-lint-jobs:
name: "Lint - ${{ matrix.projectName }} ${{ matrix.optional && ' (optional)' || ''}}" name: "Lint - ${{ matrix.projectName }} ${{ matrix.optional && ' (optional)' || ''}}"
runs-on: 'ubuntu-20.04' runs-on: 'ubuntu-20.04'
needs: [ needs: 'project-jobs'
'project-jobs', if: ${{ needs.project-jobs.outputs.lint-jobs != '[]' && github.event_name == 'pull_request' }}
'dispatch-handler'
]
# Because dispatch-handler may be skipped, we need the always() here.
if: ${{ always() && needs.project-jobs.outputs.lint-jobs != '[]' && ( github.event_name == 'pull_request' || inputs.pr_simulate != '' ) }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: ${{ fromJSON( needs.project-jobs.outputs.lint-jobs ) }} include: ${{ fromJSON( needs.project-jobs.outputs.lint-jobs ) }}
steps: steps:
- uses: 'actions/checkout@v4' - uses: 'actions/checkout@v4'
name: 'Checkout' name: 'Checkout'
with: with:
fetch-depth: 0 fetch-depth: 0
# If the workflow wasn't triggered by dispatch, this will be empty and use defaults.
ref: ${{ needs.dispatch-handler.outputs.head }}
- uses: './.github/actions/setup-woocommerce-monorepo' - uses: './.github/actions/setup-woocommerce-monorepo'
name: 'Setup Monorepo' name: 'Setup Monorepo'
@ -161,23 +102,16 @@ jobs:
project-test-jobs: project-test-jobs:
name: "${{ matrix.name }}" name: "${{ matrix.name }}"
runs-on: 'ubuntu-20.04' runs-on: 'ubuntu-20.04'
needs: [ needs: 'project-jobs'
'project-jobs', if: ${{ needs.project-jobs.outputs.test-jobs != '[]' }}
'dispatch-handler'
]
if: ${{ always() && needs.project-jobs.outputs.test-jobs != '[]' }}
env: ${{ matrix.testEnv.envVars }} env: ${{ matrix.testEnv.envVars }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: ${{ fromJSON( needs.project-jobs.outputs.test-jobs ) }} include: ${{ fromJSON( needs.project-jobs.outputs.test-jobs ) }}
steps: steps:
- uses: 'actions/checkout@v4' - uses: 'actions/checkout@v4'
name: 'Checkout' name: 'Checkout'
with:
# If the workflow wasn't triggered by dispatch, this will be empty and use defaults.
ref: ${{ needs.dispatch-handler.outputs.head }}
- uses: './.github/actions/setup-woocommerce-monorepo' - uses: './.github/actions/setup-woocommerce-monorepo'
name: 'Install Monorepo' name: 'Install Monorepo'