-
Notifications
You must be signed in to change notification settings - Fork 4.8k
149 lines (131 loc) · 7.35 KB
/
Copy pathperformance.yml
File metadata and controls
149 lines (131 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Performance Tests
on:
pull_request:
release:
types: [published]
push:
branches: [trunk]
workflow_dispatch:
inputs:
branches:
description: 'branches or commits to compare (comma separated)'
required: true
wpversion:
description: 'The base WP version to use for the tests (latest or 6.0, 6.1...)'
required: false
default: 'latest'
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
performance:
timeout-minutes: 60
name: Run performance tests
runs-on: 'ubuntu-24.04'
permissions:
contents: read
if: ${{ github.repository == 'WordPress/gutenberg' }}
env:
WP_ARTIFACTS_PATH: ${{ github.workspace }}/artifacts
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false
- name: Setup Node.js and install dependencies
uses: ./.github/setup-node
- name: Install NVM
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm -v
- name: Compare performance with base branch
if: github.event_name == 'pull_request'
run: npm exec --no release-cli -- perf "$GITHUB_SHA" "$GITHUB_BASE_REF" --tests-branch "$GITHUB_SHA"
- name: Compare performance with current WordPress Core and previous Gutenberg versions
if: github.event_name == 'release'
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
shell: bash
run: |
PLUGIN_VERSION="${RELEASE_TAG#v}"
if [[ ! "$PLUGIN_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
echo "::error::Release tag '$RELEASE_TAG' does not resolve to a valid Gutenberg plugin version."
exit 1
fi
IFS=. read -ra PLUGIN_VERSION_ARRAY <<< "$PLUGIN_VERSION"
CURRENT_RELEASE_BRANCH="release/${PLUGIN_VERSION_ARRAY[0]}.${PLUGIN_VERSION_ARRAY[1]}"
PREVIOUS_VERSION_BASE_10=$((PLUGIN_VERSION_ARRAY[0] * 10 + PLUGIN_VERSION_ARRAY[1] - 1))
PREVIOUS_RELEASE_BRANCH="release/$((PREVIOUS_VERSION_BASE_10 / 10)).$((PREVIOUS_VERSION_BASE_10 % 10))"
if ! git ls-remote --exit-code --tags origin "$RELEASE_TAG" > /dev/null; then
echo "::error::Expected release tag '$RELEASE_TAG' to exist in the Gutenberg repository."
exit 1
fi
if ! git ls-remote --exit-code --heads origin "$CURRENT_RELEASE_BRANCH" > /dev/null; then
echo "::error::Expected current release branch '$CURRENT_RELEASE_BRANCH' to exist in the Gutenberg repository."
exit 1
fi
if ! git ls-remote --exit-code --heads origin "$PREVIOUS_RELEASE_BRANCH" > /dev/null; then
echo "::error::Expected previous release branch '$PREVIOUS_RELEASE_BRANCH' to exist in the Gutenberg repository."
exit 1
fi
WP_VERSION="$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt)"
IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION"
WP_MAJOR="${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}"
npm exec --no release-cli -- perf "wp/$WP_MAJOR" "$PREVIOUS_RELEASE_BRANCH" "$CURRENT_RELEASE_BRANCH" --tests-branch "$GITHUB_SHA" --wp-version "$WP_MAJOR"
- name: Compare performance with base branch
if: github.event_name == 'push'
# The base hash used here need to be a commit that is compatible with the current WP version
# The current one is 28d414f1327652e2b49e784ddc12098768991c62 and it needs to be updated every WP major release.
# It is used as a base comparison point to avoid fluctuation in the performance metrics.
# See: https://developer.wordpress.org/block-editor/explanations/architecture/performance/#update-the-reference-commit.
run: |
WP_VERSION="$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt)"
IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION"
WP_MAJOR="${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}"
npm exec --no release-cli -- perf "$GITHUB_SHA" 28d414f1327652e2b49e784ddc12098768991c62 --tests-branch "$GITHUB_SHA" --wp-version "$WP_MAJOR"
- name: Compare performance with custom branches
if: github.event_name == 'workflow_dispatch'
env:
BRANCHES: ${{ github.event.inputs.branches }}
WP_VERSION: ${{ github.event.inputs.wpversion }}
run: |
npm exec --no release-cli -- perf "$(echo "$BRANCHES" | tr ',' ' ')" --tests-branch "$GITHUB_SHA" --wp-version "$WP_VERSION"
- name: Add workflow summary
run: cat "${WP_ARTIFACTS_PATH}/summary.md" >> "$GITHUB_STEP_SUMMARY"
- name: Archive performance results
if: success()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: performance-results
path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json
- name: Archive performance traces
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: performance-traces
path: |
${{ env.WP_ARTIFACTS_PATH }}/traces
${{ env.WP_ARTIFACTS_PATH }}/build
if-no-files-found: ignore
- name: Publish performance results
if: github.event_name == 'push'
env:
CODEHEALTH_PROJECT_TOKEN: ${{ secrets.CODEHEALTH_PROJECT_TOKEN }}
run: |
COMMITTED_AT="$(git show -s "$GITHUB_SHA" --format="%cI")"
npm run --workspace=tools/release log-performance-results -- "$CODEHEALTH_PROJECT_TOKEN" trunk "$GITHUB_SHA" 28d414f1327652e2b49e784ddc12098768991c62 "$COMMITTED_AT"
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: failure()
with:
name: failures-artifacts
path: ${{ env.WP_ARTIFACTS_PATH }}
if-no-files-found: ignore