-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add a GitHub CI to check sorting HttpsExclusions #596
Open
piquark6046
wants to merge
15
commits into
master
Choose a base branch
from
update/bank-ci
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
02f7118
Add sort.yml
piquark6046 0f35754
comments are sorted and sort 9.4 issue
piquark6046 083c7d6
fix typo
piquark6046 4a48b2e
update toolchain
piquark6046 18c3125
update ci
piquark6046 978be5f
rename
piquark6046 d6b1a47
Use Nodejs 20
piquark6046 50fa2ee
follow scripthunter7 suggestion
piquark6046 efd3492
convert to cjs and rename
piquark6046 632898a
create package-lock.json and caching
piquark6046 3732d9c
Convert to cjs
piquark6046 a84691a
make sure that tsconfig is commonjs
piquark6046 cbb8012
fix typo
piquark6046 d148401
use env
piquark6046 4bfd1b8
modify a bit
piquark6046 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 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,34 @@ | ||
name: Lint HttpsExclusions | ||
|
||
env: | ||
NODE_VERSION: 20 | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- "**/*.txt" | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- "**/*.txt" | ||
|
||
jobs: | ||
bank: | ||
name: Check that banks.txt is sorted | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Node.js LTS | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
cache: npm | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Check out to repository | ||
uses: actions/checkout@v4 | ||
- name: Run lint:banks | ||
run: npm run lint:banks | ||
shell: bash | ||
piquark6046 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist | ||
.DS_Store | ||
.DS_Store | ||
node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -5,5 +5,13 @@ | |
"main": "index.js", | ||
"repository": "[email protected]:AdguardTeam/HttpsExclusions.git", | ||
"author": "AdGuard", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "tsx tools/check.ts exclusions/banks.txt" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.2", | ||
"tsx": "^4.15.4", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains 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,65 @@ | ||
const { readFile, stat } = require('fs').promises; | ||
|
||
const RE_NL = /\r?\n/; | ||
const COMMENT_MARKER = '//'; | ||
|
||
const isFileExists = async (filePath: string): Promise<boolean> => { | ||
return stat(filePath) | ||
.then((stats) => stats.isFile()) | ||
.catch(() => false); | ||
}; | ||
|
||
const readRules = async (filePath: string): Promise<string[]> => { | ||
const fileContent = await readFile(filePath, { encoding: 'utf-8' }); | ||
|
||
return fileContent | ||
.split(RE_NL) | ||
.map((line) => line.trim()) | ||
.filter((line) => line.length > 0 && !line.startsWith(COMMENT_MARKER)); | ||
}; | ||
|
||
const isSortedAlphabetically = (arr: string[]): boolean => { | ||
for (let i = 0; i < arr.length - 1; i += 1) { | ||
if (arr[i] > arr[i + 1]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
const getErrorMessage = (err: unknown): string => { | ||
if (err instanceof Error) { | ||
return err.message; | ||
} | ||
|
||
return 'Unknown error'; | ||
}; | ||
|
||
const isNonEmptyString = (value: unknown): value is string => { | ||
return typeof value === 'string' && value.length > 0; | ||
}; | ||
|
||
const main = async () => { | ||
const filePath = process.argv[2]; | ||
|
||
try { | ||
if (!isNonEmptyString(filePath)) { | ||
throw new Error('File path is not provided'); | ||
} | ||
|
||
if (!(await isFileExists(filePath))) { | ||
throw new Error(`File ${filePath} does not exist`); | ||
} | ||
|
||
const rules = await readRules(filePath); | ||
|
||
if (!isSortedAlphabetically(rules)) { | ||
throw new Error(`Rules in ${filePath} is not sorted alphabetically`); | ||
} | ||
} catch (err) { | ||
console.error(getErrorMessage(err)); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
main(); |
piquark6046 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"tools/**/*.ts" | ||
] | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both
"**/*.txt"
can be replaced by a relative path ofbanks.txt
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, But, it can be extended in the future.