-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
214 lines (181 loc) · 6.89 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
stages:
- build
- validate
- tasks
build-master:
stage: build
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- echo "Creating env file"
- ./scripts/set_env.sh
- docker build --pull -t "$CI_REGISTRY_IMAGE" .
- docker push "$CI_REGISTRY_IMAGE"
# only:
# - master
build-release:
stage: build
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- echo "Creating env file"
- ./scripts/set_env.sh
- docker build --pull -t "$CI_REGISTRY_IMAGE" .
- docker push "$CI_REGISTRY_IMAGE"
- export TAG_IMAGE=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-`date +%Y%m%d-%H%M`
- docker tag "$CI_REGISTRY_IMAGE" $TAG_IMAGE
- docker push $TAG_IMAGE
only:
- release
run-validate:
image: $CI_REGISTRY_IMAGE:latest
stage: validate
before_script:
- apk add --no-cache --update git openssh-client rsync sshpass unzip
- eval $(ssh-agent -s)
- echo "$CONFIG_REPO_SSHKEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email $XERO_REPORT_REPO_USERMAIL
- git config --global user.name $XERO_REPORT_REPO_USERNAME
script:
# Pull configuration repo
- echo "Pulling configration repo"
- pwd
- git clone $CONFIG_REPO
- cp -Rf $CONFIG_REPO_NAME/variables /app
- cp -f $CONFIG_REPO_NAME/variables/.employees.json /app
- cp -f $CONFIG_REPO_NAME/variables/.NSW_holidays.json /app
- ls -la /app
- source /app/variables/email_sender.env
- export GITLAB_PRIVATE_TOKEN=$GITLAB_PRIVATE_TOKEN && export CI_PROJECT_ID=$CI_PROJECT_ID
- python3 /app/xero_report.py validate --client-id=$CLIENT_ID --client-secret=$CLIENT_SECRET --refresh-token=$REFRESH_TOKEN --tenant-id=$TENANT_ID
run-report-monthly:
image: $CI_REGISTRY_IMAGE:latest
stage: tasks
before_script:
- apk add --no-cache --update openssh-client git unzip sshpass rsync
- eval $(ssh-agent -s)
# Adding ssh keys is done in script
# - echo "$XERO_REPORT_REPO_SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
# - echo "$CONFIG_REPO_SSHKEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email $XERO_REPORT_REPO_USERMAIL
- git config --global user.name $XERO_REPORT_REPO_USERNAME
script:
# Pull configuration repo
- echo "$CONFIG_REPO_SSHKEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "Pulling configration repo"
- git clone $CONFIG_REPO
- cp -Rf $CONFIG_REPO_NAME/variables /app
- source /app/variables/email_sender.env
# Delete the first identity
- ssh-add -D
- export GITLAB_PRIVATE_TOKEN=$GITLAB_PRIVATE_TOKEN && export CI_PROJECT_ID=$CI_PROJECT_ID
# Pull report repo
- echo "$XERO_REPORT_REPO_SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "Pulling external repo into build"
- git clone $XERO_REPORT_REPO_ADDRESS
- cd $XERO_REPORT_REPO_NAME
# Create backup data folder
- if [ ! -d reports ];then
- mkdir reports
- fi
# Create folder for this job's report
- TIME=$(date +"%Y-%m-%dT%H:%M:%S%:z")
- mkdir reports/$TIME
# Generate report and json data
- python3 /app/xero_report.py report-month --client-id=$CLIENT_ID --client-secret=$CLIENT_SECRET --refresh-token=$REFRESH_TOKEN --tenant-id=$TENANT_ID
# Push to target repo
- cp -Rf /app/out/* reports/$TIME
- cd reports/$TIME && ls
- git add .
- git commit -m "Uploaded new reports at $TIME"
- git push
rules:
- if: '$CI_RUN_GENERATE_TIMESHEET == "true"'
- when: manual
run-report-po:
image: $CI_REGISTRY_IMAGE:latest
stage: tasks
before_script:
- apk add --no-cache --update openssh-client git unzip sshpass rsync
- eval $(ssh-agent -s)
# Adding ssh keys is done in script
# - echo "$XERO_REPORT_REPO_SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
# - echo "$CONFIG_REPO_SSHKEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email $XERO_REPORT_REPO_USERMAIL
- git config --global user.name $XERO_REPORT_REPO_USERNAME
script:
# Pull configuration repo
- echo "$CONFIG_REPO_SSHKEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "Pulling configration repo"
- git clone $CONFIG_REPO
- cp -Rf $CONFIG_REPO_NAME/variables /app
- source /app/variables/email_sender.env
# Delete the first identity
- ssh-add -D
- export GITLAB_PRIVATE_TOKEN=$GITLAB_PRIVATE_TOKEN && export CI_PROJECT_ID=$CI_PROJECT_ID
# Pull report repo
- echo "$XERO_REPORT_REPO_SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "Pulling external repo into build"
- git clone $XERO_REPORT_REPO_ADDRESS
- cd $XERO_REPORT_REPO_NAME
# Create backup data folder
- if [ ! -d reports ];then
- mkdir reports
- fi
# Create folder for this job's report
- TIME=$(date +"%Y-%m-%dT%H:%M:%S%:z")
- mkdir reports/$TIME
# Generate report and json data
- python3 /app/xero_report.py report-po --client-id=$CLIENT_ID --client-secret=$CLIENT_SECRET --refresh-token=$REFRESH_TOKEN --tenant-id=$TENANT_ID --start-time=$START_TIME --end-time=$END_TIME --po=$PO
# Push to target repo
- cp -Rf /app/out/* reports/$TIME
- cd reports/$TIME && ls
- git add .
- git commit -m "Uploaded new reports at $TIME"
- git push
rules:
- when: manual
run-close:
image: $CI_REGISTRY_IMAGE:latest
stage: tasks
script:
- export GITLAB_PRIVATE_TOKEN=$GITLAB_PRIVATE_TOKEN && export CI_PROJECT_ID=$CI_PROJECT_ID
- python3 /app/xero_report.py close --client-id=$CLIENT_ID --client-secret=$CLIENT_SECRET --refresh-token=$REFRESH_TOKEN --tenant-id=$TENANT_ID
rules:
- if: '$CI_RUN_CLOSE == "true"'
- when: manual
# run-spreadsheet:
# image: $CI_REGISTRY_IMAGE:latest
# stage: tasks
# # only:
# # - schedules
# script:
# # Pull configuration repo
# - echo "$CONFIG_REPO_SSHKEY" | tr -d '\r' | ssh-add - > /dev/null
# - echo "Pulling configration repo"
# - git clone $CONFIG_REPO
# - cp -Rf $CONFIG_REPO_NAME/variables /app
# # Set spreadsheet variables from config repo
# - source /app/variables/spreadsheet.env
# - export GITLAB_PRIVATE_TOKEN=$GITLAB_PRIVATE_TOKEN && export CI_PROJECT_ID=$CI_PROJECT_ID
# - python3 /app/xero_spread_sheet_report.py --client-id=$CLIENT_ID --client-secret=$CLIENT_SECRET --refresh-token=$REFRESH_TOKEN --tenant-id=$TENANT_ID --credential=$GOOGLE_CREDENTIAL --url=$GOOGLE_URL
# rules:
# - when: manual