-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (102 loc) · 3.04 KB
/
github-actions-ci.yml
File metadata and controls
120 lines (102 loc) · 3.04 KB
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
name: build & test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
ACCOUNT: ${{ github.repository_owner }}
REPOSITORY: ${{ github.event.repository.name }}
jobs:
# ----------- BUILD STAGE ----------- #
build:
runs-on: ubuntu-latest
container: docker:git
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: resolve paths-filter error
run: git config --global --add safe.directory /__w/${REPOSITORY}/${REPOSITORY}
- name: detect build file changes
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
buildfiles:
- Dockerfile
- requirements.txt
- tests/requirements-test.txt
- name: build & push image to registry
if: steps.filter.outputs.buildfiles == 'true'
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $ACCOUNT --password-stdin
docker build -t ghcr.io/${ACCOUNT}/${REPOSITORY} .
docker push ghcr.io/${ACCOUNT}/${REPOSITORY}
# ----------- TESTS ----------- #
unit-test:
runs-on: ubuntu-latest
needs: [build]
container:
image: ghcr.io/mapattacker/github-workflow-sample
credentials:
username: $ACCOUNT
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: run tests
run: pytest --cov=project/ tests/unit_tests/ -v
# ----------- SECURITY SCANS ----------- #
secrets-scan:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: run secrets scan
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
sast-scan:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v3
- name: run sast scan
uses: AppThreat/sast-scan-action@master
with:
output: reports
type: python
dependency-scan:
runs-on: ubuntu-latest
needs: [build]
container:
image: ghcr.io/mapattacker/github-workflow-sample
credentials:
username: $ACCOUNT
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: run dependency scan
run: safety check
license-scan:
runs-on: ubuntu-latest
needs: [build]
container:
image: ghcr.io/mapattacker/github-workflow-sample
credentials:
username: $ACCOUNT
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: generate consolidated requirements
run: pip freeze > requirements-all.txt
- name: run license scan
id: license_check_report
uses: pilosus/action-pip-license-checker@v2
with:
requirements: 'requirements-all.txt'
fail: 'StrongCopyleft,NetworkCopyleft,Other,Error'
- name: Print report
if: ${{ always() }}
run: echo "${{ steps.license_check_report.outputs.report }}"