Skip to content

Commit eecd799

Browse files
RD-1197 Migrate to platform architecture (#4)
1 parent dc9636e commit eecd799

File tree

8 files changed

+125
-56
lines changed

8 files changed

+125
-56
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
outputs:
1717
SCAN_BADGE: ${{ steps.deepbits-scan.outputs.DEEPBITS_BADGE }}
18-
DEEPBITS_LINK: ${{ steps.deepbits-scan.outputs.DEEPBITS_COMMIT }}
18+
DEEPSCA_BRANCH_LINK: ${{ steps.deepbits-scan.outputs.DEEPSCA_BRANCH }}
1919
steps:
2020
- uses: actions/checkout@v3
2121

@@ -35,7 +35,7 @@ jobs:
3535
---
3636
3737
Powered by [**Deepbits**](https://deepbits.com):
38-
- Scan Details: ${{ needs.deepbits-scan.outputs.DEEPBITS_LINK }}
38+
- Scan Details: ${{ needs.deepbits-scan.outputs.DEEPSCA_BRANCH_LINK }}
3939
- Badge: ${{ needs.deepbits-scan.outputs.SCAN_BADGE }}
4040
4141
download-artifact:

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
runs-on: ubuntu-latest
3939
outputs:
4040
SCAN_BADGE: ${{ steps.deepbits-scan.outputs.DEEPBITS_BADGE }}
41-
DEEPBITS_COMMIT_LINK: ${{ steps.deepbits-scan.outputs.DEEPBITS_COMMIT }}
42-
DEEPBITS_REPO_LINK: ${{ steps.deepbits-scan.outputs.DEEPBITS_REPO }}
41+
DEEPSCA_BRANCH_LINK: ${{ steps.deepbits-scan.outputs.DEEPSCA_BRANCH }}
42+
DEEPSCA_REPO_LINK: ${{ steps.deepbits-scan.outputs.DEEPSCA_REPO }}
4343
steps:
4444
- uses: DeepBitsTechnology/getsbom@v1
4545
id: deepbits-scan
@@ -71,22 +71,22 @@ We hope that these examples will help you understand the capabilities of our act
7171

7272
## Actions Outputs
7373

74-
In addition to the artifact, you may also view the scan results and your previous scan histories on [DeepRepo](https://tools.deepbits.com/github).
74+
In addition to the artifact, you may also view the scan results and your previous scan histories on [DeepSCA](https://tools.deepbits.com).
7575

7676
Additionally, a SVG is available that can be included in your README file.
7777

7878
To obtain these outputs, please refer to the three options listed below:
7979

80-
| Output | Description |
81-
| --------------- | ----------------------------------------------------------- |
82-
| DEEPBITS_REPO | The URL to access the repo details of DeepRepo |
83-
| DEEPBITS_COMMIT | The URL to access the scan report of the commit on DeepRepo |
84-
| DEEPBITS_BADGE | A SVG badge displaying the status of the the repo |
80+
| Output | Description |
81+
| -------------- | ---------------------------------------------------------- |
82+
| DEEPSCA_REPO | The URL to access the repo details of DeepSCA |
83+
| DEEPSCA_BRANCH | The URL to access the scan report of the branch on DeepSCA |
84+
| DEEPBITS_BADGE | A SVG badge displaying the status of the the repo |
8585

8686
You can add the SVG badge to your README.md file like this:
8787

8888
```markdown
89-
[![SBOM status]({{DEEPBITS_BADGE}})]({{DEEPBITS_REPO}})
89+
[![SBOM status]({{DEEPBITS_BADGE}})]({{DEEPSCA_REPO}})
9090
```
9191

9292
For example, the badge for this repository is:
@@ -97,11 +97,11 @@ For example, the badge for this repository is:
9797

9898
[![SBOM status](https://api.deepbits.com/gh/DeepBitsTechnology/getsbom/badge)](https://tools.deepbits.com/github/DeepBitsTechnology/getsbom)
9999

100-
**The image below is a screenshot of a scan result on [DeepRepo](https://tools.deepbits.com/github), which is accessible through the `DEEPBITS_COMMIT` output.**
100+
**The image below is a screenshot of a scan result on [DeepSCA](https://tools.deepbits.com), which is accessible through the `DEEPSCA_BRANCH` output.**
101101

102-
![Scan result on DeepRepo](./samples/deeprepo_scan_screenshots.png)
102+
![Scan result on DeepSCA](./samples/deeprepo_scan_screenshots.png)
103103

104-
The scan results displayed in DeepRepo are interactive and allow you to view detailed information about the components used in your project, as well as any vulnerabilities or licensing issues detected during the scan.
104+
The scan results displayed in DeepSCA are interactive and allow you to view detailed information about the components used in your project, as well as any vulnerabilities or licensing issues detected during the scan.
105105

106106
Click [this URL](https://tools.deepbits.com/github/DeepBitsTechnology/getsbom/d29263777ef33157254ff4207ca00cedf0d537e1) to see the comprehensive view of the screenshot results.
107107

dist/index.js

Lines changed: 47 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import * as core from '@actions/core';
22
import {
33
downloadCommitSbomZip,
4+
getBranchName,
45
getScanResult,
6+
isProperEvent,
57
isRepoPublic,
68
setInfo,
79
uploadArtifacts,
810
} from './utils/DeepbitsGitHubAction';
911

1012
export async function run(): Promise<void> {
1113
try {
14+
if (!(await isProperEvent())) {
15+
core.setFailed(
16+
'This action is available for branch push only at the moment.'
17+
);
18+
return;
19+
}
20+
1221
const isPublic = await isRepoPublic();
1322

1423
if (!isPublic) {
15-
core.setFailed('Private repositories are not supported');
24+
core.setFailed('Private repositories are not supported.');
25+
return;
26+
}
27+
28+
const branchName = getBranchName();
29+
30+
if (!branchName) {
31+
core.setFailed('Branch name is not available.');
1632
return;
1733
}
1834

19-
const scanResult = (await getScanResult())?.scanResult?.[0];
35+
const scanResult = (await getScanResult(branchName))?.scanResult;
2036

2137
let sbomZipFileLocation: string | undefined;
2238

@@ -31,7 +47,7 @@ export async function run(): Promise<void> {
3147
sbomZipFileLocation ? [sbomZipFileLocation] : undefined
3248
);
3349

34-
await setInfo();
50+
await setInfo(branchName);
3551
} catch (error) {
3652
if (error instanceof Error) core.setFailed(error.message);
3753
}

src/types/deepbitsApi.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export type ScanResult = {
3737
sbomResult?: SBOMInfo[];
3838
};
3939

40-
export type GitHubCommitDefWithPopulatedScanResult = Omit<
41-
GitHubCommitDef,
42-
'scanResult'
43-
> & {
44-
scanResult?: ScanResult[];
45-
};
40+
export interface ScanResultResponse {
41+
scanResult?: ScanResult;
42+
resourceMetaData?: any; // TODO: Feature Roadmap
43+
sbomStream?: any; // TODO: Feature Roadmap
44+
}

src/utils/DeepbitsGitHubAction.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import {BASE_URL, TOOLS_URL, getCommitResultUntilScanEnds} from './api';
77

88
const ROOT_DIRECTORY_NAME = 'DEEPBITS_SCAN_RESULTS';
99

10+
export const isProperEvent = async (): Promise<boolean> => {
11+
const eventName = github.context.eventName;
12+
13+
return eventName === 'push';
14+
};
15+
1016
export const isRepoPublic = async (): Promise<boolean> => {
1117
const token = core.getInput('token');
1218
const context = github.context;
@@ -20,31 +26,46 @@ export const isRepoPublic = async (): Promise<boolean> => {
2026
return !data.private;
2127
};
2228

23-
export const getScanResult = async () => {
29+
export const getBranchName = () => {
30+
const context = github.context;
31+
32+
const {ref} = context;
33+
const prHeadRef = process.env.GITHUB_HEAD_REF;
34+
35+
return github.context.eventName === 'pull_request'
36+
? prHeadRef
37+
: ref.replace('refs/heads/', '');
38+
};
39+
40+
export const getScanResult = async (branchName: string) => {
2441
const context = github.context;
2542

2643
const {sha} = context;
2744
const {owner, repo} = context.repo;
2845

29-
const result = await getCommitResultUntilScanEnds({owner, repo, sha});
46+
const result = await getCommitResultUntilScanEnds({
47+
owner,
48+
repo,
49+
branchName,
50+
sha,
51+
});
3052

3153
return result;
3254
};
3355

34-
export const setInfo = async () => {
56+
export const setInfo = async (branchName: string) => {
3557
const context = github.context;
3658

37-
const {sha} = context;
3859
const {owner, repo} = context.repo;
3960

4061
const infoList = [
4162
{
42-
name: 'DEEPBITS_REPO',
63+
name: 'DEEPSCA_REPO',
4364
value: `${TOOLS_URL}/${owner}/${repo}`,
4465
},
4566
{
46-
name: 'DEEPBITS_COMMIT',
47-
value: `${TOOLS_URL}/${owner}/${repo}/${sha}`,
67+
name: 'DEEPSCA_BRANCH',
68+
value: `${TOOLS_URL}/${owner}/${repo}/${branchName}`,
4869
},
4970
{
5071
name: 'DEEPBITS_BADGE',

0 commit comments

Comments
 (0)