Skip to content

Commit

Permalink
cleanup (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrybyk authored Feb 1, 2024
1 parent 6ebbb0e commit 3dabee1
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/report_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
gh_pages: 'gh-pages-dir'
report_dir: 'allure-results'
list_dirs: ${{ github.ref == 'refs/heads/main' }}
cleanup_enabled: true
max_reports: 5

- name: Git Commit and Push Action
uses: mgrybyk/git-commit-pull-push-action@v1
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM timbru31/java-node:17-alpine-jre-20

ARG RELEASE=2.26.0
ARG RELEASE=2.27.0
ARG ALLURE_REPO=https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline

RUN echo "===============" && \
echo Allure: $RELEASE && \
echo NodeJS: $(node --version) && \
java -version && \
echo "===============" && \
apk update && apk add git && \
wget --no-verbose -O /tmp/allure-$RELEASE.tgz $ALLURE_REPO/$RELEASE/allure-commandline-$RELEASE.tgz && \
tar -xf /tmp/allure-$RELEASE.tgz && \
rm -rf /tmp/* && \
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Allure Report with history per branch (type: `docker`)
See examples:

- [Allure History List](https://mgrybyk.github.io/allure-report-branch-action/allure-action/main/self-test/)
- [Allure Report](https://mgrybyk.github.io/allure-report-branch-action/allure-action/main/self-test/5931206129_1692650191550/)
- [Allure Report](https://mgrybyk.github.io/allure-report-branch-action/allure-action/main/self-test/7643572205_1706116100424/)
- [Browse different branches](https://mgrybyk.github.io/allure-report-branch-action/allure-action/)
- [Pull Request Comment Example](https://github.com/mgrybyk/allure-report-branch-action/pull/12)

Expand Down Expand Up @@ -106,13 +106,14 @@ The `allure-report-branch-action` is designed as a JavaScript action wrapped wit
As far as `docker` action runs in linux environments only, it's required to do some extra steps for users running Windows and MacOS workflows. See [Types of actions](https://docs.github.com/en/actions/creating-actions/about-custom-actions#types-of-actions) for more details.

- option 1: using upload/download artifacts. See [simple-elf/allure-report-action/issues/28#issuecomment-1139332329](https://github.com/simple-elf/allure-report-action/issues/28#issuecomment-1139332329)
- option 2: use JS version of this action (raise an issue and I'll publish it). In this case you'll have to install Java and download download allure-commandline yourself.
- option 2: use JS version of this action [mgrybyk/allure-report-branch-js-action](https://github.com/mgrybyk/allure-report-branch-js-action).

## Credits

- [docker-java-node](https://github.com/timbru31/docker-java-node) for building Dockerimage with Java and NodeJS together
- [thollander/actions-comment-pull-request](https://github.com/thollander/actions-comment-pull-request) for building Github Action that comments the linked PRs

## Upcoming features
## Planned features

- cleanup old reports
- cleanup `data.json` file per report. Raise an issue if you're interested!
- think how to deal with branch cleaup without using url. Feel free to pick up.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ inputs:
description: 'Write index.html to the Github Action folders. Might cause concurrency issues!'
required: false
default: false
cleanup_enabled:
description: 'Cleanup reports from deleted branches or if reports numbers is too big'
required: false
default: false
max_reports:
description: 'Max reports to keep per branch/report. Make sure to enable cleanup_enabled'
required: false
default: 100
outputs:
report_url:
description: 'Published Allure Report url'
Expand Down
269 changes: 202 additions & 67 deletions dist/index.js

Large diffs are not rendered by default.

32 changes: 22 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'path'
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as io from '@actions/io'
Expand All @@ -14,6 +15,7 @@ import {
} from './src/allure.js'
import { getBranchName } from './src/helpers.js'
import { isFileExist } from './src/isFileExists.js'
import { cleanupOutdatedBranches, cleanupOutdatedReports } from './src/cleanup.js'

const baseDir = 'allure-action'

Expand All @@ -25,22 +27,25 @@ try {
const ghPagesPath = core.getInput('gh_pages')
const reportId = core.getInput('report_id')
const listDirs = core.getInput('list_dirs') == 'true'
const cleanupEnabled = core.getInput('cleanup_enabled') == 'true'
const maxReports = parseInt(core.getInput('max_reports'), 10)
const branchName = getBranchName(github.context.ref, github.context.payload.pull_request)
const reportBaseDir = `${ghPagesPath}/${baseDir}/${branchName}/${reportId}`
const ghPagesBaseDir = path.join(ghPagesPath, baseDir)
const reportBaseDir = path.join(ghPagesBaseDir, branchName, reportId)

/**
* `runId` is unique but won't change on job re-run
* `runNumber` is not unique and resets from time to time
* that's why the `runTimestamp` is used to guarantee uniqueness
*/
const runUniqueId = `${github.context.runId}_${runTimestamp}`
const reportDir = `${reportBaseDir}/${runUniqueId}`
const reportDir = path.join(reportBaseDir, runUniqueId)

// urls
const githubActionRunUrl = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
const ghPagesUrl = `https://${github.context.repo.owner}.github.io/${github.context.repo.repo}`
const ghPagesBaseDir = `${ghPagesUrl}/${baseDir}/${branchName}/${reportId}`.replaceAll(' ', '%20')
const ghPagesReportDir = `${ghPagesBaseDir}/${runUniqueId}`.replaceAll(' ', '%20')
const ghPagesBaseUrl = `${ghPagesUrl}/${baseDir}/${branchName}/${reportId}`.replaceAll(' ', '%20')
const ghPagesReportUrl = `${ghPagesBaseUrl}/${runUniqueId}`.replaceAll(' ', '%20')

// log
console.log({
Expand All @@ -53,8 +58,10 @@ try {
branchName,
reportBaseDir,
reportDir,
report_url: ghPagesReportDir,
report_url: ghPagesReportUrl,
listDirs,
cleanupEnabled,
maxReports,
})

if (!(await isFileExist(ghPagesPath))) {
Expand All @@ -74,33 +81,38 @@ try {
await writeFolderListing(ghPagesPath, '.')
}
await writeFolderListing(ghPagesPath, baseDir)
await writeFolderListing(ghPagesPath, `${baseDir}/${branchName}`)
await writeFolderListing(ghPagesPath, path.join(baseDir, branchName))
}

// process allure report
const lastRunId = await getLastRunId(reportBaseDir)
if (lastRunId) {
await io.cp(`${reportBaseDir}/${lastRunId}/history`, sourceReportDir, { recursive: true })
await io.cp(path.join(reportBaseDir, lastRunId, 'history'), sourceReportDir, { recursive: true })
}
await writeExecutorJson(sourceReportDir, {
runUniqueId,
buildOrder: github.context.runId,
buildUrl: githubActionRunUrl,
reportUrl: ghPagesReportDir,
reportUrl: ghPagesReportUrl,
})
await spawnAllure(sourceReportDir, reportDir)
const results = await updateDataJson(reportBaseDir, reportDir, github.context.runId, runUniqueId)
await writeAllureListing(reportBaseDir)
await writeLastRunId(reportBaseDir, github.context.runId, runTimestamp)

// outputs
core.setOutput('report_url', ghPagesReportDir)
core.setOutput('report_history_url', ghPagesBaseDir)
core.setOutput('report_url', ghPagesReportUrl)
core.setOutput('report_history_url', ghPagesBaseUrl)
core.setOutput('test_result', results.testResult)
core.setOutput('test_result_icon', getTestResultIcon(results.testResult))
core.setOutput('test_result_passed', results.passed)
core.setOutput('test_result_failed', results.failed)
core.setOutput('test_result_total', results.total)

if (cleanupEnabled) {
await cleanupOutdatedBranches(ghPagesBaseDir, github.context.repo)
await cleanupOutdatedReports(ghPagesBaseDir, maxReports)
}
} catch (error) {
core.setFailed(error.message)
}
101 changes: 60 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3dabee1

Please sign in to comment.