forked from ShiftLeftSecurity/shiftleft-csharp-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (65 loc) · 2.92 KB
/
shiftleft.yml
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
# This workflow integrates ShiftLeft NG SAST with GitHub
# Visit https://docs.shiftleft.io for help
name: ShiftLeft
on:
pull_request:
workflow_dispatch:
jobs:
NextGen-Static-Analysis:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Download ShiftLeft CLI
run: |
Invoke-WebRequest -Uri 'https://cdn.shiftleft.io/download/sl-latest-windows-x64.zip' -OutFile sl.zip
Expand-Archive -Path sl.zip -DestinationPath .
- name: Build web api
run: dotnet build netcoreWebapi
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Analyze with NextGen Static Analysis
run: .\sl analyze --strict --app shiftleft-csharp-demo --tag branch=${{ github.head_ref || steps.extract_branch.outputs.branch }} --csharp --dotnet --cpg netcoreWebapi/netcoreWebapi.csproj
env:
SHIFTLEFT_ACCESS_TOKEN: ${{ secrets.SHIFTLEFT_ACCESS_TOKEN }}
- name: Create status check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: https://www.shiftleft.io/findingsSummary/shiftleft-csharp-demo?apps=shiftleft-csharp-demo&isApp=1
run: |
$params = @{
Uri = "https://api.github.com/repos/$ENV:GITHUB_REPOSITORY/check-runs"
Headers = @{
'Authorization' = "Bearer $ENV:GITHUB_TOKEN"
'Accept' = 'application/vnd.github.antiope-preview+json'
}
Method = 'POST'
Body = "{`"name`": `"ShiftLeft NextGen Static Analysis`", `"head_sha`": `"$ENV:GITHUB_REF`", `"external_id`": `"shiftleft-csharp-demo`", `"details_url`": `"$ENV:URL`", `"status`": `"completed`", `"conclusion`": `"action_required`", `"output`": {`"title`": `"ShiftLeft NextGen Static Analysis Findings`", `"summary`": `"Visit $ENV:URL for the findings`"}}"
ContentType = 'application/json'
}
Invoke-RestMethod @params
Build-Rules:
runs-on: windows-latest
needs: NextGen-Static-Analysis
steps:
- uses: actions/checkout@v2
- name: Download ShiftLeft CLI
run: |
Invoke-WebRequest -Uri 'https://cdn.shiftleft.io/download/sl-latest-windows-x64.zip' -OutFile sl.zip
Expand-Archive -Path sl.zip -DestinationPath .
- name: Validate Build Rules
run: |
.\sl check-analysis --app shiftleft-csharp-demo `
--branch "${{ github.head_ref || steps.extract_branch.outputs.branch }}" `
--report `
--github-pr-number=${{github.event.number}} `
--github-pr-user=${{ github.repository_owner }} `
--github-pr-repo=${{ github.event.repository.name }} `
--github-token=${{ secrets.GITHUB_TOKEN }}
env:
SHIFTLEFT_ACCESS_TOKEN: ${{ secrets.SHIFTLEFT_ACCESS_TOKEN }}