Deploy/nicolas #122
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |