Skip to content

Commit

Permalink
fix: added CI check for build files
Browse files Browse the repository at this point in the history
  • Loading branch information
saurav0705 committed Oct 30, 2023
1 parent 706d114 commit 648aa69
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
45 changes: 45 additions & 0 deletions .github/scripts/check-for-declaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from "fs";
import path from "path";

type ResultType = {
js : Record<string , boolean>
ts : Record<string , boolean>
}

const result: ResultType = {js:{} , ts:{}}

const readThroughDirectory = (directory: string): void => {
const __directoryPath = directory
const files = fs.readdirSync(__directoryPath);
files.forEach((file) => {
const filePath = path.join(__directoryPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
readThroughDirectory(filePath);
return
}

if(filePath.endsWith('.js')){
const name = filePath.split('.')
name.pop()
result.js[name.join('.')] = true
}

if(filePath.endsWith('.d.ts')){
const name = filePath.split('.')
name.pop()
name.pop()
result.ts[name.join('.')] = true
}

});

Object.keys(result.js).forEach(file => {
if(!result.ts[file]){
throw new Error(`Declaration File Missing for ${file}.js`)
}
})

};

readThroughDirectory(path.join(process.env.INIT_CWD ?? '', './bin'))
32 changes: 27 additions & 5 deletions .github/workflows/code-push-ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Сode-push CI

on:
pull_request:
on:
pull_request:
branches:
- master

Expand All @@ -15,10 +15,32 @@ jobs:
- name: Setup NodeJs
uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: "12.x"
- name: Setup dependencies
run: npm run setup
- name: Build
run: npm run build
- name: Run tests
run: npm run build
- name: Run tests
run: npm run test

build-check:
name: Should have declarartion files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup NodeJs
uses: actions/setup-node@v1
with:
node-version: "12.x"

- name: Setup dependencies
run: npm run setup

- name: Generate Release
run: npm run build:release

- name: Check For Declaration
run: |
npm run check:release
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"prebuild": "npm run clean",
"build": "tsc && npm run content",
"prebuild:release": "npm run clean",
"build:release": "tsc -p ./tsconfig-release.json && npm run content",
"build:release": "tsc -p ./tsconfig-release.json && npm run check:release && npm run content",
"check:release" : "npx ts-node .github/scripts/check-for-declaration.ts",
"test": "npm run build && mocha --recursive bin/test",
"test:debugger": "mocha --recursive --inspect-brk=0.0.0.0 bin/test",
"content": "shx cp {README.md,package.json,.npmignore} bin"
Expand Down

0 comments on commit 648aa69

Please sign in to comment.