diff --git a/.github/actions/setup-node-with-cache/action.yml b/.github/actions/setup-node-with-cache/action.yml deleted file mode 100644 index 23048805..00000000 --- a/.github/actions/setup-node-with-cache/action.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: 'Setup Node with Cache' -description: 'Sets up Node.js and caches node_modules' - -runs: - using: 'composite' - steps: - - name: Setup Node - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 - with: - node-version-file: '.nvmrc' - - - name: Get node version - id: node - run: echo "version=$(node -v)" >> $GITHUB_OUTPUT - shell: bash - - - name: Cache node_modules - id: node_modules - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 - with: - path: '**/node_modules' - key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json', '**/.npmrc') }}-${{ steps.node.outputs.version }} - - - name: Install Node dependencies - if: steps.node_modules.outputs.cache-hit != 'true' - run: npm ci --ignore-scripts - shell: bash - env: - CI: true diff --git a/.github/bin/determine-modified-files-count.js b/.github/bin/determine-modified-files-count.js deleted file mode 100644 index 5ec81272..00000000 --- a/.github/bin/determine-modified-files-count.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Determine the modified files count. - * - * Usage: - * node determine-modified-files-count.js [path/to/dir] - * - * Example: - * node determine-modified-files-count.js "foo\/bar|bar*" "foo/bar/baz\nquux" "foo/bar" - * - * Output: 1 - */ -const args = process.argv.slice(2); -const pattern = args[0]; -const modifiedFiles = args[1].split('\n'); -const dirInclude = args[2]; - -let count; - -if ( 'all' === dirInclude ) { - count = modifiedFiles.reduce((count, file) => { - if (pattern.split('|').some(pattern => file.match(pattern))) { - return count; - } - - return count + 1; - }, 0); -} else { - count = modifiedFiles.filter( ( file ) => { - return file.match( pattern ); - } ).length; -} - -console.log( count ); diff --git a/.github/workflows/test-measure.yml b/.github/workflows/test-measure.yml index fd9841de..3c9bed4d 100644 --- a/.github/workflows/test-measure.yml +++ b/.github/workflows/test-measure.yml @@ -13,238 +13,21 @@ on: permissions: contents: read -concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} - cancel-in-progress: true - jobs: - pre-run: - name: 'Pre run' - runs-on: ubuntu-latest - outputs: - changed-css-count: ${{ steps.determine-file-counts.outputs.css-count }} - changed-js-count: ${{ steps.determine-file-counts.outputs.js-count }} - changed-php-count: ${{ steps.determine-file-counts.outputs.php-count }} - changed-gha-workflow-count: ${{ steps.determine-file-counts.outputs.gha-workflow-count }} - - steps: - - name: Checkout including last 2 commits - # Fetch last 2 commits if it's not a PR, so that we can determine the list of modified files. - if: ${{ github.base_ref == null }} - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - with: - fetch-depth: 2 - - - name: Checkout - # Do usual checkout if it's a PR. - if: ${{ github.base_ref != null }} - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Fetch base branch - # Only fetch base ref if it's a PR. - if: ${{ github.base_ref != null }} - run: git fetch --depth=1 --no-tags origin ${{ github.base_ref }} - - - name: Determine modified files for PR - if: ${{ github.base_ref != null }} - run: echo "MODIFIED_FILES=$(git diff --name-only FETCH_HEAD HEAD | base64 -w 0)" >> $GITHUB_ENV - - - name: Determine modified files for commit - if: ${{ github.base_ref == null }} - run: echo "MODIFIED_FILES=$(git diff --name-only HEAD~1 HEAD | base64 -w 0)" >> $GITHUB_ENV - - - id: determine-file-counts - name: Determine if modified files should make the workflow run continue - run: | - MODIFIED_FILES=$(echo "$MODIFIED_FILES" | base64 -d) - echo -e "Modified files:\n$MODIFIED_FILES\n" - - MODIFIED_FILES_DATA=$(node .github/bin/determine-modified-files-count.js "$IGNORE_PATH_REGEX" "$MODIFIED_FILES" "all") - CSS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.s?css|package\.json|package-lock\.json" "$MODIFIED_FILES") - JS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.(js|snap)|package\.json|package-lock\.json" "$MODIFIED_FILES") - PHP_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.php|composer\.(json|lock)|phpstan\.neon\.dist" "$MODIFIED_FILES") - GHA_WORKFLOW_COUNT=$(node .github/bin/determine-modified-files-count.js "(\.github\/(workflows|actions)\/.+\.yml)" "$MODIFIED_FILES") - - echo "Changed file count: $MODIFIED_FILES_DATA" - echo "Changed ${{ github.event.repository.name }} CSS file count: $CSS_FILE_COUNT" - echo "Changed ${{ github.event.repository.name }} JS file count: $JS_FILE_COUNT" - echo "Changed ${{ github.event.repository.name }} PHP file count: $PHP_FILE_COUNT" - echo "Changed GHA workflow/actions count: $GHA_WORKFLOW_COUNT" - - echo "css-count=$CSS_FILE_COUNT" >> $GITHUB_OUTPUT - echo "js-count=$JS_FILE_COUNT" >> $GITHUB_OUTPUT - echo "php-count=$PHP_FILE_COUNT" >> $GITHUB_OUTPUT - echo "gha-workflow-count=$GHA_WORKFLOW_COUNT" >> $GITHUB_OUTPUT - env: - # Ignore Paths: - # - .github/ - # - !.github/workflows - # - !.github/actions - # - .wordpress-org/ - # - docs/ - IGNORE_PATH_REGEX: \.github\/(?!workflows)(?!actions)|\.wordpress-org\/|docs\/ - - - name: Summarize skipped jobs - run: | - SKIPPED=() - - [[ "${{ steps.determine-file-counts.outputs.css-count }}" -le 0 ]] && SKIPPED+=("lint-css") - [[ "${{ steps.determine-file-counts.outputs.js-count }}" -le 0 ]] && SKIPPED+=("lint-js" "unit-tests-js" "build-prod") - [[ "${{ steps.determine-file-counts.outputs.php-count }}" -le 0 ]] && SKIPPED+=("lint-php") - - if [[ ${#SKIPPED[@]} -gt 0 ]]; then - echo "The following jobs will be skipped as no relevant files were changed:" - for JOB in "${SKIPPED[@]}"; do - echo " - $JOB" - done - else - echo "All jobs will run." - fi - - lint-css: - needs: pre-run - if: needs.pre-run.outputs.changed-css-count > 0 - name: 'Lint CSS' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup Node with cache - uses: ./.github/actions/setup-node-with-cache - - - name: Detect coding standard violations (stylelint) - run: npm run lint:css - - lint-js: - needs: pre-run - if: needs.pre-run.outputs.changed-js-count > 0 - name: 'Lint JS' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup Node with cache - uses: ./.github/actions/setup-node-with-cache - - - name: Detect coding standard violations (eslint) - run: npm run lint:js - - unit-tests-js: - needs: pre-run - if: needs.pre-run.outputs.changed-js-count > 0 - name: 'Run JS unit tests' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup Node with cache - uses: ./.github/actions/setup-node-with-cache - - - name: Run unit tests - run: npm run test:js - env: - CI: true - - lint-php: - needs: pre-run - if: needs.pre-run.outputs.changed-php-count > 0 - name: 'Lint PHP' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup PHP - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2.37.2 - with: - php-version: '8.2' - coverage: none - tools: cs2pr - # Rate limits only; all deps are public. setup-php passes this to - # Composer's github-oauth, so an expired PAT breaks every download. - github-token: ${{ github.token }} - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Configure Composer cache - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Ensure git is installed - run: which git || (sudo apt-get update && sudo apt-get install -y git) - - - name: Install Composer dependencies - id: composer-install - run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction --no-scripts - - - name: Validate composer.json - run: composer --no-interaction validate --no-check-all - - - name: Detect coding standard violations (PHPCS) - run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings - - # Runs even when PHPCS fails, so one push surfaces both classes of error. - - name: Run PHPStan - if: ${{ !cancelled() && steps.composer-install.conclusion == 'success' }} - run: composer phpstan - - build-prod: - needs: pre-run - if: needs.pre-run.outputs.changed-js-count > 0 || needs.pre-run.outputs.changed-css-count > 0 - name: 'Build production' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup Node with cache - uses: ./.github/actions/setup-node-with-cache - - - name: Build production - id: build - run: npm run build:prod - env: - CI: true - - unit-test-php: - needs: pre-run - if: needs.pre-run.outputs.changed-php-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0 - name: "PHP Unit test: PHP ${{ matrix.php }} / WP ${{ matrix.wp }}" - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - php: ['8.2', '8.3', '8.4'] - wp: ['6.5', '6.6', '6.7', '6.8', '6.9', '7.0'] - exclude: - # WordPress added PHP 8.4 support in 6.7. - - { php: '8.4', wp: '6.5' } - - { php: '8.4', wp: '6.6' } - env: - WP_ENV_PHP_VERSION: ${{ matrix.php }} - WP_ENV_CORE: WordPress/WordPress#${{ matrix.wp }} - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup Node with cache - uses: ./.github/actions/setup-node-with-cache - - - name: Start WP environment - run: npm run wp-env start - - # Rate limits only; all deps are public. - - name: Configure Composer GitHub auth in wp-env - run: npx wp-env run cli -- composer config --global github-oauth.github.com "${{ github.token }}" - - - name: Run tests - run: npm run test:php + ci: + uses: rtCamp/wp-shared-workflows/.github/workflows/wp-ci.yml@release/v1.0.0 + with: + project-type: theme + enable-phpstan: true + php-versions: '["8.2", "8.3", "8.4"]' + wp-versions: '["6.5", "6.6", "6.7", "6.8", "6.9", "7.0"]' + # WordPress added PHP 8.4 support in 6.7. + test-php-exclude: '[{"php": "8.4", "wp": "6.5"}, {"php": "8.4", "wp": "6.6"}]' + + # Optional wp-ci inputs, upstream defaults — uncomment to change. + # skip: '' # lint-css,lint-js,lint-php,test-js,test-php,build,build-artifact,a11y + # run-a11y: false # or: ${{ contains(github.event.pull_request.labels.*.name, 'Run a11y') }} + # use-wp-env: true # false = standalone PHPUnit, no WordPress + # build-artifact-path: '' # installable dir the build emits; empty skips the install test + # build-artifact-slug: '' # empty = repo name (theme-elementary) + # Jobs also gate on changed files: no .php changes = no lint-php. diff --git a/package.json b/package.json index 622d6c5f..cca9e1f4 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,19 @@ { "name": "elementary-theme", - "description": "A starter theme that facilitates a quick head start for developing new block-based themes along with a bunch of developer-friendly features.", "version": "1.0.0", + "description": "A starter theme that facilitates a quick head start for developing new block-based themes along with a bunch of developer-friendly features.", "author": "rtCamp", + "license": "GPL-2.0-or-later", + "keywords": [ + "block-theme", + "rtcamp", + "wp-theme" + ], + "homepage": "https://github.com/rtCamp/theme-elementary#readme", + "repository": { + "type": "git", + "url": "https://github.com/rtCamp/theme-elementary.git" + }, "bugs": { "url": "https://github.com/rtCamp/theme-elementary/issues" }, @@ -40,23 +51,6 @@ "webpack": "5.107.2", "webpack-remove-empty-scripts": "1.1.1" }, - "homepage": "https://github.com/rtCamp/theme-elementary#readme", - "keywords": [ - "block-theme", - "rtcamp", - "wp-theme" - ], - "license": "GPL-2.0-or-later", - "overrides": { - "webpack-dev-server": "5.2.1", - "serialize-javascript": "7.0.3", - "minimatch": "3.1.3" - }, - "private": true, - "repository": { - "type": "git", - "url": "https://github.com/rtCamp/theme-elementary.git" - }, "scripts": { "build:dev": "npm-run-all build:assets:dev build:blocks:dev", "build:prod": "npm-run-all build:assets build:blocks", @@ -78,14 +72,20 @@ "lint:staged": "lint-staged", "pot": "composer run pot", "prepare": "npm run sync-ai", - "pretest:php": "wp-env run cli --env-cwd=/var/www/html/wp-content/themes/${PWD##*/} composer install --no-interaction --no-scripts", + "pretest:php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/themes/${PWD##*/} composer install --no-interaction --no-scripts", "start": "npm-run-all --parallel start:assets start:blocks", "start:assets": "wp-scripts start --experimental-modules --config webpack.config.js", "start:blocks": "wp-scripts start --hot --experimental-modules --config ./webpack.blocks.config.js --webpack-src-dir=./src/blocks/ --output-path=./assets/build/blocks/", "test": "npm-run-all --parallel test:*", "test:js": "wp-scripts test-unit-js --config=tests/js/jest.config.js --passWithNoTests", "test:js:watch": "npm run test:js -- --watch", - "test:php": "wp-env run cli --env-cwd=/var/www/html/wp-content/themes/${PWD##*/} composer exec 'phpunit --do-not-cache-result --verbose'", + "test:php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/themes/${PWD##*/} composer exec 'phpunit --do-not-cache-result --verbose'", "wp-env": "wp-env" - } + }, + "overrides": { + "webpack-dev-server": "5.2.1", + "serialize-javascript": "7.0.3", + "minimatch": "3.1.3" + }, + "private": true }