Skip to content

Commit ff9c07e

Browse files
committed
Build/Test Tools: Include unversioned and binary files in change detection.
Every GitHub Actions workflow performing operations that may modify versioned files ends with a `git diff` check for uncommitted changes. The workflow run fails when changes exist to ensure requried changes are not missed in a given commit. Because the `git diff` only detects unstaged changes to tracked files, newly created files that were not also added to version control can easily go undetected. `git diff` also does not include changes to binary files by default. This commit makes the following changes to improve the related steps in workflow files: - The command used for detecting is changed to `git status --porcelain`, which only reports as clean when there are no changes to tracked files (both staged or unstaged) and there are no untracked files. - The related workflows have been updated to include `git add -A` before creating any patches to ensure that all new, modified, and deleted files are represented in the diff files created. - The `--binary` flag has been added to all `git diff` commands creating patches to ensure those changes are also included. Props desrosj. See #64893. git-svn-id: https://develop.svn.wordpress.org/trunk@62533 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b7eb73b commit ff9c07e

16 files changed

Lines changed: 166 additions & 58 deletions

.github/workflows/reusable-check-built-files.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ jobs:
2424
# - Builds Emoji files.
2525
# - Builds bundled Root Certificate files.
2626
# - Builds WordPress.
27-
# - Checks for changes to versioned files.
28-
# - Displays the result of git diff for debugging purposes.
29-
# - Saves the diff to a patch file.
27+
# - Checks for uncommitted changes.
28+
# - Stages all uncommitted changes and adds any unversioned files.
29+
# - Displays a diff of all staged changes.
30+
# - Saves staged changes to a .diff file.
3031
# - Uploads the patch file as an artifact.
3132
update-built-files:
3233
name: Check and update built files
@@ -78,22 +79,26 @@ jobs:
7879
- name: Build WordPress
7980
run: npm run build:dev
8081

81-
- name: Check for changes to versioned files
82+
- name: Check for uncommitted changes
8283
id: built-file-check
8384
run: |
84-
if git diff --quiet; then
85+
if [ -z "$(git status --porcelain)" ]; then
8586
echo "uncommitted_changes=false" >> "$GITHUB_OUTPUT"
8687
else
8788
echo "uncommitted_changes=true" >> "$GITHUB_OUTPUT"
8889
fi
8990
90-
- name: Display changes to versioned files
91+
- name: Stage all changes for diff generation
9192
if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
92-
run: git diff
93+
run: git add -A
94+
95+
- name: Display all uncommitted changes
96+
if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
97+
run: git diff --cached
9398

9499
- name: Save diff to a file
95100
if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
96-
run: git diff > ./changes.diff
101+
run: git diff --cached --binary > ./changes.diff
97102

98103
# Uploads the diff file as an artifact.
99104
- name: Upload diff file as artifact

.github/workflows/reusable-coding-standards-javascript.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
# - Logs debug information about the GitHub Action runner.
2525
# - Installs npm dependencies.
2626
# - Run the WordPress JSHint checks.
27-
# - Ensures version-controlled files are not modified or deleted.
27+
# - Checks for any uncommitted changes.
2828
jshint:
2929
name: JavaScript checks
3030
runs-on: ubuntu-24.04
@@ -57,5 +57,10 @@ jobs:
5757
- name: Run JSHint
5858
run: npm run grunt jshint
5959

60-
- name: Ensure version-controlled files are not modified or deleted
61-
run: git diff --exit-code
60+
- name: Check for uncommitted changes
61+
run: |
62+
if [ -n "$(git status --porcelain)" ]; then
63+
echo "Uncommitted changes detected:"
64+
git status --porcelain
65+
exit 1
66+
fi

.github/workflows/reusable-coding-standards-php.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
# - Generate a report for displaying issues as pull request annotations.
3838
# - Runs PHPCS on the `tests` directory without (warnings included).
3939
# - Generate a report for displaying `test` directory issues as pull request annotations.
40-
# - Ensures version-controlled files are not modified or deleted.
40+
# - Checks for any uncommitted changes.
4141
phpcs:
4242
name: PHP checks
4343
runs-on: ubuntu-24.04
@@ -105,5 +105,10 @@ jobs:
105105
if: ${{ inputs.old-branch }}
106106
run: phpcbf
107107

108-
- name: Ensure version-controlled files are not modified during the tests
109-
run: git diff --exit-code
108+
- name: Check for uncommitted changes
109+
run: |
110+
if [ -n "$(git status --porcelain)" ]; then
111+
echo "Uncommitted changes detected:"
112+
git status --porcelain
113+
exit 1
114+
fi

.github/workflows/reusable-end-to-end-tests.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
# - Install additional languages.
6262
# - Run the E2E tests.
6363
# - Uploads screenshots and HTML snapshots as an artifact.
64-
# - Ensures version-controlled files are not modified or deleted.
64+
# - Checks for any uncommitted changes.
6565
e2e-tests:
6666
name: SCRIPT_DEBUG ${{ inputs.LOCAL_SCRIPT_DEBUG && 'enabled' || 'disabled' }}
6767
runs-on: ubuntu-24.04
@@ -153,5 +153,10 @@ jobs:
153153
if-no-files-found: ignore
154154
include-hidden-files: true
155155

156-
- name: Ensure version-controlled files are not modified or deleted
157-
run: git diff --exit-code
156+
- name: Check for uncommitted changes
157+
run: |
158+
if [ -n "$(git status --porcelain)" ]; then
159+
echo "Uncommitted changes detected:"
160+
git status --porcelain
161+
exit 1
162+
fi

.github/workflows/reusable-javascript-tests.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# - Logs debug information about the GitHub Action runner.
2626
# - Installs npm dependencies.
2727
# - Run the WordPress QUnit tests.
28-
# - Ensures version-controlled files are not modified or deleted.
28+
# - Checks for any uncommitted changes.
2929
test-js:
3030
name: Run QUnit tests
3131
runs-on: ubuntu-24.04
@@ -67,5 +67,10 @@ jobs:
6767
- name: Run QUnit tests
6868
run: npm run grunt qunit:compiled
6969

70-
- name: Ensure version-controlled files are not modified or deleted
71-
run: git diff --exit-code
70+
- name: Check for uncommitted changes
71+
run: |
72+
if [ -n "$(git status --porcelain)" ]; then
73+
echo "Uncommitted changes detected:"
74+
git status --porcelain
75+
exit 1
76+
fi

.github/workflows/reusable-javascript-type-checking-v1.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
# - Configures caching for TypeScript build info.
2424
# - Runs JavaScript type checking.
2525
# - Saves the TypeScript build info.
26-
# - Ensures version-controlled files are not modified or deleted.
26+
# - Checks for any uncommitted changes.
2727
typecheck:
2828
name: Run JavaScript type checking
2929
runs-on: ubuntu-24.04
@@ -72,5 +72,10 @@ jobs:
7272
*.tsbuildinfo
7373
key: "ts-build-info-${{ github.run_id }}"
7474

75-
- name: Ensure version-controlled files are not modified or deleted
76-
run: git diff --exit-code
75+
- name: Check for uncommitted changes
76+
run: |
77+
if [ -n "$(git status --porcelain)" ]; then
78+
echo "Uncommitted changes detected:"
79+
git status --porcelain
80+
exit 1
81+
fi

.github/workflows/reusable-performance-test-v2.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
# - Install MU plugin.
103103
# - Run performance tests.
104104
# - Archive artifacts.
105-
# - Ensure version-controlled files are not modified or deleted.
105+
# - Checks for any uncommitted changes.
106106
performance:
107107
name: Test ${{ inputs.subject == 'base' && inputs.BASE_TAG || inputs.subject }}
108108
runs-on: ubuntu-24.04
@@ -272,5 +272,10 @@ jobs:
272272
if-no-files-found: error
273273
include-hidden-files: true
274274

275-
- name: Ensure version-controlled files are not modified or deleted
276-
run: git diff --exit-code
275+
- name: Check for uncommitted changes
276+
run: |
277+
if [ -n "$(git status --porcelain)" ]; then
278+
echo "Uncommitted changes detected:"
279+
git status --porcelain
280+
exit 1
281+
fi

.github/workflows/reusable-php-compatibility.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
# - Make Composer packages available globally.
3131
# - Runs the PHP compatibility tests.
3232
# - Generate a report for displaying issues as pull request annotations.
33-
# - Ensures version-controlled files are not modified or deleted.
33+
# - Checks for any uncommitted changes.
3434
php-compatibility:
3535
name: Run compatibility checks
3636
runs-on: ubuntu-24.04
@@ -86,5 +86,10 @@ jobs:
8686
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
8787
run: cs2pr ./.cache/phpcs-compat-report.xml
8888

89-
- name: Ensure version-controlled files are not modified or deleted
90-
run: git diff --exit-code
89+
- name: Check for uncommitted changes
90+
run: |
91+
if [ -n "$(git status --porcelain)" ]; then
92+
echo "Uncommitted changes detected:"
93+
git status --porcelain
94+
exit 1
95+
fi

.github/workflows/reusable-phpstan-static-analysis-v1.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# - Configures caching for PHPStan static analysis scans.
3434
# - Runs PHPStan static analysis (with Pull Request annotations).
3535
# - Saves the PHPStan result cache.
36-
# - Ensures version-controlled files are not modified or deleted.
36+
# - Checks for any uncommitted changes.
3737
phpstan:
3838
name: Run PHP static analysis
3939
runs-on: ubuntu-24.04
@@ -102,5 +102,10 @@ jobs:
102102
path: .cache
103103
key: "phpstan-result-cache-${{ github.run_id }}"
104104

105-
- name: Ensure version-controlled files are not modified or deleted
106-
run: git diff --exit-code
105+
- name: Check for uncommitted changes
106+
run: |
107+
if [ -n "$(git status --porcelain)" ]; then
108+
echo "Uncommitted changes detected:"
109+
git status --porcelain
110+
exit 1
111+
fi

.github/workflows/reusable-phpunit-tests-v2.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
# - Logs debug information from inside the WordPress Docker container.
8585
# - Install WordPress within the Docker container.
8686
# - Run the PHPUnit tests.
87-
# - Ensures version-controlled files are not modified or deleted.
87+
# - Checks for any uncommitted changes.
8888
test-php:
8989
name: PHP ${{ inputs.php }} / ${{ inputs.multisite && ' Multisite' || 'Single Site' }}${{ inputs.split_slow && ' slow tests' || '' }}${{ inputs.memcached && ' with memcached' || '' }}
9090
runs-on: ${{ inputs.os }}
@@ -208,5 +208,10 @@ jobs:
208208
if: ${{ ! inputs.split_slow }}
209209
run: LOCAL_PHP_XDEBUG=true npm run "test:${PHPUNIT_SCRIPT}" -- -v --group xdebug --exclude-group __fakegroup__
210210

211-
- name: Ensure version-controlled files are not modified or deleted
212-
run: git diff --exit-code
211+
- name: Check for uncommitted changes
212+
run: |
213+
if [ -n "$(git status --porcelain)" ]; then
214+
echo "Uncommitted changes detected:"
215+
git status --porcelain
216+
exit 1
217+
fi

0 commit comments

Comments
 (0)