forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (108 loc) · 4.59 KB
/
reusable-test-core-build-process.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
115
116
117
118
119
120
121
122
123
124
##
# A reusable workflow that tests the WordPress Core build process.
##
name: Test the WordPress Build Process
on:
workflow_call:
inputs:
os:
description: 'Operating system to run tests on'
required: false
type: 'string'
default: 'ubuntu-latest'
directory:
description: 'Directory to run WordPress from. Valid values are `src` or `build`'
required: false
type: 'string'
default: 'src'
test-emoji:
description: 'Whether to run the grunt precommit:emoji script.'
required: false
type: 'boolean'
default: true
save-build:
description: 'Whether to save a ZIP of built WordPress as an artifact.'
required: false
type: 'boolean'
default: false
prepare-playground:
description: 'Whether to prepare the artifacts needed for Playground testing.'
required: false
type: 'boolean'
default: false
env:
PUPPETEER_SKIP_DOWNLOAD: ${{ true }}
jobs:
# Verifies that installing npm dependencies and building WordPress works as expected.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up Node.js.
# - Logs debug information about the GitHub Action runner.
# - Installs npm dependencies.
# - Builds WordPress to run from the desired location (src or build).
# - Ensures version-controlled files are not modified or deleted.
# - Creates a ZIP of the built WordPress files (when building to the build directory).
# - Cleans up after building WordPress.
# - Ensures version-controlled files are not modified or deleted.
# - Uploads the ZIP as a GitHub Actions artifact (when building to the build directory).
# - Saves the pull request number to a text file.
# - Uploads the pull request number as an artifact.
build-process-tests:
name: Core running from ${{ inputs.directory }} / ${{ contains( inputs.os, 'macos-' ) && 'MacOS' || contains( inputs.os, 'windows-' ) && 'Windows' || 'Linux' }}
runs-on: ${{ inputs.os }}
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
- name: Set up Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: Log debug information
run: |
npm --version
node --version
curl --version
git --version
- name: Install npm Dependencies
run: npm ci
- name: Run Emoji precommit task
if: ${{ inputs.test-emoji }}
run: npm run grunt precommit:emoji
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build WordPress to run from ${{ inputs.directory }}
run: npm run build${{ inputs.directory == 'src' && ':dev' || '' }}
- name: Ensure version-controlled files are not modified or deleted during building
run: git diff --exit-code
- name: Create ZIP of built files
if: ${{ inputs.directory == 'build' && 'ubuntu-latest' == inputs.os }}
run: zip -r wordpress.zip build/.
- name: Clean after building to run from ${{ inputs.directory }}
run: npm run grunt clean${{ inputs.directory == 'src' && ' -- --dev' || '' }}
- name: Ensure version-controlled files are not modified or deleted during cleaning
run: git diff --exit-code
- name: Upload ZIP as a GitHub Actions artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: ${{ inputs.save-build || inputs.prepare-playground }}
with:
name: wordpress-build-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
path: wordpress.zip
if-no-files-found: error
- name: Save PR number
if: ${{ inputs.prepare-playground }}
run: |
mkdir -p ./pr-number
echo ${{ github.event.number }} > ./pr-number/NR
# Uploads the PR number as an artifact for the Pull Request Commenting workflow to download and then
# leave a comment detailing how to test the PR within WordPress Playground.
- name: Upload PR number as artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: ${{ inputs.prepare-playground && github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request' }}
with:
name: pr-number
path: pr-number/