-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (83 loc) · 3.54 KB
/
cicd.yml
File metadata and controls
114 lines (83 loc) · 3.54 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
name: CI/CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
test-pipeline:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Obter o código (Checkout)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configurar Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Instalar dependências do Backend
run: npm ci
working-directory: ./backend
- name: Rodar Testes Backend e Gerar Cobertura
run: npm run test:coverage
working-directory: ./backend
- name: Instalar dependências do Frontend
run: npm ci
working-directory: ./frontend
- name: Rodar Testes Frontend
run: npm run test:coverage
working-directory: ./frontend
- name: Instalar Qlty CLI
uses: qltysh/qlty-action/install@main
- name: Inicializar Qlty
run: qlty init --no
- name: Rodar Qlty no Backend
run: qlty check --sarif . > ../backend_report.json
working-directory: ./backend
continue-on-error: true
- name: Rodar Qlty no Frontend
run: qlty check --sarif . > ../frontend_report.json
working-directory: ./frontend
continue-on-error: true
- name: Instalar ferramentas auxiliares
run: |
sudo apt-get update
sudo apt-get install gh jq -y
- name: Processar Relatórios e Criar Issues
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPORTS=("backend_report.json:backend" "frontend_report.json:frontend")
for ITEM in "${REPORTS[@]}"; do
REPORT_FILE="${ITEM%%:*}"
FOLDER_PREFIX="${ITEM##*:}"
echo "------------------------------------------------"
echo "Processando relatório: $REPORT_FILE (Contexto: $FOLDER_PREFIX)"
if [ ! -s $REPORT_FILE ]; then
echo "Relatório $REPORT_FILE não encontrado ou vazio. Pulando..."
continue
fi
jq -c '.runs[0].results[]' $REPORT_FILE | while read -r i; do
RULE_ID=$(echo $i | jq -r '.ruleId')
RAW_URI=$(echo $i | jq -r '.locations[0].physicalLocation.artifactLocation.uri')
FILE_URI="$FOLDER_PREFIX/$RAW_URI"
LINE=$(echo $i | jq -r '.locations[0].physicalLocation.region.startLine')
MESSAGE=$(echo $i | jq -r '.message.text' | sed 's/"/\\"/g')
TITLE="[Qlty Smell] $RULE_ID em $FILE_URI"
EXISTING_ISSUES=$(gh issue list --search "$TITLE label:technical-debt is:open" --json number --jq '.[0].number' --repo ${{ github.repository }} || echo "")
if [ -n "$EXISTING_ISSUES" ]; then
echo "Issue duplicada encontrada (#$EXISTING_ISSUES) para: $TITLE. Pulando criação."
else
BODY=$(echo -e "**Detalhes do Débito Técnico ($FOLDER_PREFIX)**\n\n- **Regra:** $RULE_ID\n- **Arquivo:** \`$FILE_URI\`\n- **Linha:** $LINE\n\n---\n**Mensagem do Qlty:**\n$MESSAGE\n\n\nCriado automaticamente pelo pipeline de CI.")
gh issue create --title "$TITLE" --body "$BODY" --label "technical-debt" --repo ${{ github.repository }}
echo "Issue criada para: $TITLE"
fi
done
done