Skip to content

Commit

Permalink
chore: add file copyright headers check (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Jan 21, 2022
1 parent 504bd94 commit e9e9b8b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
lib/
node_modules/
scripts/
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"project": "./tsconfig.json"
},
"rules": {
"prefer-arrow-callback": "error",
"no-trailing-spaces": "error",
"promise/prefer-await-to-then": "error",
"eslint-comments/no-use": "off",
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:
dependencies
devDependencies
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Validate Copyright Headers
run: deno run --allow-read scripts/verify-file-headers.ts

- name: Setup Node
uses: actions/setup-node@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"lint": "eslint --fix src/**/*.ts test/**/*.ts",
"package": "npm run clean && ncc build --source-map --license licenses.txt && cp action.yml dist",
"prepare": "husky install",
"setup": "./dev-setup.sh",
"setup": "./scripts/dev-setup.sh",
"test": "jest"
}
}
File renamed without changes.
17 changes: 17 additions & 0 deletions scripts/verify-file-headers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import getFiles from 'https://deno.land/x/getfiles@v1.0.0/mod.ts';

const filePaths = getFiles({ root: '.', include: ['src', 'test'] }).map(file => file.path);
const filesWithoutCopyrightHeader =
(await Promise.all(
filePaths.map(async filePath => {
const fileText = await Deno.readTextFile(filePath);
return fileText.startsWith('/*\nCopyright') ? undefined : filePath;
})
)).filter(Boolean);

if (filesWithoutCopyrightHeader.length) {
console.error(`\nThe following files are missing a valid copyright header:${filesWithoutCopyrightHeader.map(file => `\n • ${file}`).join()}`);
Deno.exit(1);
}

console.info('All files contain a valid copyright header!');
13 changes: 13 additions & 0 deletions test/types.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
/*
Copyright 2021 Expedia, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

export type Mocktokit = jest.MockInstance<any, any>;
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"moduleResolution": "node"
},
"exclude": [
"node_modules"
"node_modules",
"scripts"
]
}

0 comments on commit e9e9b8b

Please sign in to comment.