forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (102 loc) · 3.95 KB
/
reusable-performance-report-v2.yml
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
##
# A reusable workflow that compares and publishes the performance tests.
##
name: Compare and publish performance Tests
on:
workflow_call:
inputs:
BASE_TAG:
description: 'The version being used for baseline measurements.'
required: true
type: string
memcached:
description: 'Whether to enable memcached.'
required: false
type: boolean
default: false
multisite:
description: 'Whether to use Multisite.'
required: false
type: boolean
default: false
publish:
description: 'Whether to publish the results to Code Vitals.'
required: false
type: boolean
default: false
secrets:
CODEVITALS_PROJECT_TOKEN:
description: 'The authorization token for https://www.codevitals.run/project/wordpress.'
required: false
env:
BASE_TAG: ${{ inputs.BASE_TAG }}
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
# Performs the following steps:
# - Checkout repository.
# - Set up Node.js.
# - Download the relevant performance test artifacts.
# - List the downloaded files for debugging.
# - Compare results.
# - Add workflow summary.
# - Determine the sha of the baseline tag if necessary.
# - Publish performance results if necessary.
compare:
name: ${{ inputs.multisite && 'Multisite' || 'Single Site' }} ${{ inputs.memcached && 'Memcached' || 'Default' }} ${{ inputs.publish && '(Publishes)' || '' }}
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
fetch-depth: ${{ github.event_name == 'workflow_dispatch' && '2' || '1' }}
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: Download artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: performance-${{ inputs.multisite && 'multisite' || 'single' }}-${{ inputs.memcached && 'memcached' || 'default' }}-*
path: artifacts
merge-multiple: true
- name: List files
run: tree artifacts
- name: Compare results
run: node ./tests/performance/compare-results.js "${RUNNER_TEMP}/summary.md"
- name: Add workflow summary
run: cat "${RUNNER_TEMP}/summary.md" >> "$GITHUB_STEP_SUMMARY"
- name: Set the base sha
# Only needed when publishing results.
if: ${{ inputs.publish }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: base-sha
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const baseRef = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/' + process.env.BASE_TAG,
});
return baseRef.data.object.sha;
- name: Publish performance results
if: ${{ inputs.publish }}
env:
BASE_SHA: ${{ steps.base-sha.outputs.result }}
CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }}
HOST_NAME: www.codevitals.run
run: |
if [ -z "$CODEVITALS_PROJECT_TOKEN" ]; then
echo "Performance results could not be published. 'CODEVITALS_PROJECT_TOKEN' is not set"
exit 1
fi
COMMITTED_AT="$(git show -s "$GITHUB_SHA" --format='%cI')"
node ./tests/performance/log-results.js "$CODEVITALS_PROJECT_TOKEN" trunk "$GITHUB_SHA" "$BASE_SHA" "$COMMITTED_AT" "$HOST_NAME"