-
Notifications
You must be signed in to change notification settings - Fork 9
Update test and measure workflow #69
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e153471
Add testcase for Elementary_Theme class
thelovekesh 417c6fa
Fix npm scripts
thelovekesh ab219e4
Add package-json linting
thelovekesh e826e59
Add script to detemine modified files
thelovekesh 42d951d
Add workflow for test and measure
thelovekesh 0c07b25
Remove old test and measure workflow for css and js
thelovekesh 862f0ef
Fix composer lock file
thelovekesh f776bd3
Add build step with label script
thelovekesh 565f562
Fix syntax error
thelovekesh 8aca57e
Remove seperate PHPCS inspection workflow
thelovekesh fa790fd
Add modified file condition on build-prod job
thelovekesh 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
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,33 @@ | ||
/** | ||
* Determine the modified files count. | ||
* | ||
* Usage: | ||
* node determine-modified-files-count.js <file-path-pattern> <file paths delimited by newlines> [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 ); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,291 @@ | ||
name: Test and Measure | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- ready_for_review | ||
|
||
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-file-count: ${{ steps.determine-file-counts.outputs.count }} | ||
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@v3 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Checkout | ||
# Do usual checkout if it's a PR. | ||
if: ${{ github.base_ref != null }} | ||
uses: actions/checkout@v3 | ||
|
||
- 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\/.+\.yml)" "$MODIFIED_FILES") | ||
|
||
echo "Changed file count: $MODIFIED_FILES_DATA" | ||
echo "Changed CK theme CSS file count: $CSS_FILE_COUNT" | ||
echo "Changed CK theme JS file count: $JS_FILE_COUNT" | ||
echo "Changed CK theme PHP file count: $PHP_FILE_COUNT" | ||
echo "Changed GHA workflow count: $GHA_WORKFLOW_COUNT" | ||
|
||
echo "::set-output name=count::$MODIFIED_FILES_DATA" | ||
echo "::set-output name=css-count::$CSS_FILE_COUNT" | ||
echo "::set-output name=js-count::$JS_FILE_COUNT" | ||
echo "::set-output name=php-count::$PHP_FILE_COUNT" | ||
echo "::set-output name=gha-workflow-count::$GHA_WORKFLOW_COUNT" | ||
env: | ||
# Ignore Paths: | ||
# - .github/ | ||
# - !.github/workflows | ||
# - .wordpress-org/ | ||
# - docs/ | ||
IGNORE_PATH_REGEX: \.github\/(?!workflows)|\.wordpress-org\/|docs\/ | ||
|
||
lint-css: | ||
needs: pre-run | ||
if: needs.pre-run.outputs.changed-css-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0 | ||
name: 'Lint CSS' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3.2.0 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: npm | ||
|
||
- name: Install Node dependencies | ||
run: npm ci --ignore-scripts | ||
env: | ||
CI: true | ||
|
||
- 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 || needs.pre-run.outputs.changed-gha-workflow-count > 0 | ||
name: 'Lint JS' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3.2.0 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: npm | ||
|
||
- name: Install Node dependencies | ||
run: npm ci --ignore-scripts | ||
env: | ||
CI: true | ||
|
||
- 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 || needs.pre-run.outputs.changed-gha-workflow-count > 0 | ||
name: 'Run JS unit tests' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3.2.0 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: npm | ||
|
||
- name: Install Node dependencies | ||
run: npm ci --ignore-scripts | ||
env: | ||
CI: true | ||
|
||
- 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 || needs.pre-run.outputs.changed-gha-workflow-count > 0 | ||
name: 'Lint PHP' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.0' | ||
coverage: none | ||
tools: cs2pr | ||
|
||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Configure Composer cache | ||
uses: actions/cache@v3.0.2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
- name: Install Composer dependencies | ||
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 | ||
|
||
unit-test-php: | ||
name: "PHP Unit test" | ||
runs-on: ubuntu-latest | ||
needs: pre-run | ||
steps: | ||
# Note: The repeated `needs.pre-run.outputs.changed-php-count > 0` checks would be avoided if a step could short- | ||
# circuit per <https://github.com/actions/runner/issues/662>. The reason why the if statement can't be put on the | ||
# job as a whole is because the name is variable based on the matrix, and if the condition is not met then the | ||
# name won't be interpolated in order to match the required jobs set up in branch protection. | ||
- name: Notice | ||
if: needs.pre-run.outputs.changed-php-count > 0 | ||
run: echo "No PHP files were changed in CK theme so no PHP unit tests will run" | ||
|
||
- name: Checkout | ||
if: needs.pre-run.outputs.changed-php-count > 0 | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
if: needs.pre-run.outputs.changed-php-count > 0 | ||
uses: actions/setup-node@v3.2.0 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: npm | ||
|
||
- name: Install Node dependencies | ||
if: needs.pre-run.outputs.changed-php-count > 0 | ||
run: npm ci --ignore-scripts | ||
env: | ||
CI: true | ||
|
||
- name: Start WP environment | ||
if: needs.pre-run.outputs.changed-php-count > 0 | ||
run: npm run wp-env start | ||
|
||
- name: Run tests | ||
if: ${{ needs.pre-run.outputs.changed-php-count > 0 }} | ||
run: npm run test:php | ||
|
||
build-prod: | ||
needs: pre-run | ||
if: needs.pre-run.outputs.changed-js-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0 || needs.pre-run.outputs.changed-css-count > 0 | ||
name: 'Build production' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3.2.0 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: npm | ||
|
||
- name: Install Node dependencies | ||
run: npm ci --ignore-scripts | ||
env: | ||
CI: true | ||
|
||
- name: Build production | ||
id: build | ||
run: npm run build:prod | ||
continue-on-error: true | ||
env: | ||
CI: true | ||
|
||
- name: Comment on PR with build status | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
if ( '${{ steps.build.outcome }}' != 'success' ) { | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['Build:Failing'] | ||
}) | ||
if ( ${{ github.event.label.name == 'Build:Passing' }} ) { | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: 'Build:Passing' | ||
}) | ||
} | ||
} else { | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['Build:Passing'] | ||
}) | ||
if ( ${{ github.event.label.name == 'Build:Failing' }} ) { | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: 'Build:Failing' | ||
}) | ||
} | ||
} |
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.