|
| 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 | + } |
0 commit comments