2023-10-19 18:24:20 +00:00
name : 'CI'
2024-03-27 15:21:49 +00:00
on :
2024-04-17 11:31:16 +00:00
pull_request :
push :
branches :
- 'trunk'
- 'release/*'
2024-06-06 16:51:02 +00:00
release :
types : [ published, edited ]
2024-05-22 18:04:44 +00:00
workflow_call :
2024-06-04 20:03:38 +00:00
inputs :
trigger :
description : 'Type of run to trigger. E.g. daily-e2e, release-checks, etc.'
required : true
default : 'default'
type : string
2023-04-26 20:41:31 +00:00
concurrency :
2024-04-17 11:31:16 +00:00
group : '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress : true
2024-06-03 21:12:45 +00:00
env :
FORCE_COLOR : 1
2024-03-27 15:21:49 +00:00
2021-03-14 00:29:15 +00:00
jobs :
2024-04-17 11:31:16 +00:00
project-jobs :
# 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
# 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'
runs-on : 'ubuntu-20.04'
outputs :
lint-jobs : ${{ steps.project-jobs.outputs.lint-jobs }}
2024-06-06 18:50:52 +00:00
test-jobs : ${{ steps.project-jobs.outputs.test-jobs }}
report-jobs : ${{ steps.project-jobs.outputs.report-jobs }}
2024-04-17 11:31:16 +00:00
steps :
- uses : 'actions/checkout@v4'
name : 'Checkout'
with :
fetch-depth : 0
- uses : './.github/actions/setup-woocommerce-monorepo'
name : 'Setup Monorepo'
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@v7
name : 'Build Matrix'
id : 'project-jobs'
with :
script : |
let baseRef = ${{ toJson( github.base_ref ) }};
if ( baseRef ) {
baseRef = `--base-ref origin/${ baseRef }`;
}
2024-05-10 08:47:23 +00:00
2024-05-01 17:36:24 +00:00
let githubEvent = ${{ toJson( github.event_name ) }};
2024-06-05 16:02:54 +00:00
const refType = ${{ toJson( github.ref_type ) }};
const refName = ${{ toJson( github.ref_name ) }};
if ( refType === 'tag' && refName !== 'nightly' ) {
githubEvent = 'release-checks';
}
if ( refType === 'tag' && refName === 'nightly' ) {
githubEvent = 'nightly-checks';
}
2024-05-22 18:04:44 +00:00
let trigger = ${{ toJson( inputs.trigger ) }};
if ( trigger ) {
githubEvent = trigger;
}
2024-05-10 08:47:23 +00:00
2024-04-17 11:31:16 +00:00
const child_process = require( 'node:child_process' );
2024-05-01 17:36:24 +00:00
child_process.execSync( `pnpm utils ci-jobs ${ baseRef } --event ${ githubEvent }` );
2024-04-17 11:31:16 +00:00
project-lint-jobs :
2024-05-16 20:31:17 +00:00
name : "Lint - ${{ matrix.projectName }} ${{ matrix.optional && ' (optional)' || ''}}"
2024-04-17 11:31:16 +00:00
runs-on : 'ubuntu-20.04'
needs : 'project-jobs'
2024-05-23 14:16:07 +00:00
if : ${{ needs.project-jobs.outputs.lint-jobs != '[]' && github.event_name == 'pull_request' }}
2024-04-17 11:31:16 +00:00
strategy :
fail-fast : false
matrix :
include : ${{ fromJSON( needs.project-jobs.outputs.lint-jobs ) }}
steps :
- uses : 'actions/checkout@v4'
name : 'Checkout'
with :
fetch-depth : 0
2024-06-11 17:01:43 +00:00
2024-04-17 11:31:16 +00:00
- uses : './.github/actions/setup-woocommerce-monorepo'
name : 'Setup Monorepo'
id : 'setup-monorepo'
with :
install : '${{ matrix.projectName }}...'
2024-06-11 18:52:48 +00:00
build : '${{ matrix.projectName }}'
2024-06-11 17:01:43 +00:00
2024-04-17 11:31:16 +00:00
- name : 'Lint'
run : 'pnpm --filter="${{ matrix.projectName }}" ${{ matrix.command }}'
2024-06-06 18:50:52 +00:00
project-test-jobs :
name : "${{ matrix.name }}"
2024-04-17 11:31:16 +00:00
runs-on : 'ubuntu-20.04'
needs : 'project-jobs'
2024-06-06 18:50:52 +00:00
if : ${{ needs.project-jobs.outputs.test-jobs != '[]' }}
2024-05-21 21:33:43 +00:00
env : ${{ matrix.testEnv.envVars }}
2024-04-17 11:31:16 +00:00
strategy :
fail-fast : false
matrix :
2024-06-06 18:50:52 +00:00
include : ${{ fromJSON( needs.project-jobs.outputs.test-jobs ) }}
2024-04-17 11:31:16 +00:00
steps :
- uses : 'actions/checkout@v4'
name : 'Checkout'
2024-06-06 18:50:52 +00:00
2024-04-17 11:31:16 +00:00
- uses : './.github/actions/setup-woocommerce-monorepo'
2024-06-05 16:02:54 +00:00
name : 'Install Monorepo'
id : 'install-monorepo'
2024-04-17 11:31:16 +00:00
with :
2024-06-06 18:50:52 +00:00
install : '${{ matrix.projectName }}...'
build : 'false'
2024-06-05 16:02:54 +00:00
- uses : './.github/actions/setup-woocommerce-monorepo'
if : ${{ github.ref_type != 'tag' }}
name : 'Build project'
id : 'build-project'
with :
install : 'false'
build : ${{ matrix.projectName }}
2024-06-06 18:50:52 +00:00
2024-06-05 16:02:54 +00:00
- name : 'Update wp-env config'
if : ${{ github.ref_type == 'tag' }}
env :
2024-06-06 18:50:52 +00:00
RELEASE_TAG : ${{ github.ref_name }}
ARTIFACT_NAME : ${{ github.ref_name == 'nightly' && 'woocommerce-trunk-nightly.zip' || 'woocommerce.zip' }}
2024-06-05 16:02:54 +00:00
working-directory : ${{ matrix.projectPath }}
run : node ./tests/e2e-pw/bin/override-wp-env-plugins.js
2024-06-28 13:50:32 +00:00
- name : 'Cache Playwright Downloads'
id : 'cache-playwright-downloads'
if : ${{ matrix.testEnv.shouldCreate }}
uses : 'actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319'
with :
path : '~/.cache/ms-playwright/'
key : "${{ runner.os }}-playwright-${{ hashFiles( '**/pnpm-lock.yaml' ) }}"
restore-keys : '${{ runner.os }}-playwright-'
2024-06-06 18:50:52 +00:00
2024-06-03 21:12:45 +00:00
- name : 'Start Test Environment'
2024-04-17 11:31:16 +00:00
id : 'prepare-test-environment'
if : ${{ matrix.testEnv.shouldCreate }}
2024-06-06 18:50:52 +00:00
env : ${{ matrix.testEnv.envVars }}
2024-04-17 11:31:16 +00:00
run : 'pnpm --filter="${{ matrix.projectName }}" ${{ matrix.testEnv.start }}'
2024-06-06 18:50:52 +00:00
- name : 'Get commit message'
id : 'get_commit_message'
env :
HEAD_COMMIT_MESSAGE : ${{ github.event.head_commit.message }}
PR_TITLE : ${{ github.event.pull_request.title }}
run : |
if [[ "${{ github.event_name }}" == "push" ]]; then
COMMIT_MESSAGE=`echo "$HEAD_COMMIT_MESSAGE" | head -1`
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
COMMIT_MESSAGE="$PR_TITLE"
else
COMMIT_MESSAGE="${{ github.event_name }}"
fi
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> "$GITHUB_OUTPUT"
shell : bash
2024-04-17 11:31:16 +00:00
- name : 'Run tests'
2024-05-16 18:31:21 +00:00
env :
2024-06-06 18:50:52 +00:00
BUILDKITE_ANALYTICS_TOKEN : ${{ secrets.BUILDKITE_CORE_E2E_TOKEN }}
BUILDKITE_ANALYTICS_MESSAGE : ${{ steps.get_commit_message.outputs.COMMIT_MESSAGE }}
CODEVITALS_PROJECT_TOKEN : ${{ secrets.CODEVITALS_PROJECT_TOKEN }} # required by Metrics tests
2024-04-17 11:31:16 +00:00
run : 'pnpm --filter="${{ matrix.projectName }}" ${{ matrix.command }}'
2024-06-06 18:50:52 +00:00
2024-06-11 16:57:23 +00:00
- name : 'Resolve artifacts path'
2024-06-17 17:16:04 +00:00
if : ${{ always() && matrix.report.resultsPath != '' }}
2024-06-11 16:57:23 +00:00
# Blocks e2e use a relative path which is not supported by actions/upload-artifact@v4
# https://github.com/actions/upload-artifact/issues/176
env :
ARTIFACTS_PATH : '${{ matrix.projectPath }}/${{ matrix.report.resultsPath }}'
run : echo "ARTIFACTS_PATH=$(realpath $ARTIFACTS_PATH)" >> $GITHUB_ENV
2024-04-17 11:31:16 +00:00
- name : 'Upload artifacts'
2024-06-06 18:50:52 +00:00
if : ${{ always() && matrix.report.resultsPath != '' }}
2024-04-17 11:31:16 +00:00
uses : actions/upload-artifact@v4
with :
2024-06-14 16:03:43 +00:00
name : '${{ matrix.report.resultsBlobName }}__${{ strategy.job-index }}'
2024-06-11 16:57:23 +00:00
path : ${{ env.ARTIFACTS_PATH }}
- name : 'Upload flaky test reports'
uses : actions/upload-artifact@v4
with :
name : flaky-tests-${{ strategy.job-index }}
path : ${{ env.ARTIFACTS_PATH }}/flaky-tests
if-no-files-found : ignore
2024-04-17 11:31:16 +00:00
2024-06-06 18:50:52 +00:00
- name : 'Archive metrics results'
if : ${{ success() && startsWith(matrix.name, 'Metrics') }} # this seems too fragile, we should update the reporting path and use the generic upload step above
2024-04-17 11:31:16 +00:00
uses : actions/upload-artifact@v4
env :
2024-06-06 18:50:52 +00:00
WP_ARTIFACTS_PATH : ${{ github.workspace }}/artifacts
2024-04-17 11:31:16 +00:00
with :
2024-06-06 18:50:52 +00:00
name : metrics-results
path : ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json
2024-04-17 11:31:16 +00:00
evaluate-project-jobs :
# In order to add a required status check we need a consistent job that we can grab onto.
# Since we are dynamically generating a matrix for the project jobs, however, we can't
# rely 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'
runs-on : 'ubuntu-20.04'
needs :
[
'project-jobs' ,
'project-lint-jobs' ,
2024-06-06 18:50:52 +00:00
'project-test-jobs' ,
2024-04-17 11:31:16 +00:00
]
2024-05-21 21:28:24 +00:00
if : ${{ always() && github.event_name == 'pull_request' }}
2024-04-17 11:31:16 +00:00
steps :
2024-05-16 20:31:17 +00:00
- uses : 'actions/checkout@v4'
name : 'Checkout'
2024-06-04 20:03:38 +00:00
2024-04-17 11:31:16 +00:00
- name : 'Evaluation'
2024-05-16 20:31:17 +00:00
env :
2024-06-04 20:03:38 +00:00
REPOSITORY : ${{ github.repository }}
RUN_ID : ${{ github.run_id }}
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2024-04-17 11:31:16 +00:00
run : |
2024-05-16 20:31:17 +00:00
# Check if project-jobs was successful. Fail for any other status, including skipped.
2024-04-17 11:31:16 +00:00
result="${{ needs.project-jobs.result }}"
2024-05-16 20:31:17 +00:00
if [[ $result != "success" ]]; then
echo "Generating CI jobs was not successful."
2024-04-17 11:31:16 +00:00
exit 1
fi
2024-06-04 20:03:38 +00:00
node .github/workflows/scripts/evaluate-jobs-conclusions.js
2024-05-24 20:18:54 +00:00
alert-on-failure :
name : 'Report results on Slack'
runs-on : 'ubuntu-20.04'
needs :
[
'project-jobs' ,
'project-lint-jobs' ,
2024-06-06 18:50:52 +00:00
'project-test-jobs' ,
2024-05-24 20:18:54 +00:00
]
if : ${{ always() && github.event_name != 'pull_request' }}
steps :
- uses : 'actions/checkout@v4'
name : 'Checkout'
2024-06-04 20:03:38 +00:00
2024-05-24 20:18:54 +00:00
- uses : './.github/actions/setup-woocommerce-monorepo'
name : 'Setup Monorepo'
with :
2024-06-04 20:03:38 +00:00
php-version : false
2024-05-24 20:18:54 +00:00
- name : 'Send messages for failed jobs'
env :
2024-06-04 20:03:38 +00:00
SLACK_TOKEN : ${{ secrets.E2E_SLACK_TOKEN }}
SLACK_CHANNEL : ${{ secrets.TEST_REPORTS_SLACK_CHANNEL }}
HEAD_COMMIT_MESSAGE : ${{ github.event.head_commit.message }}
INPUT_TRIGGER : ${{ inputs.trigger }}
2024-06-06 18:50:52 +00:00
RUN_TYPE : ${{ github.ref_type == 'tag' && (github.ref_name == 'nightly' && 'nightly-checks' || 'release-checks') || '' }}
2024-05-24 20:18:54 +00:00
run : |
COMMIT_MESSAGE=`echo "$HEAD_COMMIT_MESSAGE" | head -1`
2024-06-06 18:50:52 +00:00
if [[ -n "${INPUT_TRIGGER}" ]]; then
CHECKS_TYPE="${INPUT_TRIGGER}"
else
CHECKS_TYPE="${RUN_TYPE}"
fi
2024-06-04 20:03:38 +00:00
2024-06-06 18:50:52 +00:00
pnpm utils slack-test-report -c "${{ needs.project-jobs.result }}" -r "$CHECKS_TYPE Build jobs matrix" -m "$COMMIT_MESSAGE"
pnpm utils slack-test-report -c "${{ needs.project-lint-jobs.result }}" -r "$CHECKS_TYPE Linting" -m "$COMMIT_MESSAGE"
pnpm utils slack-test-report -c "${{ needs.project-test-jobs.result }}" -r "$CHECKS_TYPE Tests" -m "$COMMIT_MESSAGE"
2024-05-24 20:18:54 +00:00
2024-06-06 18:50:52 +00:00
test-reports :
2024-06-10 18:21:46 +00:00
name : 'Test reports - ${{ matrix.report }}'
2024-06-06 18:50:52 +00:00
needs :
[
'project-jobs' ,
'project-test-jobs' ,
]
if : ${{ always() && needs.project-jobs.outputs.report-jobs != '[]' }}
strategy :
fail-fast : false
matrix :
report : ${{ fromJSON( needs.project-jobs.outputs.report-jobs ) }}
2024-04-17 11:31:16 +00:00
runs-on : ubuntu-latest
2024-06-19 16:37:50 +00:00
env :
ARTIFACT_NAME : ${{ matrix.report }}-attempt-${{ github.run_attempt }}
2024-04-17 11:31:16 +00:00
steps :
- uses : actions/checkout@v4
2024-06-10 18:21:46 +00:00
- name : 'Merge artifacts'
2024-06-19 16:37:50 +00:00
id : merge-artifacts
2024-06-10 18:21:46 +00:00
uses : actions/upload-artifact/merge@v4
continue-on-error : true
with :
2024-06-19 16:37:50 +00:00
name : ${{ env.ARTIFACT_NAME }}
2024-06-14 16:03:43 +00:00
pattern : ${{ matrix.report }}__*
2024-06-10 18:21:46 +00:00
delete-merged : true
2024-04-17 11:31:16 +00:00
2024-06-06 18:50:52 +00:00
- name : 'Publish report to dashboard'
2024-06-19 16:37:50 +00:00
if : ${{ !! steps.merge-artifacts.outputs.artifact-id }}
2024-06-12 20:38:37 +00:00
env :
GH_TOKEN : ${{ secrets.REPORTS_TOKEN }}
PR_NUMBER : ${{ github.event.pull_request.number }}
REPORT_NAME : ${{ matrix.report }}
HEAD_COMMIT_MESSAGE : ${{ github.event.head_commit.message }}
PR_TITLE : ${{ github.event.pull_request.title }}
EVENT_NAME : ${{ inputs.trigger == '' && github.event_name || inputs.trigger }}
run : |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
REPORT_TITLE="$PR_TITLE"
REF_NAME="$GITHUB_HEAD_REF"
elif [[ "${{ github.event_name }}" == "push" ]]; then
REPORT_TITLE=`echo "$HEAD_COMMIT_MESSAGE" | head -1`
REF_NAME="$GITHUB_REF_NAME"
else
REPORT_TITLE="$EVENT_NAME"
REF_NAME="$GITHUB_REF_NAME"
fi
gh workflow run report.yml \
2024-06-19 16:37:50 +00:00
-f artifact="$ARTIFACT_NAME" \
2024-06-12 20:38:37 +00:00
-f run_id="$GITHUB_RUN_ID" \
2024-06-17 17:14:32 +00:00
-f run_attempt="$GITHUB_RUN_ATTEMPT" \
2024-06-12 20:38:37 +00:00
-f event="$EVENT_NAME" \
-f pr_number="$PR_NUMBER" \
-f ref_name="$REF_NAME" \
-f commit_sha="$GITHUB_SHA" \
-f repository="$GITHUB_REPOSITORY" \
-f suite="$REPORT_NAME" \
-f report_title="$REPORT_TITLE" \
--repo woocommerce/woocommerce-test-reports
2024-06-11 16:57:23 +00:00
report-flaky-tests :
name : 'Create issues for flaky tests'
if : ${{ !cancelled() && ! github.event.pull_request.head.repo.fork }}
needs : [ 'project-test-jobs' ]
runs-on : ubuntu-latest
permissions :
contents : read
issues : write
steps :
- uses : actions/checkout@v4
with :
repository : WordPress/gutenberg
ref : dbf201449e9736f672b61e422787d47659db327a
- uses : actions/download-artifact@v4
id : download-artifact
with :
pattern : flaky-tests*
path : flaky-tests
merge-multiple : true
- name : 'Check if there are flaky tests reports'
run : |
downloadPath='${{ steps.download-artifact.outputs.download-path }}'
# make dir so that next step doesn't fail if it doesn't exist
mkdir -p $downloadPath
# any output means there are reports
echo "FLAKY_REPORTS=$(ls -A $downloadPath | head -1)" >> $GITHUB_ENV
- name : 'Setup'
if : ${{ !!env.FLAKY_REPORTS }}
uses : ./.github/setup-node
- name : 'Build packages'
if : ${{ !!env.FLAKY_REPORTS }}
run : npm run build:packages
- name : 'Report flaky tests'
if : ${{ !!env.FLAKY_REPORTS }}
uses : ./packages/report-flaky-tests
with :
repo-token : ${{ secrets.GITHUB_TOKEN }}
label: 'metric : flaky e2e test'