-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
182 lines (146 loc) · 4.55 KB
/
.gitlab-ci.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
############################# Helper Anchors ##################################
.use_github_repo: &use_github_repo |
eval $(ssh-agent -s)
ssh-add ~/.ssh/${GITHUB_HOST}
ORIGIN="git@${GITHUB_HOST}:${GITHUB_NAME}/${CI_PROJECT_NAME}.git"
git config --global user.name ${GITHUB_NAME}
git config --global user.email ${GITHUB_EMAIL}
git remote rm origin
git remote add origin ${ORIGIN}
.use_gitlab_repo: &use_gitlab_repo |
eval $(ssh-agent -s)
ssh-add ~/.ssh/${GITLAB_HOST}
ORIGIN="git@${GITLAB_HOST}:${GITLAB_NAME}/${CI_PROJECT_NAME}.git"
git config --global user.name ${GITLAB_NAME}
git config --global user.email ${GITLAB_EMAIL}
git remote rm origin
git remote add origin ${ORIGIN}
################################# Set Up ######################################
variables:
GIT_STRATEGY: clone
GITLAB_NAME: "chuck"
GITLAB_EMAIL: "chuck@gitlab.mothership"
GITLAB_HOST: "gitlab.mothership"
GITHUB_NAME: "chuckorde"
GITHUB_EMAIL: "chuckorde@gmail.com"
GITHUB_HOST: "github.com"
before_script:
- apt-get update -yqq
- apt-get -qy install ssh git curl zip > /dev/null
- umask 077
- mkdir -p ~/.ssh
- echo "${GITLAB_SSH_PRIVATE_KEY}" > ~/.ssh/${GITLAB_HOST}
- ssh-keyscan -H ${GITLAB_HOST} > ~/.ssh/known_hosts
- echo "${GITHUB_SSH_PRIVATE_KEY}" > ~/.ssh/${GITHUB_HOST}
- ssh-keyscan -H ${GITHUB_HOST} >> ~/.ssh/known_hosts
stages:
- test
- package
- publish
############################ Branchs Dev / Master ############################
Unit Test:
stage: test
tags:
- python
script:
- pip3 install -e .
- python3 tests.py
only:
- dev
- master
SCA Test: # run SCA on any branch
stage: test
tags:
- python
script:
- curl -sSL https://download.sourceclear.com/ci.sh | bash
only:
- dev
- master
# SAST Sandbox Test: # this only runs on the dev branch, so run a Sandbox scan
# stage: test
#
# tags:
# - python
#
# script:
# - zip project.zip
# setup.* LICENSE.txt -r $(echo ${CI_PROJECT_NAME} | cut -d'-' -f1)
# - pip3 install veracode-python
#
# - veracode app scan
# --app="${CI_PROJECT_NAME}"
# --name="$(date) - ${CI_COMMIT_SHORT_SHA}"
# --sandbox='Development Build'
# --files='project.zip'
# --timeout=30
#
only:
- dev
############################## Master Only ####################################
# SAST Policy Test: # this is on master so run a SAST policy scan
# stage: test
#
# tags:
# - python
#
# script:
# - zip project.zip
# setup.* LICENSE.txt -r $(echo ${CI_PROJECT_NAME} | cut -d'-' -f1)
# - pip3 install veracode-python
#
# - veracode app scan
# --app="${CI_PROJECT_NAME}"
# --name="$(date) - ${CI_COMMIT_SHORT_SHA}"
# --files='project.zip'
# --timeout=30
#
# only:
# - master
Create Release: # increment version and create release tag
stage: package
tags:
- python
script:
- *use_gitlab_repo
- git pull origin master
- git checkout master
- export RELEASE=$(git log -1 --pretty='format:%B' | cut -d':' -f1)
- export VERSION=$(python3 setup.py -q version --increment ${RELEASE})
- echo "Creating ${RELEASE} ${VERSION}"
- git add -u
- git commit -m "Release v${VERSION} [skip ci]"
- git push origin master
- git tag -a v${VERSION} -m "Release ${VERSION}"
- git push origin v${VERSION}
only:
- master
Mirror to Github: # mirror Github and use API to create release
stage: publish
tags:
- python
script:
- *use_gitlab_repo
- git pull origin master
- git checkout master
- echo "Packaging version $(python3 setup.py -q version)"
- *use_github_repo
- git push -u origin master --force
- pip3 install requests # needed for github release
- python3 setup.py github --create-release ${GITHUB_API_TOKEN}
only:
- master
Publish to PyPi: # publish on PyPi
stage: publish
tags:
- python
script:
- *use_gitlab_repo
- git pull origin master
- git checkout master
- rm -rf dist
- pip3 install twine
- python3 setup.py sdist
- twine upload -u ${TWINE_USERNAME} -p ${TWINE_PASSWORD} dist/*
only:
- master