diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fe0dd1f..7010ce4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,6 @@ --- version: 2 updates: - - package-ecosystem: github-actions - directory: /allure-multi - schedule: - interval: weekly - package-ecosystem: github-actions directory: /canary-release schedule: diff --git a/allure-multi/README.md b/allure-multi/README.md deleted file mode 100644 index 19555cd..0000000 --- a/allure-multi/README.md +++ /dev/null @@ -1,42 +0,0 @@ -allure-multi -============ - -Generate multiple allure reports from a third repository, using github actions' builtin Java runtime instead of containers. - -Allows hosting of allure reports in a github pages separate from the tested project. - -How to use ----------- - -1. Configure a repository to upload `allure-results.tar.gz` as an artifact, - containing a tarball of the `allure-results` folder. This is a bunch of json that allure - uses to create its report. The name should be unique per test run, and the path should always be `allure-results.tar.gz`. - -```yaml -- name: Run test - run: | - python -m pip install allure-pytest - pytest --alluredir=allure-results - tar -zcf allure-results.tar.gz allure-results -- name: Upload allure-results - uses: actions/upload-artifact@v2 - with: - name: allure-${{ matrix.python-version }}_${{ matrix.os }} - path: allure-results.tar.gz -``` - -2. Clone https://github.com/dholth/allure-multi-target, as a template. Make sure it has a `gh-pages` branch. Configure github pages to use the `GitHub Actions` source, instead of `Deploy from a branch` - -3. Edit `.github/workflows/build-report.yml` to point to the repository configured in (1). The action will download all artifacts named `allure-*` (or what's specified in the pattern). -Artifacts are grouped into reports based on regular expression matching, or everything after `allure-` by default. - -```yaml -- name: Call allure-multi action - uses: conda/actions/allure-multi@ - with: - repository: your/public-repository - pattern: allure-* - group: allure-(.*) -``` - -> For example, if your tests are split into `allure-osx-1` and `allure-osx-2`, and `allure-linux-1` and `allure-linux-2`, the pattern `allure-(.*)-.*` creates an `osx` report combining `allure-osx-1` and `allure-osx-2`, and a `linux` report combining `allure-linux-1` and `allure-linux-2`. This is especially useful for parallel test runs, where parts of the test suite run on different machines. diff --git a/allure-multi/action.py b/allure-multi/action.py deleted file mode 100644 index 207a091..0000000 --- a/allure-multi/action.py +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env python -""" -Generate a bunch of allure reports. - -Assumes github pages branch is checked out to $PWD/gh-pages. -""" - -import json -import os -from pathlib import Path -import subprocess -import re - -ALLURE = os.environ.get("ALLURE_PATH", "allure") - -# pass in env: section; not automatic from github actions -REPOSITORY = os.environ.get("INPUT_REPOSITORY") -# glob pattern used to download some artifacts -PATTERN = os.environ.get("INPUT_ARTIFACT_PATTERN") -# regex matching the group part of an artifact -GROUP_REGEX = os.environ.get("INPUT_ARTIFACT_GROUP", r"allure-(\d.*)") - -TEMPLATE = """\ - -
-

Test reports

-""" - - -def list_runs(repository): - runs = subprocess.run( - [ - "gh", - "run", - "-R", - repository, - "ls", - "--json", - "status,conclusion,databaseId,workflowName,headBranch", - ], - check=True, - capture_output=True, - ) - return json.loads(runs.stdout) - - -def download_run(repository, run_id, pattern=PATTERN): - """ - Download artifacts for a single run. - """ - assert pattern, "pattern is required" - workdir = Path(run_id) - try: - workdir.mkdir() - except OSError: - print(f"Skip existing {workdir}") - return workdir - result = subprocess.run( - ["gh", "run", "download", "-p", pattern, "-R", repository, run_id], - cwd=workdir, - ) - if result.returncode == 0: - return workdir - else: - # will also fail if workdir is not empty - workdir.rmdir() - print("stdout", result.stdout) - print("stderr", result.stderr) - - -def report_run( - repository: str, - run: dict, - outdir="gh-pages", - pattern: re.Pattern = re.compile(r"(.*)"), -): - workdir = Path(str(run["databaseId"])) - groups = {} - for path in workdir.iterdir(): - if match := pattern.match(path.name): - groupname = match.groups()[0] - groups[groupname] = groups.get(groupname, []) + [path] - - for group in groups: - report_dir = Path(workdir, f"allure-report-{group}") - report_dir.mkdir(exist_ok=True) - # extract related results on top of each other - for artifact_dir in groups[group]: - command = [ - "find", - str(artifact_dir), - "-name", - "allure-results.tar.gz", - "-exec", - "tar", - "-C", - str(report_dir), - "-xf", - "{}", - "--strip-components=1", - ";", # no shell escaping - ] - - subprocess.run( - command, - ) - - output_dir = Path(outdir, run["headBranch"].replace("/", "-"), group) - - try: - (output_dir / "history").rename(report_dir / "history") - except OSError: - print(f"Could not move history from {output_dir} to {report_dir}") - - # allure generate --output input-dir - command = [ - ALLURE, - "generate", - "--clean", - "--output", - str(output_dir), - report_dir, - ] - subprocess.run(command) - - -def index_html(outdir="gh-pages"): - """ - Link to all the reports. - """ - outdir = Path(outdir) - outfile = outdir / "index.html" - indexes = [index.relative_to(outdir) for index in outdir.glob("*/**/index.html")] - - page = TEMPLATE + "\n".join( - (f"""{index}
""" for index in sorted(indexes)) - ) - - outfile.write_text(page) - - -def go(): - repository = REPOSITORY - assert repository, "no repository!" - # group multiple assets together - pattern = re.compile(GROUP_REGEX) - seen = Path("gh-pages", "seen.txt") - seen_ids = set() - if seen.exists(): - seen_ids = set(seen.read_text().splitlines()) - for run in reversed(list_runs(repository)): - if run["status"] != "completed": - continue - if run["databaseId"] in seen_ids: - continue - print(f"Download {run}") - rundir = download_run(repository, str(run["databaseId"])) - if not rundir: - continue - print(f"Report {run}") - report_run(repository, run, pattern=pattern) - index_html() - seen_ids.add(run["databaseId"]) - seen.write_text("\n".join(str(token) for token in seen_ids if token)) - - -if __name__ == "__main__": - go() diff --git a/allure-multi/action.yml b/allure-multi/action.yml deleted file mode 100644 index d3e0a9e..0000000 --- a/allure-multi/action.yml +++ /dev/null @@ -1,67 +0,0 @@ ---- -name: Allure Multi -description: Generate multiple allure reports from artifacts and publish to gh-pages. -author: dholth -branding: - icon: book - color: green - -# from actions/checkout -inputs: - repository: - description: Repository name with owner. For example, actions/checkout - default: ${{ github.repository }} - ref: - description: > - The branch, tag or SHA to checkout. When checking out the repository that - triggered a workflow, this defaults to the reference or SHA for that - event. Otherwise, uses the default branch. - token: - description: > - Personal access token (PAT) used to fetch the repository. The PAT is configured - with the local git config, which enables your scripts to run authenticated git - commands. The post-job step removes the PAT. - We recommend using a service account with the least permissions necessary. - Also when generating a new PAT, select the least scopes necessary. - [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) - default: ${{ github.token }} - pattern: - description: > - Glob pattern to limit artifact downloads. - default: allure-* - group: - description: > - Regex matching common part of multiple-artifacts for a single report. - default: allure-(.*) - -runs: - using: composite - steps: - - uses: actions/setup-java@v4 - with: - # Don't know which Java is the best. - distribution: temurin - java-version: '17' - - - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - - name: Download allure - shell: bash - run: | - cd $RUNNER_TEMP - curl -L -O https://github.com/allure-framework/allure2/releases/download/2.20.0/allure-2.20.0.tgz - tar -xf allure-2.20.0.tgz - - - name: Make reports - shell: bash - env: - # necessary to run gh cli - GH_TOKEN: ${{ github.token }} - INPUT_REPOSITORY: ${{ inputs.repository }} - INPUT_ARTIFACT_PATTERN: ${{ inputs.pattern }} - INPUT_ARTIFACT_GROUP: ${{ inputs.group }} - run: | - export ALLURE_PATH=$RUNNER_TEMP/allure-2.20.0/bin/allure - python $GITHUB_ACTION_PATH/action.py