Skip to content

Commit 4fc1450

Browse files
author
gabrielsouza80
committed
feat: Add CI pipeline for automated testing and Allure report generation
1 parent e591647 commit 4fc1450

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed

.github/workflows/allure-pages.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: CI Tests + Allure Pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
issues: write
12+
pull-requests: write
13+
14+
concurrency:
15+
group: allure-pages-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
test-and-publish:
20+
runs-on: windows-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Java 21
27+
uses: actions/setup-java@v4
28+
with:
29+
distribution: temurin
30+
java-version: '21'
31+
cache: maven
32+
33+
- name: Checkout gh-pages (history source)
34+
uses: actions/checkout@v4
35+
continue-on-error: true
36+
with:
37+
ref: gh-pages
38+
path: gh-pages
39+
40+
- name: Run tests
41+
shell: pwsh
42+
run: mvn -B clean test -Dheadless=true
43+
44+
- name: Restore Allure history from gh-pages
45+
shell: pwsh
46+
run: |
47+
if (Test-Path "gh-pages/history") {
48+
New-Item -ItemType Directory -Path "target/allure-results/history" -Force | Out-Null
49+
Copy-Item "gh-pages/history/*" "target/allure-results/history/" -Recurse -Force
50+
Write-Host "Allure history restored from gh-pages."
51+
}
52+
else {
53+
Write-Host "No previous gh-pages history found."
54+
}
55+
56+
- name: Regenerate Allure report with history
57+
shell: pwsh
58+
run: mvn -B allure:report
59+
60+
- name: Install Allure CLI (for single-file)
61+
shell: pwsh
62+
run: |
63+
$version = "2.30.0"
64+
$zipFile = "allure-$version.zip"
65+
$url = "https://github.com/allure-framework/allure2/releases/download/$version/$zipFile"
66+
Invoke-WebRequest -Uri $url -OutFile $zipFile
67+
Expand-Archive -Path $zipFile -DestinationPath . -Force
68+
$allureBin = "$PWD\allure-$version\bin\allure.bat"
69+
"ALLURE_BIN=$allureBin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
70+
71+
- name: Generate single-file report
72+
shell: pwsh
73+
run: |
74+
try {
75+
& "$env:ALLURE_BIN" generate target/allure-results --clean --single-file -o target/reports/allure-single-file
76+
New-Item -ItemType Directory -Path "target/reports/allure-report/single-file" -Force | Out-Null
77+
Copy-Item "target/reports/allure-single-file/index.html" "target/reports/allure-report/single-file/index.html" -Force
78+
Write-Host "Single-file report generated successfully."
79+
}
80+
catch {
81+
Write-Host "Single-file generation failed. Keeping standard Allure report only."
82+
}
83+
84+
- name: Upload Allure report artifact
85+
if: always()
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: allure-report
89+
path: target/reports/allure-report
90+
if-no-files-found: warn
91+
92+
- name: Upload single-file artifact
93+
if: always()
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: allure-single-file
97+
path: target/reports/allure-report/single-file/index.html
98+
if-no-files-found: warn
99+
100+
- name: Deploy Allure report to GitHub Pages (gh-pages)
101+
if: github.event_name != 'pull_request'
102+
uses: peaceiris/actions-gh-pages@v4
103+
with:
104+
github_token: ${{ secrets.GITHUB_TOKEN }}
105+
publish_branch: gh-pages
106+
publish_dir: target/reports/allure-report
107+
enable_jekyll: false
108+
109+
- name: Comment PR with Allure links
110+
if: github.event_name == 'pull_request'
111+
uses: actions/github-script@v7
112+
with:
113+
script: |
114+
const marker = '<!-- allure-report-comment -->';
115+
const owner = context.repo.owner;
116+
const repo = context.repo.repo;
117+
const prNumber = context.payload.pull_request.number;
118+
119+
const pagesUrl = `https://${owner}.github.io/${repo}/`;
120+
const singleFileUrl = `${pagesUrl}single-file/index.html`;
121+
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`;
122+
123+
const body = `${marker}
124+
## 📊 Allure Report
125+
126+
- 🌐 Online (última execução publicada em main): ${pagesUrl}
127+
- 📄 Single-file (última execução publicada em main): ${singleFileUrl}
128+
- 🧪 Artefatos desta execução do PR: ${runUrl}
129+
130+
> Nota: para PR, o deploy em GitHub Pages não é executado. O link online reflete a última publicação da branch main.`;
131+
132+
const { data: comments } = await github.rest.issues.listComments({
133+
owner,
134+
repo,
135+
issue_number: prNumber,
136+
per_page: 100,
137+
});
138+
139+
const existing = comments.find(comment =>
140+
comment.user?.type === 'Bot' && comment.body?.includes(marker)
141+
);
142+
143+
if (existing) {
144+
await github.rest.issues.updateComment({
145+
owner,
146+
repo,
147+
comment_id: existing.id,
148+
body,
149+
});
150+
} else {
151+
await github.rest.issues.createComment({
152+
owner,
153+
repo,
154+
issue_number: prNumber,
155+
body,
156+
});
157+
}

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,43 @@ Gerar e abrir relatório Allure local:
114114
mvn allure:serve
115115
```
116116

117+
## Pipeline e relatório online (GitHub Pages)
118+
119+
Este repositório possui pipeline em [.github/workflows/allure-pages.yml](.github/workflows/allure-pages.yml) para:
120+
121+
- Executar testes automaticamente no GitHub Actions
122+
- Gerar Allure report com histórico (Trend entre execuções)
123+
- Publicar relatório online na branch `gh-pages`
124+
- Gerar versão `single-file` do Allure e anexar como artifact
125+
- Comentar automaticamente no PR com links do relatório e artefatos da execução
126+
127+
URL do relatório online (após primeira execução da pipeline):
128+
129+
```text
130+
https://<seu-usuario>.github.io/<seu-repositorio>/
131+
```
132+
133+
Exemplo para este projeto:
134+
135+
```text
136+
https://gabrielsouza80.github.io/playwright-java-saucedemo/
137+
```
138+
139+
Arquivo single-file publicado:
140+
141+
```text
142+
https://gabrielsouza80.github.io/playwright-java-saucedemo/single-file/index.html
143+
```
144+
145+
### Como habilitar no GitHub
146+
147+
1. Faça push do repositório com o workflow.
148+
2. Vá em **Settings > Pages**.
149+
3. Em **Build and deployment**, selecione **Deploy from a branch**.
150+
4. Escolha a branch **gh-pages** e a pasta **/(root)**.
151+
152+
> Dica: em repositórios novos, a branch `gh-pages` é criada automaticamente após a primeira execução bem-sucedida do workflow.
153+
117154
## Convenções de testes
118155

119156
- Casos identificados por `TCxx` no `@DisplayName`
@@ -125,4 +162,5 @@ mvn allure:serve
125162

126163
- Falha por configuração ausente: valide `config.properties` e nomes das chaves
127164
- Allure em branco ao abrir HTML direto: prefira `mvn allure:serve`
165+
- Widget `Categories` vazio: esperado quando não existem testes `failed`/`broken` (suíte 100% verde)
128166
- Erros visuais no VS Code após refactor: reinicie o Java Language Server

0 commit comments

Comments
 (0)