ci: add GitHub Actions workflow for validate-filepaths#20616
Open
okwn wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds CI coverage for the .github/script/validate-filepaths Node/Jest test suite by introducing a dedicated GitHub Actions workflow, along with a new Jest test file intended to validate filepath/date rules.
Changes:
- Added a new GitHub Actions workflow to run
npm testforvalidate-filepathson Node 20. - Added a new Jest test file under
.github/script/validate-filepaths/__tests__.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| .github/workflows/validate-filepaths.yml | Runs the validate-filepaths Jest tests in CI on pushes/PRs targeting master. |
| .github/script/validate-filepaths/tests/validate.test.js | Adds additional unit tests around year-folder detection and filename date pattern checks. |
Comments suppressed due to low confidence (2)
.github/script/validate-filepaths/tests/validate.test.js:67
- The file defines
isFileInsideAYearFolder/isFilepathDateValida second time in a laterdescribe. Duplicating helper implementations increases the chance tests diverge over time; reuse a single helper/import across the file (or import the real functions) to keep tests consistent.
describe("filepath structure validation", () => {
// Tests for the overall filepath structure (year folder, optional month folder, filename)
function isFileInsideAYearFolder(filepath) {
return filepath.match(/^\d{4}/) !== null;
}
function isFilepathDateValid(filepath) {
const filename = filepath.split("/").pop();
const dateStringInFilename = filename.match(/\d{4}-\d{2}-\d{2}/);
return dateStringInFilename !== null;
}
.github/script/validate-filepaths/tests/validate.test.js:91
- This test is labeled as an “incorrect structure with non-matching date in filename”, but it asserts
isFilepathDateValid(...)istrue. If the intended rule is that folder year/month must match the date in the filename (asisFileInCorrectFolderenforces), update the assertions to reflect the expected failure condition and/or call the actual folder-validation function here.
test("incorrect structure with non-matching date in filename", () => {
const invalidPath = "2024/06/2023-06-15-brand.markdown";
expect(isFileInsideAYearFolder(invalidPath)).toBe(true);
expect(isFilepathDateValid(invalidPath)).toBe(true);
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+22
to
+24
|
|
||
| - name: Install dependencies | ||
| run: npm install |
Comment on lines
+6
to
+10
| // This function is defined in index.js - we test the logic it's testing | ||
|
|
||
| function isFileInsideAYearFolder(filepath) { | ||
| return filepath.match(/^\d{4}/) !== null; | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a GitHub Actions workflow that runs Jest tests for the validate-filepaths script on Node 20.