Skip to content

Commit bebdc79

Browse files
authored
[patch] Update packs (#1)
1 parent 3404100 commit bebdc79

File tree

8 files changed

+2922
-2856
lines changed

8 files changed

+2922
-2856
lines changed

.github/workflows/build.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: NodeJS with Webpack
2+
permissions: write-all
3+
4+
on:
5+
push:
6+
branches: [ "main" ]
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Use Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18.x'
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- uses: volta-cli/action@v4
23+
- name: Install
24+
run: npm ci
25+
26+
- name: Versions
27+
run: |
28+
node --version
29+
npm --version
30+
31+
- name: Lint
32+
run: npm run lint
33+
34+
- name: Build
35+
run: npm run build
36+
37+
- name: Test Jest
38+
run: npm run test:cov
39+
40+
- name: Archive code coverage results
41+
if: success() || failure() # always run even if the previous step fails
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: code-coverage-report
45+
path: ./reports/coverage-jest/lcov-report/
46+
47+
- name: Monitor coverage
48+
if: success() || failure() # always run even if the previous step fails
49+
uses: slavcodev/coverage-monitor-action@v1
50+
with:
51+
github_token: ${{ secrets.GITHUB_TOKEN }}
52+
coverage_path: "reports/coverage-jest/clover.xml"
53+
54+
- name: Publish
55+
env:
56+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
57+
run: |
58+
branch=${{ github.ref }}
59+
echo "Branch: $branch"
60+
61+
gitmsg="${{ github.event.commits[0].message }}"
62+
echo "Commit: $gitmsg"
63+
64+
if [[ "$gitmsg" =~ "[patch]" ]]; then
65+
echo "publish patch"
66+
npm run publish:patch
67+
git push --tags
68+
exit 0
69+
fi
70+
71+
if [[ "$gitmsg" =~ "[fix]" ]]; then
72+
echo "publish patch"
73+
npm run publish:patch
74+
git push --tags
75+
exit 0
76+
fi
77+
78+
if [[ "$gitmsg" =~ "[minor]" ]]; then
79+
echo "publish minor"
80+
npm run publish:minor
81+
git push --tags
82+
exit 0
83+
fi
84+
85+
if [[ "$gitmsg" =~ "[major]" ]]; then
86+
echo "publish major"
87+
npm run publish:major
88+
git push --tags
89+
exit 0
90+
fi
91+
92+
echo "publishing alpha, for other commit message should contain [minor], [major] or [patch]/[fix]"
93+
npm run publish:alpha
94+
git push --tags

.scripts/merge.js

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env node
2+
const yargs = require("yargs");
3+
const path = require("path");
4+
const istanbul = require('istanbul-lib-coverage');
5+
const { existsSync, mkdirSync, rmSync, writeFileSync, readFileSync} = require("fs");
6+
7+
/**
8+
* this taken from @cypress/code-coverage
9+
* @param coverage object
10+
*/
11+
function fixSourcePaths(coverage) {
12+
Object.values(coverage).forEach((file) => {
13+
const { path: absolutePath, inputSourceMap } = file
14+
const fileName = /([^\/\\]+)$/.exec(absolutePath)[1]
15+
if (!inputSourceMap || !fileName) return
16+
17+
if (inputSourceMap.sourceRoot) inputSourceMap.sourceRoot = ''
18+
inputSourceMap.sources = inputSourceMap.sources.map((source) =>
19+
source.includes(fileName) ? absolutePath : source
20+
)
21+
})
22+
}
23+
24+
/**
25+
* this partly taken from @cypress/code-coverage
26+
* @param tempDir directory where to merge
27+
* @param fileWithCoverage file containing coverage
28+
*/
29+
function combineCoverage(tempDir, fileWithCoverage) {
30+
const fileToSave = `${tempDir}/combined.json`;
31+
32+
const coverage = existsSync(fileToSave)
33+
? JSON.parse(readFileSync(fileToSave, 'utf8'))
34+
: {};
35+
36+
fixSourcePaths(coverage)
37+
38+
const previousCoverage = existsSync(fileWithCoverage)
39+
? JSON.parse(readFileSync(fileWithCoverage, 'utf8'))
40+
: {}
41+
42+
const coverageMap = istanbul.createCoverageMap(previousCoverage)
43+
coverageMap.merge(coverage)
44+
45+
writeFileSync(fileToSave, JSON.stringify(coverageMap, null, 2))
46+
console.log('combined coverage from `%s` with %s', fileToSave, fileWithCoverage)
47+
}
48+
49+
/**
50+
* Create report by NYC library,
51+
* Will not read nyc config and temp dic from nyc.config.js
52+
* @param tempDir dir where json files located
53+
* @param reportDir dir where to put report
54+
* @param reporterArr array with reporters like ['json', 'lcov', 'text']
55+
*/
56+
function createReport(tempDir, reportDir, reporterArr){
57+
const NYC = require('nyc');
58+
const nycReportOptions = {
59+
reportDir: reportDir,
60+
tempDir: tempDir,
61+
reporter: reporterArr ?? ['json', 'lcov', 'text'],
62+
};
63+
64+
const nyc = new NYC(nycReportOptions)
65+
66+
nyc.report().then(()=> {
67+
console.log("Report created");
68+
})
69+
}
70+
71+
/**
72+
* Remove directory sync
73+
* @param dir
74+
*/
75+
const removeDir = (dir) => {
76+
const pathResolved = path.resolve(dir)
77+
if(existsSync(pathResolved)){
78+
rmSync(pathResolved, {recursive: true});
79+
}
80+
}
81+
82+
/**
83+
* Clear directory sync
84+
* @param dir
85+
*/
86+
const clearDir = (dir) => {
87+
const pathResolved = path.resolve(dir)
88+
if(existsSync(pathResolved)){
89+
rmSync(pathResolved, {recursive: true});
90+
}
91+
mkdirSync(pathResolved, {recursive: true});
92+
}
93+
94+
const argv = yargs(process.argv.slice(2))
95+
.options({
96+
cypress: {
97+
type: 'string',
98+
demandOption: true,
99+
default: 'reports/coverage-cypress',
100+
describe: `Path to coverage reports directory (relative to current working directory)
101+
Path with directories - each of them should contain coverage report (coverage-final.json)`,
102+
},
103+
jest: {
104+
type: 'string',
105+
demandOption: true,
106+
default: 'reports/coverage-jest',
107+
describe: `Path to jet coverage report, should contain coverage report (coverage-final.json)`,
108+
},
109+
out: {
110+
type: 'string',
111+
demandOption: true,
112+
default: 'reports/coverage-temp',
113+
describe: `Path to final report`,
114+
},
115+
report: {
116+
type: 'string',
117+
demandOption: true,
118+
default: 'reports/coverage-full',
119+
describe: `Path to final report`,
120+
},
121+
})
122+
.alias('c', 'cypress')
123+
.alias('j', 'jest')
124+
.alias('h', 'help')
125+
.help('help')
126+
.parseSync();
127+
128+
console.log(' ======== MERGE COVERAGE REPORTS');
129+
130+
const { jest, cypress, out, report } = argv;
131+
const outDir = path.resolve(out);
132+
const reportDir = path.resolve(report);
133+
134+
removeDir(reportDir);
135+
clearDir(outDir);
136+
137+
combineCoverage(outDir, `${cypress}/coverage-final.json`);
138+
combineCoverage(outDir, `${jest}/coverage-final.json`);
139+
createReport(outDir, reportDir, ['json', 'lcov', 'text', 'cobertura', 'clover']);

.scripts/remove.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
sed '/"scripts":/,/},/d' dist/package.json > dist/temp.json
4+
5+
mv dist/temp.json dist/package.json

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
moduleFileExtensions: ['ts', 'js'],
99
clearMocks: true,
1010
coverageDirectory: 'reports/coverage-jest',
11-
coverageReporters: ['text', 'lcov', 'cobertura', 'json'],
11+
coverageReporters: ['text', 'lcov', 'cobertura', 'json', 'clover'],
1212
setupFilesAfterEnv: ['./jest.setup.ts'],
1313
collectCoverageFrom: ['src/**/*.{ts,tsx}', 'src/*.{ts,tsx}', '!**/node_modules/**'],
1414
testEnvironment: 'node',

0 commit comments

Comments
 (0)