This repository was archived by the owner on Oct 27, 2025. It is now read-only.
Repository navigation
206 lines (196 loc) · 7.64 KB
/
Copy pathtests.yaml
File metadata and controls
206 lines (196 loc) · 7.64 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
name: "Tests"
on:
workflow_call:
secrets:
TERRAFORM_AWS_ACCESS_KEY_ID:
required: false
description: "AWS access key id"
TERRAFORM_AWS_SECRET_ACCESS_KEY:
required: false
description: "AWS secret access key"
jobs:
terraform:
runs-on: ubuntu-latest
# Allow crash due to fork policy
continue-on-error: true
# Only if branch is main or release or a branch in the origin repo
if: |
github.event_name == 'release' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == '42atomys/stud42')
env:
# Compare the changes when plan with production
TF_WORKSPACE: "production"
AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
# TF VARS (bind to production to display changes between branch and production)
# Compare the changes when plan with production
TF_VAR_namespace: "production"
TF_ENV_appsVersion: '{"s42": "${{ inputs.imageTag }}"}'
TF_VAR_baseUrl: "s42.app"
TF_VAR_webhooksEnabled: "true"
TF_VAR_crawlerEnabled: "true"
TF_VAR_hasPersistentStorage: "true"
strategy:
matrix:
stack: ["pre-cluster", "cluster", "apps"]
defaults:
run:
working-directory: "deploy/stacks/${{ matrix.stack }}"
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup kube config
env:
KUBECONFIG_ADMIN: ${{ secrets.KUBECONFIG_ADMIN }}
run: mkdir -p ~/.kube && echo "$KUBECONFIG_ADMIN" >> ~/.kube/config
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
# Force the version due to crash on latest
# https://github.com/hashicorp/terraform/issues/32200
terraform_version: "1.3.3"
- name: Terraform Init
id: init
run: terraform init -input=false
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
id: plan
run: terraform plan -no-color -input=false -out=${{ matrix.stack }}-tfplan
- name: Store terraform plan as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.stack }}-tfplan
path: deploy/stacks/${{ matrix.stack }}/${{ matrix.stack }}-tfplan
retention-days: 7
# On pull request, build or change infrastructure according
# to Terraform configuration files
- uses: actions/github-script@v7
if: always() && github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform data for \`${{ matrix.stack }}\` stack')
})
// 2. Prepare format of the comment
const output = `## Terraform data for \`${{ matrix.stack }}\` stack
#### Terraform Initialization ⚙️ \`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖 \`${{ steps.validate.outcome }}\`
<details><summary>Show Validation</summary>
\`\`\`
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖 \`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`
${{ steps.plan.outputs.stdout }}
\`\`\`
</details>`
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
backend:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: "1.23"
check-latest: true
- name: Install Task
uses: arduino/setup-task@v2
- name: Generate code
run: task generate
- name: Run Unit tests
run: |
go test ./... -coverprofile coverage.out -covermode count
go tool cover -func coverage.out
- name: Quality Gate - Test coverage shall be above threshold
# continue-on-error to allow job to pass without tests.
# @see issue #57 on Github
continue-on-error: true
env:
TESTCOVERAGE_THRESHOLD: 80
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi
- name: Run Go Build
run: |
go build -o /tmp/applications-test-units
frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: "web/ui"
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Cache node_modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Generate code
run: yarn generate
- name: Jest
run: yarn test:ci
- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 70
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`cat coverage/coverage-summary.json | jq '.total.statements.pct'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi