This repository was archived by the owner on Apr 5, 2023. It is now read-only.
Repository navigation
281 lines (246 loc) · 9.35 KB
/
Copy pathci.yml
File metadata and controls
281 lines (246 loc) · 9.35 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: CI/CD Workflow
on:
workflow_dispatch:
push:
branches:
- '**'
# pull_request:
# types:
# - closed
jobs:
run_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: ponicode/azure-devops-npm-action@master
with:
organisation: precise-finance
project: precise-finance
registry: precise-npm
user: danshapir
password: ${{ secrets.AZURE_PAT }}
email: dan@precisefinance.ai
# scope: ponicode
- run: cp `pwd`/.npmrc ~ # We need the .npmrc file in the $HOME directory
- name: Setup Node.js
uses: actions/setup-node@v4.0.0
with:
node-version: '18' # Adjust as necessary
- name: Cache node_modules
id: cache-node-modules # Added an ID for this step
uses: actions/cache@v3
with:
path: node_modules # caching node_modules directly
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true' # Only run if cache was a miss
run: npm ci
- name: Run tests
run: |
npx prisma generate
npm run test:ci
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: JEST Tests # Name of the check run which will be created
path: reports/jest-*.xml # Path to test results
reporter: jest-junit # Format of test results
build_image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Checkout Helm repo
uses: actions/checkout@v4
with:
repository: Precise-Finance/charts
path: helm-repo
ref: main
token: ${{ secrets.GH_SECRET }}
- name: Install yq
run: |
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.12.2/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Get current image tag
id: get_current_tag
run: |
CURRENT_TAG=$(yq eval ".image.tag" helm-repo/${{ github.event.repository.name }}/values.yaml)
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
- name: Check if tag needs update
id: check_tag
run: |
if [[ "${{ steps.get_current_tag.outputs.current_tag }}" == "$GITHUB_SHA" ]]; then
echo "Image tag is already up-to-date. Skipping."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Azure npm auth
if: steps.check_tag.outputs.skip == 'false'
uses: ponicode/azure-devops-npm-action@master
with:
organisation: precise-finance
project: precise-finance
registry: precise-npm
user: danshapir
password: ${{ secrets.AZURE_PAT }}
email: dan@precisefinance.ai
# scope: ponicode
- run: cp `pwd`/.npmrc ~ # We need the .npmrc file in the $HOME directory
- name: Setup Node.js
if: steps.check_tag.outputs.skip == 'false'
uses: actions/setup-node@v4.0.0
with:
node-version: '18' # Adjust as necessary
- name: Configure AWS credentials
if: steps.check_tag.outputs.skip == 'false'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Login to Amazon ECR Private
if: steps.check_tag.outputs.skip == 'false'
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
if: steps.check_tag.outputs.skip == 'false'
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
if: steps.check_tag.outputs.skip == 'false'
uses: actions/cache@v3.3.2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile', '**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-buildx-${{ hashFiles('**/package-lock.json') }}
${{ runner.os }}-buildx-
- name: Build, tag, and push docker image to Amazon ECR using Buildx
if: steps.check_tag.outputs.skip == 'false'
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: precise/${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker buildx create --use
docker buildx build --push \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
- name: Update values.yaml
if: steps.check_tag.outputs.skip == 'false'
run: |
yq eval ".image.tag = \"$(echo $GITHUB_SHA )\"" -i helm-repo/${{ github.event.repository.name }}/values.yaml
cat helm-repo/${{ github.event.repository.name }}/values.yaml
- name: Set up Git
if: steps.check_tag.outputs.skip == 'false'
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
- name: Commit and Push Changes
if: steps.check_tag.outputs.skip == 'false'
run: |
cd helm-repo
git add .
git commit -m "Update image tag after commit"
git push
- name: Generate File
run: |
cd helm-repo
echo $(git rev-parse HEAD) > ../helm_commit.txt
- name: Upload artifact
uses: actions/upload-artifact@v3.1.3
with:
name: helm-commit
path: helm_commit.txt
approval_and_tag_dev:
needs: [run_tests, build_image] # Change the dependency to the newly separated jobs
if: contains(github.ref, 'refs/pull/') || startsWith(github.ref, 'refs/heads/feature/')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v3.0.2
with:
name: helm-commit
path: helm-commit
- name: Set output
id: get_commit_id
run: |
echo $(cat helm-commit/helm_commit.txt)
echo "commit_id=$(cat helm-commit/helm_commit.txt)" >> $GITHUB_OUTPUT
- name: Get Commit Details
id: get_commit_details
run: |
echo $(git log -1 --pretty=format:'%s')
echo "commit_message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT
- name: Get PR Details
id: get_pr_details
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "pr_link=${{ github.event.pull_request.html_url }}" >> $GITHUB_OUTPUT
else
echo "Not a PR event, skipping PR details extraction."
fi
- name: send approval
uses: Precise-Finance/slack-approval@v2.8
env:
SLACK_APP_TOKEN: ${{ secrets.SLACK_APP_TOKEN }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }}
SLACK_CHANNEL_ID: deployment-approvals-dev #${{ secrets.SLACK_CHANNEL_ID }}
DEPLOYMENT_ENV: DEV
COMMIT_SHA: ${{ steps.get_commit_id.outputs.commit_id }}
GH_SECRET: ${{ secrets.GH_SECRET }}
PR_LINK: ${{ steps.get_pr_details.outputs.pr_link }}
COMMIT_MESSAGE: ${{ steps.get_commit_details.outputs.commit_message }}
timeout-minutes: 10
approval_and_tag_prod:
needs: [run_tests, build_image] # Change the dependency to the newly separated jobs
if: (github.ref == 'refs/heads/main') || (github.ref == 'refs/heads/master')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v3.0.2
with:
name: helm-commit
path: helm-commit
- name: Set output
id: get_commit_id
run: |
echo $(cat helm-commit/helm_commit.txt)
echo "commit_id=$(cat helm-commit/helm_commit.txt)" >> $GITHUB_OUTPUT
- name: Get Commit Details
id: get_commit_details
run: |
echo $(git log -1 --pretty=format:'%s')
echo "commit_message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT
- name: Get PR Details
id: get_pr_details
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "pr_link=${{ github.event.pull_request.html_url }}" >> $GITHUB_OUTPUT
else
echo "Not a PR event, skipping PR details extraction."
fi
- name: send approval
uses: Precise-Finance/slack-approval@v2.8
env:
SLACK_APP_TOKEN: ${{ secrets.SLACK_APP_TOKEN }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }}
SLACK_CHANNEL_ID: deployment-approvals #${{ secrets.SLACK_CHANNEL_ID }}
DEPLOYMENT_ENV: Production
COMMIT_SHA: ${{ steps.get_commit_id.outputs.commit_id }}
GH_SECRET: ${{ secrets.GH_SECRET }}
PR_LINK: ${{ steps.get_pr_details.outputs.pr_link }}
COMMIT_MESSAGE: ${{ steps.get_commit_details.outputs.commit_message }}
timeout-minutes: 10