Repository navigation
Build/Test Tools: Check that CSS and JS files are in the right directories. #13684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
adimoldovan
wants to merge
11
commits into
WordPress:trunk
from
adimoldovan:65279-prevent-files-in-wrong-dirs
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
59fa52f
Build/Test Tools: Check that CSS and JS files are in the right direct…
adimoldovan 79fcc56
Merge branch 'trunk' into 65279-prevent-files-in-wrong-dirs
adimoldovan a02dc44
Build/Test Tools: Trim comments in the file type check workflow.
adimoldovan b8bdc3e
Merge branch 'trunk' into 65279-prevent-files-in-wrong-dirs
adimoldovan 784b426
Build/Test Tools: Let Git filter the file type check.
adimoldovan 455cbde
Build/Test Tools: Note that the file type check skips generated PHP.
adimoldovan 98740e8
Build/Test Tools: Anchor the excludes in the file type check.
adimoldovan 13a2dee
Merge branch 'trunk' into 65279-prevent-files-in-wrong-dirs
adimoldovan 83e46ab
Merge remote-tracking branch 'upstream/trunk' into 65279-prevent-file…
adimoldovan f3df9ab
Build/Test Tools: Use ubuntu-26.04 runner in the file type check.
adimoldovan 2ce5312
Build/Test Tools: Scope file type check cancellation to the PR and re…
adimoldovan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| name: File Type Check | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - trunk | ||
| - '6.[8-9]' | ||
| - '[7-9].[0-9]' | ||
| paths: | ||
| # Inward check: files added to CSS/JS directories. | ||
| - 'src/wp-includes/css/**' | ||
| - 'src/wp-includes/js/**' | ||
| - 'src/wp-admin/css/**' | ||
| - 'src/wp-admin/js/**' | ||
| # Outward check: CSS/JS files placed outside designated directories. | ||
| - 'src/wp-includes/**.css' | ||
| - 'src/wp-includes/**.js' | ||
| - 'src/wp-admin/**.css' | ||
| - 'src/wp-admin/**.js' | ||
| # Confirm any changes to the workflow file itself. | ||
| - '.github/workflows/file-type-check.yml' | ||
| pull_request: | ||
| branches: | ||
| - trunk | ||
| - '6.[8-9]' | ||
| - '[7-9].[0-9]' | ||
| paths: | ||
| - 'src/wp-includes/css/**' | ||
| - 'src/wp-includes/js/**' | ||
| - 'src/wp-admin/css/**' | ||
| - 'src/wp-admin/js/**' | ||
| - 'src/wp-includes/**.css' | ||
| - 'src/wp-includes/**.js' | ||
| - 'src/wp-admin/**.css' | ||
| - 'src/wp-admin/**.js' | ||
| - '.github/workflows/file-type-check.yml' | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| # Verifies that CSS and JS files live in the directories intended for them. | ||
| # | ||
| # The JS sources in src/js/ are out of scope. The build system decides where | ||
| # those are placed, so only its output is checked. | ||
| check-file-types: | ||
| name: Verify file types in CSS/JS directories | ||
| runs-on: ubuntu-26.04 | ||
| permissions: | ||
| contents: read | ||
| if: | | ||
| github.repository == 'WordPress/wordpress-develop' || ( | ||
| github.event_name == 'pull_request' && ( | ||
| ! github.event.repository.private || | ||
| ! github.event.pull_request.draft || | ||
| contains( github.event.pull_request.labels.*.name, 'Draft Workflow Runs' ) | ||
| ) | ||
| ) | ||
| timeout-minutes: 5 | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Check for misplaced CSS and JS files | ||
| run: | | ||
| # Git does the filtering, so no path is ever matched as text. Shell | ||
| # patterns break on names holding a tab, a newline or a quote: Git | ||
| # C-quotes those, and core.quotePath=false does not stop it. | ||
| # | ||
| # Each check is a bare assignment, so `set -e` sees a failure from Git. | ||
| # | ||
| # Every exclude starts with src/, the directory the positive pathspecs share. | ||
| # git ls-files strips that shared directory from every pathspec, excludes | ||
| # included, without checking that it is there. An exclude such as *.js is | ||
| # then cut down to a pattern that can match every file. | ||
| # | ||
| # Only tracked files are checked. The PHP that Gutenberg generates | ||
| # into css/dist and js/dist is untracked, so it never appears here. | ||
| # Whether it should be tracked, moved, or not copied at all is still | ||
| # open in #65278. If it becomes tracked, this check will flag it. | ||
|
|
||
| # Git exits 0 when a pathspec matches nothing. | ||
| if [ -z "$( git ls-files -- src/wp-includes src/wp-admin )" ]; then | ||
| echo "::error::No tracked files found under src/wp-includes or src/wp-admin." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # The SCSS sources for the admin color schemes are the only tracked | ||
| # non-CSS files in these directories. | ||
| inward_css=$( git ls-files -- src/wp-includes/css src/wp-admin/css \ | ||
| ':(exclude,glob)src/wp-includes/css/**/*.css' \ | ||
| ':(exclude,glob)src/wp-admin/css/**/*.css' \ | ||
| ':(exclude,glob)src/wp-admin/css/colors/**/*.scss' ) | ||
|
|
||
| # Both directories are gitignored in full, so this only catches a file | ||
| # committed with `git add -f`. | ||
| inward_js=$( git ls-files -- src/wp-includes/js src/wp-admin/js \ | ||
| ':(exclude,glob)src/wp-includes/js/**/*.js' \ | ||
| ':(exclude,glob)src/wp-admin/js/**/*.js' ) | ||
|
|
||
| # src/wp-includes/build/ is tracked, not gitignored: it holds the | ||
| # generated routes and pages. | ||
| outward=$( git ls-files -- \ | ||
| ':(glob)src/wp-includes/**/*.css' ':(glob)src/wp-includes/**/*.js' \ | ||
| ':(glob)src/wp-admin/**/*.css' ':(glob)src/wp-admin/**/*.js' \ | ||
| ':(exclude,glob)src/wp-includes/css/**' \ | ||
| ':(exclude,glob)src/wp-includes/js/**' \ | ||
| ':(exclude,glob)src/wp-admin/css/**' \ | ||
| ':(exclude,glob)src/wp-admin/js/**' \ | ||
| ':(exclude,glob)src/wp-includes/build/**' ) | ||
|
|
||
| violations=$( printf '%s\n%s\n%s' "$inward_css" "$inward_js" "$outward" | grep -v '^$' || true ) | ||
|
|
||
| if [ -n "$violations" ]; then | ||
| echo "::error::Misplaced files found." | ||
| echo | ||
| echo "$violations" | ||
| echo | ||
| echo "CSS directories should contain only .css files and JS directories only .js files." | ||
| echo ".css and .js files belong in those directories, not elsewhere in wp-includes/ or wp-admin/." | ||
| echo "If a file is a legitimate exception, update .github/workflows/file-type-check.yml." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "All tracked CSS and JS files are correctly placed." | ||
|
|
||
| slack-notifications: | ||
| name: Slack Notifications | ||
| uses: ./.github/workflows/slack-notifications.yml | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| needs: [ check-file-types ] | ||
| if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} | ||
| with: | ||
| calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} | ||
| secrets: | ||
| SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} | ||
| SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} | ||
| SLACK_GHA_FIXED_WEBHOOK: ${{ secrets.SLACK_GHA_FIXED_WEBHOOK }} | ||
| SLACK_GHA_FAILURE_WEBHOOK: ${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }} | ||
|
|
||
| failed-workflow: | ||
| name: Failed workflow tasks | ||
| runs-on: ubuntu-26.04 | ||
| permissions: | ||
| actions: write | ||
| needs: [ check-file-types, slack-notifications ] | ||
| if: | | ||
| always() && | ||
| github.repository == 'WordPress/wordpress-develop' && | ||
| github.event_name != 'pull_request' && | ||
| github.run_attempt < 2 && | ||
| ( | ||
| contains( needs.*.result, 'cancelled' ) || | ||
| contains( needs.*.result, 'failure' ) | ||
| ) | ||
|
|
||
| steps: | ||
| - name: Dispatch workflow run | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| with: | ||
| retries: 2 | ||
| retry-exempt-status-codes: 418 | ||
| script: | | ||
| github.rest.actions.createWorkflowDispatch({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: 'failed-workflow.yml', | ||
| ref: 'trunk', | ||
| inputs: { | ||
| run_id: `${context.runId}`, | ||
| } | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.