Skip to content

Commit f045589

Browse files
committed
Create script/workflow to create tpip report and commit to main (#43)
1 parent 22a32e1 commit f045589

File tree

8 files changed

+920
-687
lines changed

8 files changed

+920
-687
lines changed

.github/workflows/tpip.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: TPIP
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/tpip.yml'
7+
- docs/third-party-licenses.json
8+
- docs/tpip-header.md
9+
- scripts/tpip-reporter.ts
10+
branches:
11+
- main
12+
13+
workflow_dispatch:
14+
15+
jobs:
16+
report:
17+
name: Generate report
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.ref_name }}
23+
24+
- uses: actions/setup-node@v2
25+
with:
26+
node-version: '20'
27+
cache: 'yarn'
28+
29+
- name: Install dependencies
30+
run: yarn --frozen-lockfile --prefer-offline
31+
32+
- name: Generate third-party licenses report
33+
run: yarn run tpip:report
34+
35+
- name: Commit changes
36+
run: |
37+
git config --local user.email "[email protected]"
38+
git config --local user.name "GitHub Action"
39+
git add TPIP.md
40+
git commit -m "Update third-party licenses report [skip ci]"
41+
git push

TPIP.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# TPIP Report for vscode-cmsis-debugger
2+
3+
Report prepared at : 26/02/2025, 16:50:28
4+
5+
| *Package* | *Version* | *Repository* | *License* |
6+
|---|---|---|---|
7+
| pyocd | 0.36.0 | https://github.com/pyocd/pyOCD | https://github.com/pyocd/pyOCD/blob/v0.36.0/LICENSE |

docs/third-party-licenses.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"name": "pyocd",
4+
"version": "0.36.0",
5+
"spdx": "Apache-2.0",
6+
"url": "https://github.com/pyocd/pyOCD",
7+
"license": "https://github.com/pyocd/pyOCD/blob/v0.36.0/LICENSE"
8+
}
9+
]

docs/tpip-header.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TPIP Report for vscode-cmsis-debugger
2+

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,25 @@
228228
"watch": "webpack -w",
229229
"lint": "eslint .",
230230
"test": "jest",
231-
"package": "vsce package --yarn"
231+
"package": "vsce package --yarn",
232+
"tpip:report": "ts-node scripts/tpip-reporter --header docs/tpip-header.md docs/third-party-licenses.json TPIP.md"
232233
},
233234
"vsce": {
234235
"yarn": true,
235236
"baseContentUrl": "https://github.com/Open-CMSIS-Pack/vscode-cmsis-debugger/blob/main/README.md"
236237
},
238+
"dependencies": {},
237239
"devDependencies": {
238240
"@types/jest": "^29.5.14",
239241
"@types/node": "^20.14.8",
240242
"@types/node-fetch": "^2.6.12",
241243
"@types/vscode": "^1.63.0",
244+
"@types/yargs": "^17.0.33",
245+
"@types/yarnpkg__lockfile": "^1.1.9",
242246
"@typescript-eslint/eslint-plugin": "^8.24.1",
243247
"@typescript-eslint/parser": "^8.24.1",
244248
"@vscode/vsce": "^3.2.2",
249+
"@yarnpkg/lockfile": "^1.1.0",
245250
"eslint": "^9.20.1",
246251
"extract-zip": "^2.0.1",
247252
"jest": "^29.7.0",
@@ -252,6 +257,7 @@
252257
"ts-jest": "29.2.5",
253258
"ts-loader": "^9.5.2",
254259
"ts-node": "^10.9.2",
260+
"type-fest": "^4.35.0",
255261
"typescript": "^5.4.5",
256262
"typescript-eslint": "8.24.1",
257263
"vscode-uri": "^3.1.0",

scripts/tpip-reporter.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!npx ts-node
2+
3+
/**
4+
* Copyright 2025 Arm Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import yargs from "yargs";
20+
import { hideBin } from "yargs/helpers";
21+
import fs from "fs";
22+
23+
async function main() {
24+
25+
const { json, report, header } = yargs(hideBin(process.argv))
26+
.usage('Usage: $0 <json> <report> [--header <header>]')
27+
.options('header', {
28+
describe: 'Header to add to the report',
29+
type: 'string'
30+
})
31+
.command('$0 <json> <report>', '', y => {
32+
y.positional('json', {
33+
describe: 'JSON file to parse',
34+
type: 'string'
35+
});
36+
y.positional('report', {
37+
describe: 'Report file to generate',
38+
type: 'string'
39+
});
40+
})
41+
.help('h')
42+
.version(false)
43+
.strict()
44+
.parseSync();
45+
46+
const tpipJson = JSON.parse(fs.readFileSync(json as string, "utf8"));
47+
48+
var data: string = '';
49+
if (header && fs.existsSync(header as string)) {
50+
data += fs.readFileSync(header as string, "utf8");
51+
} else {
52+
data += "# TPIP Report\n\n";
53+
}
54+
55+
data += `Report prepared at: ${new Date().toLocaleString('en-GB')}\n\n`;
56+
data += '| *Package* | *Version* | *Repository* | *License* |\n';
57+
data += '|---|---|---|---|\n';
58+
59+
for(const value of tpipJson) {
60+
data += `| ${value.name} | ${value.version} | ${value.url} | ${value.license} |\n`;
61+
}
62+
63+
fs.writeFileSync(report as string, data);
64+
}
65+
66+
main().catch(error => {
67+
console.error(error);
68+
process.exit(1);
69+
});

scripts/update-tpip.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!npx ts-node
2+
3+
/**
4+
* Copyright 2025 Arm Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import fs from "fs";
20+
import yargs from 'yargs'
21+
import { hideBin } from 'yargs/helpers'
22+
import { parse, LockFileObject } from "@yarnpkg/lockfile";
23+
import { PackageJson } from "type-fest";
24+
25+
class PackageFile {
26+
public content: PackageJson;
27+
28+
constructor(filename: string) {
29+
const content = fs.readFileSync(filename, "utf8");
30+
this.content = JSON.parse(content);
31+
}
32+
33+
get dependencies() {
34+
return this.content.dependencies;
35+
}
36+
}
37+
38+
class YarnLock {
39+
public content: LockFileObject;
40+
41+
constructor(filename: string) {
42+
const content = fs.readFileSync(filename, "utf8");
43+
const parsedLockfile = parse(content);
44+
45+
if (parsedLockfile.type === "success") {
46+
this.content = parsedLockfile.object;
47+
} else {
48+
throw new Error(`Failed to parse ${filename} due to merge conflicts`);
49+
}
50+
}
51+
52+
}
53+
54+
async function main() {
55+
56+
const { package: packageFile, lockfile } = yargs(hideBin(process.argv))
57+
.usage('Usage: $0 [options]')
58+
.option('package', {
59+
alias: 'p',
60+
description: 'Path to package.json',
61+
default: 'package.json',
62+
type: 'string',
63+
})
64+
.option('lockfile', {
65+
alias: 'l',
66+
description: 'Path to yarn.lock',
67+
default: 'yarn.lock',
68+
type: 'string',
69+
})
70+
.help('h')
71+
.version(false)
72+
.strict()
73+
.parseSync();
74+
75+
const yarnLock = new YarnLock(lockfile);
76+
const packageJson = new PackageFile(packageFile);
77+
78+
79+
if (packageJson.dependencies) {
80+
console.log("Dependencies in package.json:");
81+
for (const [key, value] of Object.entries(packageJson.dependencies)) {
82+
console.log(`${key}: ${value}`);
83+
}
84+
}
85+
86+
console.log("\nDependencies in yarn.lock:");
87+
for (const [key, value] of Object.entries(yarnLock.content)) {
88+
console.log(`${key}: ${value.version}`);
89+
}
90+
91+
}
92+
93+
main().catch(error => {
94+
console.error(error);
95+
process.exit(1);
96+
});

0 commit comments

Comments
 (0)