Skip to content
Merged

Tpip #43

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/tpip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
paths:
- '.github/workflows/tpip.yml'
- docs/third-party-licenses.json
- docs/tpip-header.md
- scripts/tpip-reporter.ts
branches:
- main

workflow_dispatch:

jobs:
report:
name: Generate Third-Party licenses report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}

- uses: actions/setup-node@v2
with:
node-version: '20'
cache: 'yarn'

- name: Install dependencies
run: yarn --frozen-lockfile --prefer-offline

- name: Generate third-party licenses report
run: yarn run tpip:report

- name: Commit changes
run: |
git config --local user.email "[email protected]
git config --local user.name "GitHub Action"
git add TPIP.md
git commit -m "Update third-party licenses report [skip ci]"
git push
7 changes: 7 additions & 0 deletions TPIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# TPIP Report for vscode-cmsis-debugger

Report prepared at : 26/02/2025, 16:50:28

| *Package* | *Version* | *Repository* | *License* |
|---|---|---|---|
| pyocd | 0.36.0 | https://github.com/pyocd/pyOCD | https://github.com/pyocd/pyOCD/blob/v0.36.0/LICENSE |
9 changes: 9 additions & 0 deletions docs/third-party-licenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"name": "pyocd",
"version": "0.36.0",
"spdx": "Apache-2.0",
"url": "https://github.com/pyocd/pyOCD",
"license": "https://github.com/pyocd/pyOCD/blob/v0.36.0/LICENSE"
}
]
2 changes: 2 additions & 0 deletions docs/tpip-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TPIP Report for vscode-cmsis-debugger

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,25 @@
"watch": "webpack -w",
"lint": "eslint .",
"test": "jest",
"package": "vsce package --yarn"
"package": "vsce package --yarn",
"tpip:report": "ts-node scripts/tpip-reporter --header docs/tpip-header.md docs/third-party-licenses.json TPIP.md"
},
"vsce": {
"yarn": true,
"baseContentUrl": "https://github.com/Open-CMSIS-Pack/vscode-cmsis-debugger/blob/main/README.md"
},
"dependencies": {},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^20.14.8",
"@types/node-fetch": "^2.6.12",
"@types/vscode": "^1.63.0",
"@types/yargs": "^17.0.33",
"@types/yarnpkg__lockfile": "^1.1.9",
"@typescript-eslint/eslint-plugin": "^8.24.1",
"@typescript-eslint/parser": "^8.24.1",
"@vscode/vsce": "^3.2.2",
"@yarnpkg/lockfile": "^1.1.0",
"eslint": "^9.20.1",
"extract-zip": "^2.0.1",
"jest": "^29.7.0",
Expand All @@ -252,6 +257,7 @@
"ts-jest": "29.2.5",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"type-fest": "^4.35.0",
"typescript": "^5.4.5",
"typescript-eslint": "8.24.1",
"vscode-uri": "^3.1.0",
Expand Down
69 changes: 69 additions & 0 deletions scripts/tpip-reporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!npx ts-node

/**
* Copyright 2025 Arm Limited
*
* 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
*
* http://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.
*/

import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import fs from "fs";

async function main() {

const { json, report, header } = yargs(hideBin(process.argv))
.usage('Usage: $0 <json> <report> [--header <header>]')
.options('header', {
describe: 'Header to add to the report',
type: 'string'
})
.command('$0 <json> <report>', '', y => {
y.positional('json', {
describe: 'JSON file to parse',
type: 'string'
});
y.positional('report', {
describe: 'Report file to generate',
type: 'string'
});
})
.help('h')
.version(false)
.strict()
.parseSync();

const tpipJson = JSON.parse(fs.readFileSync(json as string, "utf8"));

var data: string = '';
if (header && fs.existsSync(header as string)) {
data += fs.readFileSync(header as string, "utf8");
} else {
data += "# TPIP Report\n\n";
}

data += `Report prepared at: ${new Date().toLocaleString('en-GB')}\n\n`;
data += '| *Package* | *Version* | *Repository* | *License* |\n';
data += '|---|---|---|---|\n';

for(const value of tpipJson) {
data += `| ${value.name} | ${value.version} | ${value.url} | ${value.license} |\n`;
}

fs.writeFileSync(report as string, data);
}

main().catch(error => {
console.error(error);
process.exit(1);
});
96 changes: 96 additions & 0 deletions scripts/update-tpip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!npx ts-node

/**
* Copyright 2025 Arm Limited
*
* 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
*
* http://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.
*/

import fs from "fs";
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import { parse, LockFileObject } from "@yarnpkg/lockfile";
import { PackageJson } from "type-fest";

class PackageFile {
public content: PackageJson;

constructor(filename: string) {
const content = fs.readFileSync(filename, "utf8");
this.content = JSON.parse(content);
}

get dependencies() {
return this.content.dependencies;
}
}

class YarnLock {
public content: LockFileObject;

constructor(filename: string) {
const content = fs.readFileSync(filename, "utf8");
const parsedLockfile = parse(content);

if (parsedLockfile.type === "success") {
this.content = parsedLockfile.object;
} else {
throw new Error(`Failed to parse ${filename} due to merge conflicts`);
}
}

}

async function main() {

const { package: packageFile, lockfile } = yargs(hideBin(process.argv))
.usage('Usage: $0 [options]')
.option('package', {
alias: 'p',
description: 'Path to package.json',
default: 'package.json',
type: 'string',
})
.option('lockfile', {
alias: 'l',
description: 'Path to yarn.lock',
default: 'yarn.lock',
type: 'string',
})
.help('h')
.version(false)
.strict()
.parseSync();

const yarnLock = new YarnLock(lockfile);
const packageJson = new PackageFile(packageFile);


if (packageJson.dependencies) {
console.log("Dependencies in package.json:");
for (const [key, value] of Object.entries(packageJson.dependencies)) {
console.log(`${key}: ${value}`);
}
}

console.log("\nDependencies in yarn.lock:");
for (const [key, value] of Object.entries(yarnLock.content)) {
console.log(`${key}: ${value.version}`);
}

}

main().catch(error => {
console.error(error);
process.exit(1);
});
Loading
Loading