|
1 | 1 | name: Test and Measure |
2 | 2 |
|
| 3 | +# Thin caller that delegates CI to the shared rtCamp orchestrator |
| 4 | +# (rtCamp/wp-shared-workflows). It runs detect-changes first, then the theme |
| 5 | +# preset's lint / test / build jobs, each gated on the changed-file buckets. |
3 | 6 | on: |
4 | 7 | push: |
5 | 8 | branches: |
|
13 | 16 | permissions: |
14 | 17 | contents: read |
15 | 18 |
|
16 | | -concurrency: |
17 | | - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} |
18 | | - cancel-in-progress: true |
19 | | - |
20 | 19 | jobs: |
21 | | - pre-run: |
22 | | - name: 'Pre run' |
23 | | - runs-on: ubuntu-latest |
24 | | - outputs: |
25 | | - changed-css-count: ${{ steps.determine-file-counts.outputs.css-count }} |
26 | | - changed-js-count: ${{ steps.determine-file-counts.outputs.js-count }} |
27 | | - changed-php-count: ${{ steps.determine-file-counts.outputs.php-count }} |
28 | | - changed-gha-workflow-count: ${{ steps.determine-file-counts.outputs.gha-workflow-count }} |
29 | | - |
30 | | - steps: |
31 | | - - name: Checkout including last 2 commits |
32 | | - # Fetch last 2 commits if it's not a PR, so that we can determine the list of modified files. |
33 | | - if: ${{ github.base_ref == null }} |
34 | | - uses: actions/checkout@v6 |
35 | | - with: |
36 | | - fetch-depth: 2 |
37 | | - |
38 | | - - name: Checkout |
39 | | - # Do usual checkout if it's a PR. |
40 | | - if: ${{ github.base_ref != null }} |
41 | | - uses: actions/checkout@v6 |
42 | | - |
43 | | - - name: Fetch base branch |
44 | | - # Only fetch base ref if it's a PR. |
45 | | - if: ${{ github.base_ref != null }} |
46 | | - run: git fetch --depth=1 --no-tags origin ${{ github.base_ref }} |
47 | | - |
48 | | - - name: Determine modified files for PR |
49 | | - if: ${{ github.base_ref != null }} |
50 | | - run: echo "MODIFIED_FILES=$(git diff --name-only FETCH_HEAD HEAD | base64 -w 0)" >> $GITHUB_ENV |
51 | | - |
52 | | - - name: Determine modified files for commit |
53 | | - if: ${{ github.base_ref == null }} |
54 | | - run: echo "MODIFIED_FILES=$(git diff --name-only HEAD~1 HEAD | base64 -w 0)" >> $GITHUB_ENV |
55 | | - |
56 | | - - id: determine-file-counts |
57 | | - name: Determine if modified files should make the workflow run continue |
58 | | - run: | |
59 | | - MODIFIED_FILES=$(echo "$MODIFIED_FILES" | base64 -d) |
60 | | - echo -e "Modified files:\n$MODIFIED_FILES\n" |
61 | | -
|
62 | | - MODIFIED_FILES_DATA=$(node .github/bin/determine-modified-files-count.js "$IGNORE_PATH_REGEX" "$MODIFIED_FILES" "all") |
63 | | - CSS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.s?css|package\.json|package-lock\.json" "$MODIFIED_FILES") |
64 | | - JS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.(js|snap)|package\.json|package-lock\.json" "$MODIFIED_FILES") |
65 | | - PHP_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.php|composer\.(json|lock)|phpstan\.neon\.dist" "$MODIFIED_FILES") |
66 | | - GHA_WORKFLOW_COUNT=$(node .github/bin/determine-modified-files-count.js "(\.github\/(workflows|actions)\/.+\.yml)" "$MODIFIED_FILES") |
67 | | -
|
68 | | - echo "Changed file count: $MODIFIED_FILES_DATA" |
69 | | - echo "Changed ${{ github.event.repository.name }} CSS file count: $CSS_FILE_COUNT" |
70 | | - echo "Changed ${{ github.event.repository.name }} JS file count: $JS_FILE_COUNT" |
71 | | - echo "Changed ${{ github.event.repository.name }} PHP file count: $PHP_FILE_COUNT" |
72 | | - echo "Changed GHA workflow/actions count: $GHA_WORKFLOW_COUNT" |
73 | | -
|
74 | | - echo "css-count=$CSS_FILE_COUNT" >> $GITHUB_OUTPUT |
75 | | - echo "js-count=$JS_FILE_COUNT" >> $GITHUB_OUTPUT |
76 | | - echo "php-count=$PHP_FILE_COUNT" >> $GITHUB_OUTPUT |
77 | | - echo "gha-workflow-count=$GHA_WORKFLOW_COUNT" >> $GITHUB_OUTPUT |
78 | | - env: |
79 | | - # Ignore Paths: |
80 | | - # - .github/ |
81 | | - # - !.github/workflows |
82 | | - # - !.github/actions |
83 | | - # - .wordpress-org/ |
84 | | - # - docs/ |
85 | | - IGNORE_PATH_REGEX: \.github\/(?!workflows)(?!actions)|\.wordpress-org\/|docs\/ |
86 | | - |
87 | | - - name: Summarize skipped jobs |
88 | | - run: | |
89 | | - SKIPPED=() |
90 | | -
|
91 | | - [[ "${{ steps.determine-file-counts.outputs.css-count }}" -le 0 ]] && SKIPPED+=("lint-css") |
92 | | - [[ "${{ steps.determine-file-counts.outputs.js-count }}" -le 0 ]] && SKIPPED+=("lint-js" "unit-tests-js" "build-prod") |
93 | | - [[ "${{ steps.determine-file-counts.outputs.php-count }}" -le 0 ]] && SKIPPED+=("lint-php") |
94 | | -
|
95 | | - if [[ ${#SKIPPED[@]} -gt 0 ]]; then |
96 | | - echo "The following jobs will be skipped as no relevant files were changed:" |
97 | | - for JOB in "${SKIPPED[@]}"; do |
98 | | - echo " - $JOB" |
99 | | - done |
100 | | - else |
101 | | - echo "All jobs will run." |
102 | | - fi |
103 | | -
|
104 | | - lint-css: |
105 | | - needs: pre-run |
106 | | - if: needs.pre-run.outputs.changed-css-count > 0 |
107 | | - name: 'Lint CSS' |
108 | | - runs-on: ubuntu-latest |
109 | | - steps: |
110 | | - - name: Checkout |
111 | | - uses: actions/checkout@v6 |
112 | | - |
113 | | - - name: Setup Node with cache |
114 | | - uses: ./.github/actions/setup-node-with-cache |
115 | | - |
116 | | - - name: Detect coding standard violations (stylelint) |
117 | | - run: npm run lint:css |
118 | | - |
119 | | - lint-js: |
120 | | - needs: pre-run |
121 | | - if: needs.pre-run.outputs.changed-js-count > 0 |
122 | | - name: 'Lint JS' |
123 | | - runs-on: ubuntu-latest |
124 | | - steps: |
125 | | - - name: Checkout |
126 | | - uses: actions/checkout@v6 |
127 | | - |
128 | | - - name: Setup Node with cache |
129 | | - uses: ./.github/actions/setup-node-with-cache |
130 | | - |
131 | | - - name: Detect coding standard violations (eslint) |
132 | | - run: npm run lint:js |
133 | | - |
134 | | - unit-tests-js: |
135 | | - needs: pre-run |
136 | | - if: needs.pre-run.outputs.changed-js-count > 0 |
137 | | - name: 'Run JS unit tests' |
138 | | - runs-on: ubuntu-latest |
139 | | - steps: |
140 | | - - name: Checkout |
141 | | - uses: actions/checkout@v6 |
142 | | - |
143 | | - - name: Setup Node with cache |
144 | | - uses: ./.github/actions/setup-node-with-cache |
145 | | - |
146 | | - - name: Run unit tests |
147 | | - run: npm run test:js |
148 | | - env: |
149 | | - CI: true |
150 | | - |
151 | | - lint-php: |
152 | | - needs: pre-run |
153 | | - if: needs.pre-run.outputs.changed-php-count > 0 |
154 | | - name: 'Lint PHP' |
155 | | - runs-on: ubuntu-latest |
156 | | - steps: |
157 | | - - name: Checkout |
158 | | - uses: actions/checkout@v6 |
159 | | - |
160 | | - - name: Setup PHP |
161 | | - uses: shivammathur/setup-php@v2 |
162 | | - with: |
163 | | - php-version: '8.2' |
164 | | - coverage: none |
165 | | - tools: cs2pr |
166 | | - github-token: ${{ secrets.WP_FRAMEWORK_REPO_TEMP_TOKEN }} |
167 | | - |
168 | | - - name: Get Composer Cache Directory |
169 | | - id: composer-cache |
170 | | - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
171 | | - |
172 | | - - name: Configure Composer cache |
173 | | - uses: actions/cache@v5.0.3 |
174 | | - with: |
175 | | - path: ${{ steps.composer-cache.outputs.dir }} |
176 | | - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
177 | | - restore-keys: | |
178 | | - ${{ runner.os }}-composer- |
179 | | -
|
180 | | - - name: Ensure git is installed |
181 | | - run: which git || (sudo apt-get update && sudo apt-get install -y git) |
182 | | - |
183 | | - - name: Install Composer dependencies |
184 | | - run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction --no-scripts |
185 | | - |
186 | | - - name: Validate composer.json |
187 | | - run: composer --no-interaction validate --no-check-all |
188 | | - |
189 | | - - name: Detect coding standard violations (PHPCS) |
190 | | - run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings |
191 | | - |
192 | | - build-prod: |
193 | | - needs: pre-run |
194 | | - if: needs.pre-run.outputs.changed-js-count > 0 || needs.pre-run.outputs.changed-css-count > 0 |
195 | | - name: 'Build production' |
196 | | - runs-on: ubuntu-latest |
197 | | - steps: |
198 | | - - name: Checkout |
199 | | - uses: actions/checkout@v6 |
200 | | - |
201 | | - - name: Setup Node with cache |
202 | | - uses: ./.github/actions/setup-node-with-cache |
203 | | - |
204 | | - - name: Build production |
205 | | - id: build |
206 | | - run: npm run build:prod |
207 | | - env: |
208 | | - CI: true |
209 | | - |
210 | | - unit-test-php: |
211 | | - needs: pre-run |
212 | | - if: needs.pre-run.outputs.changed-php-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0 |
213 | | - name: "PHP Unit test: PHP ${{ matrix.php }} / WP ${{ matrix.wp }}" |
214 | | - runs-on: ubuntu-latest |
215 | | - strategy: |
216 | | - fail-fast: false |
217 | | - matrix: |
218 | | - php: ['8.2', '8.3', '8.4'] |
219 | | - wp: ['6.5', '6.6', '6.7', '6.8', '6.9', '7.0'] |
220 | | - exclude: |
221 | | - # WordPress added PHP 8.4 support in 6.7. |
222 | | - - { php: '8.4', wp: '6.5' } |
223 | | - - { php: '8.4', wp: '6.6' } |
224 | | - env: |
225 | | - WP_ENV_PHP_VERSION: ${{ matrix.php }} |
226 | | - WP_ENV_CORE: WordPress/WordPress#${{ matrix.wp }} |
227 | | - steps: |
228 | | - - name: Checkout |
229 | | - uses: actions/checkout@v6 |
230 | | - |
231 | | - - name: Setup Node with cache |
232 | | - uses: ./.github/actions/setup-node-with-cache |
233 | | - |
234 | | - - name: Start WP environment |
235 | | - run: npm run wp-env start |
236 | | - |
237 | | - - name: Configure Composer GitHub auth in wp-env |
238 | | - run: npx wp-env run cli -- composer config --global github-oauth.github.com "${{ secrets.WP_FRAMEWORK_REPO_TEMP_TOKEN }}" |
239 | | - |
240 | | - - name: Run tests |
241 | | - run: npm run test:php |
| 20 | + ci: |
| 21 | + uses: rtCamp/wp-shared-workflows/.github/workflows/wp-ci.yml@release/v1.0.0 |
| 22 | + with: |
| 23 | + project-type: theme |
| 24 | + # PHPUnit matrix carried over from the previous workflow: PHP 8.2-8.4 x WP 6.5-7.0. |
| 25 | + php-versions: '["8.2", "8.3", "8.4"]' |
| 26 | + wp-versions: '["6.5", "6.6", "6.7", "6.8", "6.9", "7.0"]' |
| 27 | + # WordPress added PHP 8.4 support in 6.7. |
| 28 | + test-php-exclude: '[{"php": "8.4", "wp": "6.5"}, {"php": "8.4", "wp": "6.6"}]' |
| 29 | + secrets: |
| 30 | + # WP_FRAMEWORK_REPO_TEMP_TOKEN must have read access to both private repos: |
| 31 | + # - rtCamp/wp-tooling (detect-changes installs the interim CLI from it) |
| 32 | + # - rtCamp/wp-framework (composer install in lint-php / test-php) |
| 33 | + wp-tooling-token: ${{ secrets.WP_FRAMEWORK_REPO_TEMP_TOKEN }} |
| 34 | + packages-token: ${{ secrets.WP_FRAMEWORK_REPO_TEMP_TOKEN }} |
0 commit comments