-
Notifications
You must be signed in to change notification settings - Fork 6
225 lines (216 loc) · 8.29 KB
/
Copy pathgithub-actions-self-test.yml
File metadata and controls
225 lines (216 loc) · 8.29 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: GitHub Actions Self-Test
on:
push:
branches:
- trunk
paths:
- packages/github-actions/**
- .github/workflows/github-actions-self-test.yml
pull_request:
paths:
- packages/github-actions/**
- .github/workflows/github-actions-self-test.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
unit-test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Install dependencies
working-directory: packages/github-actions
run: npm ci --ignore-scripts
- name: Run unit tests
working-directory: packages/github-actions
run: npm test
build-check:
name: Build Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Install dependencies
working-directory: packages/github-actions
run: npm ci --ignore-scripts
- name: Verify build succeeds
working-directory: packages/github-actions
run: npm run build
test-prepare-node:
name: "prepare-node (Node ${{ matrix.node-version }}, deps: ${{ matrix.install-deps }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['24', '22', '20']
install-deps: ['yes', 'no']
ignore-scripts: ['yes']
include:
- node-version: '24'
install-deps: 'yes'
ignore-scripts: 'no'
steps:
- uses: actions/checkout@v6
- uses: ./packages/github-actions/actions/prepare-node
with:
node-version: ${{ matrix.node-version }}
install-deps: ${{ matrix.install-deps }}
ignore-scripts: ${{ matrix.ignore-scripts }}
- name: Verify Node.js major version
env:
EXPECTED_VERSION: ${{ matrix.node-version }}
run: |
ACTUAL=$(node --version | sed 's/^v//' | cut -d. -f1)
if [ "$ACTUAL" != "$EXPECTED_VERSION" ]; then
echo "Expected Node $EXPECTED_VERSION but got $ACTUAL"
exit 1
fi
# prepare-node runs `npm ci` from the workspace root, so the installed
# node_modules lives there. Pin the verification to the same directory.
- name: Verify node_modules exists
if: matrix.install-deps == 'yes'
working-directory: ${{ github.workspace }}
run: test -d node_modules
- name: Verify node_modules does not exist
if: matrix.install-deps == 'no'
working-directory: ${{ github.workspace }}
run: test ! -d node_modules
test-prepare-php:
name: "prepare-php (PHP ${{ matrix.php-version }}, deps: ${{ matrix.install-deps }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.2', '8.4']
install-deps: ['no']
include:
- php-version: '8.2'
install-deps: 'yes'
steps:
- uses: actions/checkout@v6
- name: Create minimal Composer project for install test
if: matrix.install-deps == 'yes'
run: |
# The repo's own project depends on the private woocommerce/woorelease
# repo, which composer cannot fetch here. Replace it with a minimal
# public dependency and drop the lock so the install test is isolated.
rm -f composer.lock
echo '{"require": {"psr/log": "^3.0"}}' > composer.json
- uses: ./packages/github-actions/actions/prepare-php
with:
php-version: ${{ matrix.php-version }}
install-deps: ${{ matrix.install-deps }}
- name: Verify PHP version
env:
EXPECTED_VERSION: ${{ matrix.php-version }}
run: |
ACTUAL=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
if [ "$ACTUAL" != "$EXPECTED_VERSION" ]; then
echo "Expected PHP $EXPECTED_VERSION but got $ACTUAL"
exit 1
fi
- name: Verify Composer is available
run: composer --version
- name: Verify vendor directory exists
if: matrix.install-deps == 'yes'
run: test -d vendor
test-prepare-mysql:
name: prepare-mysql
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./packages/github-actions/actions/prepare-mysql
- name: Verify MySQL connection
run: mysql -u root -proot -e "SELECT 1;"
test-eslint-formatter:
name: "eslint-annotation (eslint v${{ matrix.eslint-version }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
eslint-version: ['8', '9']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
- name: Build the formatter
working-directory: packages/github-actions
run: |
npm ci --ignore-scripts
npm run build
- name: Set up test environment
run: |
mkdir /tmp/formatter-test
cd /tmp/formatter-test
npm init -y
npm install eslint@${{ matrix.eslint-version }}
# Prepend eslint-disable to suppress linting on the formatter itself
echo '/* eslint-disable */' > eslintFormatter.cjs
cat "$GITHUB_WORKSPACE/packages/github-actions/actions/eslint-annotation/eslintFormatter.cjs" >> eslintFormatter.cjs
# Create a file with a known lint error
echo 'var unused = 1;' > sample.js
- name: Verify formatter produces annotation commands
working-directory: /tmp/formatter-test
run: |
MAJOR=$(./node_modules/.bin/eslint --version | cut -d. -f1 | tr -d 'v')
if [ "$MAJOR" -ge 9 ]; then
CONFIG_FLAG="--no-config-lookup"
else
CONFIG_FLAG="--no-eslintrc"
fi
# eslint's exit code comes from its own error count, not the formatter, so a
# non-zero-exit assertion would add nothing. The annotation grep is the guard.
OUTPUT=$(./node_modules/.bin/eslint sample.js $CONFIG_FLAG --rule 'no-unused-vars: error' --format ./eslintFormatter.cjs 2>&1 || true)
echo "$OUTPUT"
echo "$OUTPUT" | grep -qE '^::(error|warning) '
test-stylelint-formatter:
name: "stylelint-annotation (stylelint v${{ matrix.stylelint-version }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
stylelint-version: ['15', '16', '17']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
- name: Build the formatter
working-directory: packages/github-actions
run: |
npm ci --ignore-scripts
npm run build
- name: Set up test environment
run: |
mkdir /tmp/formatter-test
cd /tmp/formatter-test
npm init -y
npm install stylelint@${{ matrix.stylelint-version }}
# Prepend eslint-disable to suppress linting on the stylelint formatter
echo '/* eslint-disable */' > stylelintFormatter.cjs
cat "$GITHUB_WORKSPACE/packages/github-actions/actions/stylelint-annotation/stylelintFormatter.cjs" >> stylelintFormatter.cjs
# Create a CSS file with a known lint error (duplicate property)
echo 'a { color: red; color: blue; }' > sample.css
echo '{"rules": {"declaration-block-no-duplicate-properties": true}}' > .stylelintrc.json
- name: Verify formatter annotates and fails on lint errors
working-directory: /tmp/formatter-test
run: |
OUTPUT=$(./node_modules/.bin/stylelint sample.css --custom-formatter ./stylelintFormatter.cjs 2>&1) && STATUS=0 || STATUS=$?
echo "$OUTPUT"
echo "stylelint exit status: $STATUS"
# The formatter must emit annotation commands.
echo "$OUTPUT" | grep -qE '^::(error|warning) '
# Lint errors must make stylelint exit non-zero. A formatter that returns an
# empty report makes stylelint's CLI skip its exit-code assignment, which
# would let lint errors pass CI with a green check.
if [ "$STATUS" -eq 0 ]; then
echo "Expected stylelint to exit non-zero for lint errors, but it exited 0."
exit 1
fi