-
Notifications
You must be signed in to change notification settings - Fork 4
126 lines (106 loc) · 4.9 KB
/
ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
name: ci
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
vulnerability-scan:
name: vulnerability-scan
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
statuses: read
checks: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: anchore/scan-action/download-grype@v4
id: grype
- name: code scan
run: ${{steps.grype.outputs.cmd}} -v -o json --file output.json --fail-on high --only-fixed dir:.
- name: Output results to markdown table as a comment on the PR
if: (success() || failure()) && github.event_name == 'pull_request'
run: |
echo '### Library Vulnerability scan results' > table.txt
echo -e 'The following vulnerabilities have been found in libraries included in the repository (some might be dependencies of dependencies).\n' >> table.txt
echo -e 'Critical and High severity vulnerabilities **must** be fixed before the PR can be merged, even if they are dependencies of dependencies.\n' >> table.txt
jq -r '.matches[] | [.artifact.name, .artifact.version, .vulnerability.severity, .vulnerability.fix.versions[0], .vulnerability.id, .vulnerability.dataSource] | @tsv' output.json | awk -v FS="\t" 'BEGIN{print "| Library | Vulnerable version | Severity | Fix version | Vulnerability ID |";print "| ------------ | ------------ | ------------ | ------------ | ------------ |"}{printf "| %s | %s | %s | %s | [%s](%s) |%s",$1,$2,$3,$4,$5,$6,ORS}' >> table.txt
sed -ie 's/Critical/**Critical** :red_circle:/g' table.txt
sed -ie 's/High/**High** :yellow_circle:/g' table.txt
cat table.txt
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
gh pr comment $PR_NUMBER -F table.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
java-unit-test:
name: java-unit-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze SDK
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./mvnw -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} -Dsonar.projectKey=${{ vars.SONAR_JAVA_PROJECT_KEY }}
nodejs-unit-test:
name: nodejs-unit-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.12
registry-url: 'https://registry.npmjs.org'
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
working-directory: ./kraken-app/kraken-app-portal
run: echo "dir=$(npm config get cache)" >> "${GITHUB_OUTPUT}"
- uses: actions/cache@v3
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: browser-actions/setup-chrome@latest
# Skip post-install scripts here, as a malicious
# script could steal NODE_AUTH_TOKEN.
- run: npm ci --ignore-scripts --legacy-peer-deps
working-directory: ./kraken-app/kraken-app-portal
- run: npm run build --if-present
working-directory: ./kraken-app/kraken-app-portal
# some repos don't have unit test now, need to add in future.
- run: CHROME_BIN=$(which chrome) npm run test:coverage -- -u
working-directory: ./kraken-app/kraken-app-portal
- name: SonarCloud Scan
if: success() || failure()
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.organization=${{ vars.SONAR_ORGANIZATION }}
-Dsonar.projectKey=${{ vars.SONAR_NODEJS_PROJECT_KEY }}