-
Notifications
You must be signed in to change notification settings - Fork 1
257 lines (220 loc) · 6.8 KB
/
Copy pathci.yml
File metadata and controls
257 lines (220 loc) · 6.8 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
name: CI - Build & Test
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
jobs:
detect-and-build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
fail-fast: false
steps:
- name: Checkout código
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
if: hashFiles('**/package.json') != ''
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
if: hashFiles('**/requirements.txt', '**/pyproject.toml', '**/setup.py') != ''
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
if: hashFiles('**/*.csproj', '**/*.sln') != ''
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
if: hashFiles('**/pom.xml', '**/build.gradle') != ''
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
if: hashFiles('**/go.mod') != ''
# NODE.JS / JAVASCRIPT / TYPESCRIPT
- name: Instalar dependências Node.js
if: hashFiles('**/package.json') != ''
run: |
if [ -f "package-lock.json" ]; then
npm ci
elif [ -f "yarn.lock" ]; then
npm install -g yarn
yarn install --frozen-lockfile
elif [ -f "pnpm-lock.yaml" ]; then
npm install -g pnpm
pnpm install --frozen-lockfile
else
npm install
fi
- name: Lint Node.js
if: hashFiles('**/package.json') != ''
continue-on-error: true
run: |
if grep -q "\"lint\"" package.json; then
npm run lint
fi
- name: Build Node.js/Frontend
if: hashFiles('**/package.json') != ''
run: |
if grep -q "\"build\"" package.json; then
npm run build
fi
- name: Testes Node.js
if: hashFiles('**/package.json') != ''
continue-on-error: true
run: |
if grep -q "\"test\"" package.json; then
npm test
fi
# PYTHON
- name: Instalar dependências Python
if: hashFiles('**/requirements.txt', '**/pyproject.toml', '**/setup.py') != ''
run: |
python -m pip install --upgrade pip
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
fi
if [ -f "requirements-dev.txt" ]; then
pip install -r requirements-dev.txt
fi
if [ -f "pyproject.toml" ]; then
pip install -e .
fi
- name: Lint Python
if: hashFiles('**/requirements.txt', '**/pyproject.toml', '**/setup.py') != ''
continue-on-error: true
run: |
if python -c "import flake8" 2>/dev/null; then
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
fi
- name: Testes Python
if: hashFiles('**/requirements.txt', '**/pyproject.toml', '**/setup.py') != ''
continue-on-error: true
run: |
if python -c "import pytest" 2>/dev/null; then
pytest
elif python -c "import unittest" 2>/dev/null; then
python -m unittest discover
fi
# .NET
- name: Restaurar dependências .NET
if: hashFiles('**/*.csproj', '**/*.sln') != ''
run: dotnet restore
- name: Build .NET
if: hashFiles('**/*.csproj', '**/*.sln') != ''
run: dotnet build --configuration Release --no-restore
- name: Testes .NET
if: hashFiles('**/*.csproj', '**/*.sln') != ''
continue-on-error: true
run: dotnet test --configuration Release --no-build --verbosity normal
# JAVA
- name: Build Maven
if: hashFiles('**/pom.xml') != ''
run: mvn clean install -DskipTests
- name: Testes Maven
if: hashFiles('**/pom.xml') != ''
continue-on-error: true
run: mvn test
- name: Build Gradle
if: hashFiles('**/build.gradle') != ''
run: |
if [ -f "gradlew" ]; then
chmod +x gradlew
./gradlew build -x test
else
gradle build -x test
fi
- name: Testes Gradle
if: hashFiles('**/build.gradle') != ''
continue-on-error: true
run: |
if [ -f "gradlew" ]; then
./gradlew test
else
gradle test
fi
# GO
- name: Build Go
if: hashFiles('**/go.mod') != ''
run: go build -v ./...
- name: Testes Go
if: hashFiles('**/go.mod') != ''
continue-on-error: true
run: go test -v ./...
# DOCKER (se existir Dockerfile)
- name: Build Docker Image
if: hashFiles('**/Dockerfile') != ''
run: |
docker build -t app:${{ github.sha }} .
- name: Upload artefatos
uses: actions/upload-artifact@v4
if: always()
continue-on-error: true
with:
name: build-artifacts-${{ matrix.node-version }}
path: |
dist/
build/
target/
out/
bin/
retention-days: 5
security-scan:
runs-on: ubuntu-latest
needs: detect-and-build
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Executar Trivy security scanner
uses: aquasecurity/trivy-action@master
continue-on-error: true
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy results
uses: github/codeql-action/upload-sarif@v3
continue-on-error: true
with:
sarif_file: 'trivy-results.sarif'
code-quality:
runs-on: ubuntu-latest
needs: detect-and-build
steps:
- name: Checkout código
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
notify:
runs-on: ubuntu-latest
needs: [detect-and-build, security-scan, code-quality]
if: always()
steps:
- name: Status da pipeline
run: |
echo "Pipeline concluída!"
echo "Status: ${{ needs.detect-and-build.result }}"