Skip to content

Commit d0f3a5a

Browse files
committed
fix: action build process
1 parent 9a1777c commit d0f3a5a

124 files changed

Lines changed: 1216 additions & 6413 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/release.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
permissions:
8+
contents: write
9+
packages: write
10+
11+
jobs:
12+
publish:
13+
name: Publish
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: dylanvann/publish-github-action@v1.1.49
18+
with:
19+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test
2+
on:
3+
push:
4+
branches-ignore:
5+
- main
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 24
16+
cache: npm
17+
- run: npm ci
18+
# Optional integration test of the action using a dedicated GitHub App.
19+
- id: create_token
20+
if: ${{ vars.TEST_GITHUB_APP_ID != '' }}
21+
uses: ./
22+
with:
23+
# The only required permission is `Repository permissions > Metadata: Read-only`.
24+
app_id: ${{ vars.TEST_GITHUB_APP_ID }}
25+
private_key: ${{ secrets.TEST_GITHUB_APP_PRIVATE_KEY }}
26+
- if: ${{ steps.create_token.outcome != 'skipped' }}
27+
run: node --eval "assert('${{ steps.create_token.outputs.token }}'.length > 0);"
28+
- run: npm run prettier -- --check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,76 +61,81 @@ Parent project uuid in Dependency-Track (available in DT v4.8 and later)
6161
## Example usage
6262

6363
With project name and version:
64+
6465
```yml
6566
uses: DependencyTrack/gh-upload-sbom@v3
6667
with:
67-
serverHostname: 'example.com'
68+
serverHostname: "example.com"
6869
apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
69-
projectName: 'Example Project'
70-
projectVersion: 'master'
70+
projectName: "Example Project"
71+
projectVersion: "master"
7172
bomFilename: "/path/to/bom.xml"
7273
autoCreate: true
7374
```
7475
7576
With project name, version and tags:
77+
7678
```yml
7779
uses: DependencyTrack/gh-upload-sbom@v3
7880
with:
79-
serverHostname: 'example.com'
81+
serverHostname: "example.com"
8082
apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
81-
projectName: 'Example Project'
82-
projectVersion: 'master'
83-
projectTags: 'tag1,tag2'
83+
projectName: "Example Project"
84+
projectVersion: "master"
85+
projectTags: "tag1,tag2"
8486
bomFilename: "/path/to/bom.xml"
8587
autoCreate: true
8688
```
8789
8890
With protocol, port and project name:
91+
8992
```yml
9093
uses: DependencyTrack/gh-upload-sbom@v3
9194
with:
9295
protocol: ${{ secrets.DEPENDENCYTRACK_PROTOCOL }}
9396
serverHostname: ${{ secrets.DEPENDENCYTRACK_HOSTNAME }}
9497
port: ${{ secrets.DEPENDENCYTRACK_PORT }}
9598
apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
96-
projectName: 'Example Project'
97-
projectVersion: 'master'
99+
projectName: "Example Project"
100+
projectVersion: "master"
98101
bomFilename: "/path/to/bom.xml"
99102
autoCreate: true
100103
```
101104
102105
With project uuid:
106+
103107
```yml
104108
uses: DependencyTrack/gh-upload-sbom@v3
105109
with:
106-
serverHostname: 'example.com'
110+
serverHostname: "example.com"
107111
apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
108-
project: 'dadec8ad-7053-4e8c-8044-7b6ef698e08d'
112+
project: "dadec8ad-7053-4e8c-8044-7b6ef698e08d"
109113
```
110114
111115
With protocol, port, project name and parent name:
116+
112117
```yml
113118
uses: DependencyTrack/gh-upload-sbom@v3
114119
with:
115120
protocol: ${{ secrets.DEPENDENCYTRACK_PROTOCOL }}
116121
serverHostname: ${{ secrets.DEPENDENCYTRACK_HOSTNAME }}
117122
port: ${{ secrets.DEPENDENCYTRACK_PORT }}
118123
apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
119-
projectName: 'Example Project'
120-
projectVersion: 'master'
124+
projectName: "Example Project"
125+
projectVersion: "master"
121126
bomFilename: "/path/to/bom.xml"
122127
autoCreate: true
123-
parentName: 'Example Parent'
124-
parentVersion: 'master'
128+
parentName: "Example Parent"
129+
parentVersion: "master"
125130
```
126131
127132
With parent uuid:
133+
128134
```yml
129135
uses: DependencyTrack/gh-upload-sbom@v3
130136
with:
131-
serverHostname: 'example.com'
137+
serverHostname: "example.com"
132138
apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
133-
project: 'dadec8ad-7053-4e8c-8044-7b6ef698e08d'
134-
parent: '6a5a3c33-3f8b-42ee-8d50-594bfd95dd32'
139+
project: "dadec8ad-7053-4e8c-8044-7b6ef698e08d"
140+
parent: "6a5a3c33-3f8b-42ee-8d50-594bfd95dd32"
135141
```
136-

action.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
name: 'Upload BOM to Dependency-Track'
1+
name: "Upload BOM to Dependency-Track"
22
author: Patrick Dwyer
3-
description: 'Uploads a CycloneDX software bill of materials to a Dependency-Track server'
3+
description: "Uploads a CycloneDX software bill of materials to a Dependency-Track server"
44
inputs:
55
serverhostname:
6-
description: 'Dependency-Track hostname'
6+
description: "Dependency-Track hostname"
77
required: true
88
port:
9-
description: 'Dependency-Track port'
9+
description: "Dependency-Track port"
1010
required: false
11-
default: '443'
11+
default: "443"
1212
protocol:
13-
description: 'Dependency-Track protocol'
13+
description: "Dependency-Track protocol"
1414
required: false
15-
default: 'https'
15+
default: "https"
1616
apikey:
17-
description: 'Dependency-Track API key'
17+
description: "Dependency-Track API key"
1818
required: true
1919
project:
20-
description: 'Project in Dependency-Track'
20+
description: "Project in Dependency-Track"
2121
required: false
2222
projectname:
23-
description: 'Project name in Dependency-Track'
23+
description: "Project name in Dependency-Track"
2424
required: false
2525
projectversion:
26-
description: 'Project version in Dependency-Track'
26+
description: "Project version in Dependency-Track"
2727
required: false
2828
projecttags:
29-
description: 'Comma-separated list of tags (available in DT v4.12 and later)'
30-
default: ''
29+
description: "Comma-separated list of tags (available in DT v4.12 and later)"
30+
default: ""
3131
required: false
3232
autocreate:
3333
description: "Automatically create the project in Dependency-Track if it doesn't exist"
34-
default: 'false'
34+
default: "false"
3535
required: false
3636
bomfilename:
37-
description: 'Path and filename of the BOM'
38-
default: 'bom.xml'
37+
description: "Path and filename of the BOM"
38+
default: "bom.xml"
3939
required: false
4040
parent:
41-
description: 'Parent project UUID in Dependency-Track (available in DT v4.8 and later)'
41+
description: "Parent project UUID in Dependency-Track (available in DT v4.8 and later)"
4242
required: false
4343
parentname:
44-
description: 'Parent project name in Dependency-Track (available in DT v4.8 and later)'
44+
description: "Parent project name in Dependency-Track (available in DT v4.8 and later)"
4545
required: false
4646
parentversion:
47-
description: 'Parent project version in Dependency-Track (available in DT v4.8 and later)'
47+
description: "Parent project version in Dependency-Track (available in DT v4.8 and later)"
4848
required: false
4949
runs:
50-
using: 'node24'
51-
main: 'index.js'
50+
using: "node24"
51+
main: "index.js"

index.js

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
1-
const fs = require('fs');
2-
const core = require('@actions/core');
1+
const fs = require("fs");
2+
const core = require("@actions/core");
33

44
async function run() {
55
try {
6-
const serverHostname = core.getInput('serverhostname');
7-
const port = core.getInput('port');
8-
const protocol = core.getInput('protocol');
9-
const apiKey = core.getInput('apikey');
10-
const project = core.getInput('project');
11-
const projectName = core.getInput('projectname');
12-
const projectVersion = core.getInput('projectversion');
13-
const projectTags = core.getInput('projecttags');
14-
const autoCreate = core.getInput('autocreate') !== 'false';
15-
const bomFilename = core.getInput('bomfilename');
16-
const parent = core.getInput('parent');
17-
const parentName = core.getInput('parentname');
18-
const parentVersion = core.getInput('parentversion');
6+
const serverHostname = core.getInput("serverhostname");
7+
const port = core.getInput("port");
8+
const protocol = core.getInput("protocol");
9+
const apiKey = core.getInput("apikey");
10+
const project = core.getInput("project");
11+
const projectName = core.getInput("projectname");
12+
const projectVersion = core.getInput("projectversion");
13+
const projectTags = core.getInput("projecttags");
14+
const autoCreate = core.getInput("autocreate") !== "false";
15+
const bomFilename = core.getInput("bomfilename");
16+
const parent = core.getInput("parent");
17+
const parentName = core.getInput("parentname");
18+
const parentVersion = core.getInput("parentversion");
1919

2020
if (protocol !== "http" && protocol !== "https") {
21-
throw 'protocol "' + protocol + '" not supported, must be one of: https, http'
21+
throw (
22+
'protocol "' + protocol + '" not supported, must be one of: https, http'
23+
);
2224
}
2325

2426
if (project === "" && (projectName === "" || projectVersion === "")) {
25-
throw 'project or projectName + projectVersion must be set'
27+
throw "project or projectName + projectVersion must be set";
2628
}
2729

2830
if (!autoCreate && project === "") {
29-
throw 'project can\'t be empty if autoCreate is false'
31+
throw "project can't be empty if autoCreate is false";
3032
}
3133

3234
if (project === "" && (projectName === "" || projectVersion === "")) {
33-
throw 'project or projectName + projectVersion must be set'
35+
throw "project or projectName + projectVersion must be set";
3436
}
3537

36-
if ((parentName === "" && parentVersion !== "") || (parentName !== "" && parentVersion === "")) {
37-
throw 'parentName + parentVersion must both be set'
38+
if (
39+
(parentName === "" && parentVersion !== "") ||
40+
(parentName !== "" && parentVersion === "")
41+
) {
42+
throw "parentName + parentVersion must both be set";
3843
}
3944

4045
core.info(`Reading BOM: ${bomFilename}...`);
4146
const bomContents = fs.readFileSync(bomFilename);
42-
let encodedBomContents = Buffer.from(bomContents).toString('base64');
43-
if (encodedBomContents.startsWith('77u/')) {
47+
let encodedBomContents = Buffer.from(bomContents).toString("base64");
48+
if (encodedBomContents.startsWith("77u/")) {
4449
encodedBomContents = encodedBomContents.substring(4);
4550
}
4651

@@ -50,56 +55,62 @@ async function run() {
5055
projectName: projectName,
5156
projectVersion: projectVersion,
5257
autoCreate: autoCreate,
53-
bom: encodedBomContents
54-
}
58+
bom: encodedBomContents,
59+
};
5560
if (projectTags) {
56-
bomPayload.projectTags = projectTags.split(',').map(tag => ({name: tag.trim()}));
61+
bomPayload.projectTags = projectTags
62+
.split(",")
63+
.map((tag) => ({ name: tag.trim() }));
5764
}
5865
} else {
5966
bomPayload = {
6067
project: project,
61-
bom: encodedBomContents
62-
}
68+
bom: encodedBomContents,
69+
};
6370
}
6471

6572
if (parent && parent.trim().length > 0) {
6673
bomPayload.parentUUID = parent;
67-
} else if (parentName && parentName.trim().length > 0 && parentVersion && parentVersion.trim().length > 0) {
74+
} else if (
75+
parentName &&
76+
parentName.trim().length > 0 &&
77+
parentVersion &&
78+
parentVersion.trim().length > 0
79+
) {
6880
bomPayload.parentName = parentName;
6981
bomPayload.parentVersion = parentVersion;
7082
}
7183

7284
const postData = JSON.stringify(bomPayload);
7385

7486
const requestOptions = {
75-
method: 'PUT',
87+
method: "PUT",
7688
headers: {
77-
'X-API-Key': apiKey,
78-
'Content-Type': 'application/json',
89+
"X-API-Key": apiKey,
90+
"Content-Type": "application/json",
7991
},
80-
body: postData
92+
body: postData,
8193
};
8294

8395
const url = new URL(`${protocol}://${serverHostname}`);
8496
if (port) {
8597
url.port = port;
8698
}
87-
url.pathname = '/api/v1/bom';
99+
url.pathname = "/api/v1/bom";
88100

89101
core.info(`Uploading to Dependency-Track server ${serverHostname}...`);
90102

91103
const response = await fetch(url.toString(), requestOptions);
92104

93105
if (response.ok) {
94-
core.info('Finished uploading BOM to Dependency-Track server.');
106+
core.info("Finished uploading BOM to Dependency-Track server.");
95107
} else {
96108
const responseBody = await response.text();
97109
if (responseBody) {
98110
core.debug(responseBody);
99111
}
100-
core.setFailed('Failed response status code:' + response.status);
112+
core.setFailed("Failed response status code:" + response.status);
101113
}
102-
103114
} catch (error) {
104115
core.setFailed(error.message);
105116
}

node_modules/.bin/uuid

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)