How to publish (serve) allure report at Github Actions

3 min read 05-10-2024
How to publish (serve) allure report at Github Actions


Publishing Allure Reports with GitHub Actions: A Step-by-Step Guide

Problem: You've implemented automated tests using Allure, a powerful framework for generating beautiful and informative reports. But you need to make these reports easily accessible to your team, especially when using GitHub Actions for continuous integration and delivery (CI/CD).

Solution: This article provides a comprehensive guide on publishing your Allure reports directly to your GitHub Actions workflow, making them readily viewable within the workflow's summary page.

Scenario: Imagine you have a Python project with automated tests using pytest and Allure. Your GitHub Actions workflow runs the tests and generates an Allure report. You want to publish this report so anyone can easily see the test results.

Original Code:

name: Allure Report

on:
  push:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Run tests with Allure
        run: pytest --alluredir=allure-results
      - name: Upload Allure Report
        uses: actions/upload-artifact@v3
        with:
          name: allure-report
          path: allure-results

Explanation:

  • on: push: ...: Triggers the workflow on every push to the main branch.
  • jobs: test: ...: Defines a job named "test" that runs on the ubuntu-latest runner.
  • steps: ...: Defines the steps within the job:
    • actions/checkout@v3: Checks out the repository code.
    • Install dependencies: Installs project dependencies.
    • Run tests with Allure: Executes the pytest tests with the --alluredir flag, specifying the directory for storing Allure results.
    • Upload Allure Report: Uploads the generated Allure results directory as an artifact named allure-report.

Limitations of Original Code:

While the original code uploads the Allure report as an artifact, it doesn't make it directly viewable. To view the report, you would have to manually download the artifact, which can be cumbersome.

Enhanced Solution:

To publish the Allure report directly to the GitHub Actions workflow, you can use a specialized action like allure-report/upload-allure-results. This action automatically processes your Allure results and displays a detailed report in the GitHub Actions workflow summary page.

Modified Code:

name: Allure Report

on:
  push:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Run tests with Allure
        run: pytest --alluredir=allure-results
      - name: Upload Allure Report
        uses: allure-report/upload-allure-results@v1
        with:
          results: allure-results

Explanation:

  • allure-report/upload-allure-results@v1: This action processes the Allure results and uploads them to GitHub.
  • results: allure-results: Specifies the path to the Allure results directory.

Benefits of Using allure-report/upload-allure-results:

  • Direct Viewing: The Allure report is displayed directly in the GitHub Actions workflow summary, eliminating the need for manual downloads.
  • Enhanced Visualization: The report includes comprehensive test results with detailed information about failures, attachments, and execution timelines.
  • Ease of Use: Simple configuration and easy integration with existing workflows.

Additional Tips:

  • Customize Report Display: You can configure the allure-report/upload-allure-results action to customize how the report is displayed, including the title and URL.
  • Use Allure Server: For larger teams and more complex projects, consider using an Allure server to manage and access reports centrally.
  • Integrate with CI/CD Pipelines: Publish Allure reports as part of your continuous integration and delivery pipeline for comprehensive test visibility across development stages.

References:

Conclusion:

Publishing Allure reports to GitHub Actions allows teams to easily access and analyze test results, improving transparency and collaboration. By following the guidelines and code examples provided, you can seamlessly integrate Allure reporting into your workflow and ensure efficient test feedback for your project.