Add README.md
This commit is contained in:
190
README.md
Normal file
190
README.md
Normal file
@ -0,0 +1,190 @@
|
||||
# Dejo Infra
|
||||
|
||||
> Guia de configuração, desenvolvimento e fluxo de CI/CD com Conventional Commits e Semantic Release no Gitea.
|
||||
|
||||
---
|
||||
|
||||
## 📋 Índice
|
||||
|
||||
- [Pré-requisitos](#-pré-requisitos)
|
||||
- [Clonando o Repositório](#-clonando-o-repositório)
|
||||
- [⚙️ Instalação e Hooks](#-instalação-e-hooks)
|
||||
- [📦 Conventional Commits](#-conventional-commits)
|
||||
- [🚀 Fluxo de CI/CD](#-fluxo-de-cicd)
|
||||
- [📝 Novos Releases](#-novos-releases)
|
||||
- [🛠️ Troubleshooting](#-troubleshooting)
|
||||
- [📜 Licença](#-licença)
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Pré-requisitos
|
||||
|
||||
- Git v2.25+
|
||||
- Node.js v20.x LTS
|
||||
- npm v8+
|
||||
- Acesso ao repositório no Gitea com permissão para _secrets_
|
||||
|
||||
---
|
||||
|
||||
## 🔗 Clonando o Repositório
|
||||
|
||||
```bash
|
||||
git clone https://git.dejodigital.com.br/dejo-infra/iac.git
|
||||
cd iac
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Instalação e Hooks
|
||||
|
||||
> ⚠️ **Atenção:** execute `npm ci --no-audit` antes de qualquer commit. Isso instala as dependências e configura os hooks; sem isso, o hook `commit-msg` não será instalado e seus commits poderão ser bloqueados.
|
||||
|
||||
Instale dependências e configure hooks:
|
||||
|
||||
```bash
|
||||
npm ci --no-audit
|
||||
```
|
||||
|
||||
O script `prepare` (via `package.json`) executa:
|
||||
|
||||
```bash
|
||||
git config core.hooksPath hooks
|
||||
```
|
||||
|
||||
A pasta `hooks/` contém o `commit-msg` que valida as mensagens.
|
||||
|
||||
**Testando o hook:**
|
||||
|
||||
```bash
|
||||
# Deve falhar
|
||||
git commit --allow-empty -m "mensagem inválida"
|
||||
|
||||
# Deve passar
|
||||
git commit --allow-empty -m "feat: testando hook de commit-msg"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📦 Conventional Commits
|
||||
|
||||
Formato obrigatório:
|
||||
|
||||
```text
|
||||
<tipo>(<escopo>): <descrição>
|
||||
```
|
||||
|
||||
**Tipos válidos:**
|
||||
|
||||
- `feat`: Nova funcionalidade
|
||||
- `fix`: Correção de bug
|
||||
- `docs`: Documentação
|
||||
- `style`: Formatação
|
||||
- `refactor`: Refatoração
|
||||
- `test`: Testes
|
||||
- `chore`: Tarefas de build/infra
|
||||
- `ci`: CI/CD
|
||||
- `perf`: Performance
|
||||
- `revert`: Reversão
|
||||
|
||||
**Exemplo:**
|
||||
|
||||
```bash
|
||||
git commit -m "fix(api): corrige timeout na rota /users"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Fluxo de CI/CD
|
||||
|
||||
O workflow está em **`.gitea/workflows/release.yml`**:
|
||||
|
||||
```yaml
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
lint_commits:
|
||||
name: Lint Commits
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Dependencies
|
||||
env:
|
||||
NODE_ENV: development
|
||||
NPM_CONFIG_PRODUCTION: 'false'
|
||||
run: npm ci --no-audit
|
||||
|
||||
- name: Lint Commit Messages
|
||||
run: npx commitlint --from=origin/master --to=HEAD
|
||||
|
||||
release:
|
||||
name: Release
|
||||
needs: lint_commits
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Install Dependencies
|
||||
env:
|
||||
NODE_ENV: development
|
||||
NPM_CONFIG_PRODUCTION: 'false'
|
||||
run: npm ci --no-audit
|
||||
|
||||
- name: Run Semantic Release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_URL: https://git.dejodigital.com.br
|
||||
run: npx semantic-release
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔑 Secrets necessários
|
||||
|
||||
- **GITEA_TOKEN**: token com permissão de `repo:write`
|
||||
- **GITEA_URL**: URL da instância (ex.: `https://git.dejodigital.com.br`)
|
||||
|
||||
---
|
||||
|
||||
## 📝 Novos Releases
|
||||
|
||||
Para criar um novo release, basta:
|
||||
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "feat: adiciona recurso X"
|
||||
git push origin master
|
||||
```
|
||||
|
||||
O CI vai:
|
||||
1. Validar commits
|
||||
2. Gerar versão semântica
|
||||
3. Atualizar `CHANGELOG.md`
|
||||
4. Criar tag `vX.Y.Z`
|
||||
5. Publicar release no Gitea
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Troubleshooting
|
||||
|
||||
- **commitlint não encontrado:** verifique `devDependencies` no `package.json` e se o `commitlint.config.js` está na raiz.
|
||||
- **Erro `addAbortListener`:** use Node.js v20 no workflow.
|
||||
- **Mensagens de audit:** use `--no-audit` ou configure `.npmrc` com `audit=false`.
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user