From ea32c9cffd198f29aa82a2f7a6ebcedb8db73c1d Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 5 Nov 2024 15:47:44 +0545 Subject: [PATCH] chore: add workflow and script for allure report deployment --- .../generate_latest_report_redirect.sh | 18 +++ .github/scripts/generate_report_details.sh | 11 ++ .github/scripts/register_report.sh | 15 +++ .../workflows/test_integration_playwright.yml | 118 ++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 .github/scripts/generate_latest_report_redirect.sh create mode 100644 .github/scripts/generate_report_details.sh create mode 100644 .github/scripts/register_report.sh create mode 100644 .github/workflows/test_integration_playwright.yml diff --git a/.github/scripts/generate_latest_report_redirect.sh b/.github/scripts/generate_latest_report_redirect.sh new file mode 100644 index 0000000..688e612 --- /dev/null +++ b/.github/scripts/generate_latest_report_redirect.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +REPORT_NUMBER="$1" + +mkdir -p build +cp -r allure-history/*[^index.html] build/ +allure_report_path=$(basename "$GH_PAGES") + +cat < build/index.html + + + + + + Redirecting... + + +EOF diff --git a/.github/scripts/generate_report_details.sh b/.github/scripts/generate_report_details.sh new file mode 100644 index 0000000..f9e4416 --- /dev/null +++ b/.github/scripts/generate_report_details.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [[ ! -d "gh-pages/$REPORT_NAME" ]]; then + latest_number=0 +else + gh_pages_content=$(ls "gh-pages/$REPORT_NAME/") + latest_number=$(echo "$gh_pages_content" | grep -Eo '[0-9]+' | sort -nr | head -n 1) +fi + +echo "::set-output name=report_number::$((latest_number+1))" +echo "::set-output name=report_url::https://$(dirname "$GH_PAGES").github.io/$(basename "$GH_PAGES")/$REPORT_NAME" diff --git a/.github/scripts/register_report.sh b/.github/scripts/register_report.sh new file mode 100644 index 0000000..a36016e --- /dev/null +++ b/.github/scripts/register_report.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +PROJECT_DIR="project" +PROJECT_FILE="projects.txt" + +mkdir -p "$PROJECT_DIR" +cp -r gh-pages/* "$PROJECT_DIR" || true + +if grep -q "$REPORT_NAME" "$PROJECT_DIR/$PROJECT_FILE"; then + echo "Project already exists" + echo "::set-output name=project_exists::true" +else + echo "$REPORT_NAME" >> "$PROJECT_DIR/$PROJECT_FILE" + echo "::set-output name=project_exists::false" +fi diff --git a/.github/workflows/test_integration_playwright.yml b/.github/workflows/test_integration_playwright.yml new file mode 100644 index 0000000..81b5716 --- /dev/null +++ b/.github/workflows/test_integration_playwright.yml @@ -0,0 +1,118 @@ +name: Integration Test [Playwright] + +on: + push: + branches: + - test + +jobs: + integration-tests: + runs-on: ubuntu-latest + defaults: + run: + working-directory: tests/integration + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "18" + cache: "npm" + cache-dependency-path: "./tests/integration/package-lock.json" + + - name: Install dependencies + run: npm ci + + - name: Cache Playwright browsers + id: cache-playwright-browsers + uses: actions/cache@v3 + with: + path: | + ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-browsers + + - name: Install Playwright browsers if not cached + if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' + run: npx playwright install --with-deps + + - name: Run tests + run: | + npm test + + - name: Upload report + uses: actions/upload-artifact@v3 + if: always() + with: + name: allure-results + path: tests/integration/allure-results + + publish-report: + runs-on: ubuntu-latest + if: always() + needs: integration-tests + steps: + - uses: actions/checkout@v4 + - name: Download report + uses: actions/download-artifact@v3 + with: + name: allure-results + path: allure-results + + - name: Get Allure history + uses: actions/checkout@v4 + continue-on-error: true + with: + ref: gh-pages + path: gh-pages + repository: ${{vars.GH_PAGES}} + ssh-key: ${{ secrets.DEPLOY_KEY }} + + - name: Register report + id: register-project + if: ${{success()}} + run: | + chmod +x .github/scripts/register_report.sh + .github/scripts/register_report.sh + - if: steps.register-project.outputs.project_exists != 'true' + uses: JamesIves/github-pages-deploy-action@v4 + with: + ssh-key: ${{ secrets.DEPLOY_KEY }} + repository-name: ${{vars.GH_PAGES}} + branch: gh-pages + folder: project + + - name: Generate report details + id: report-details + run: | + chmod +x .github/scripts/generate_report_details.sh + .github/scripts/generate_report_details.sh + + - name: Build report + uses: simple-elf/allure-report-action@master + if: always() + id: allure-report + with: + allure_results: allure-results + gh_pages: gh-pages/${{env.REPORT_NAME}} + allure_report: allure-report + allure_history: allure-history + keep_reports: 2000 + report_url: ${{steps.report-details.outputs.report_url}} + github_run_num: ${{steps.report-details.outputs.report_number}} + + - name: Generate Latest Report + run: | + chmod +x .github/scripts/generate_latest_report_redirect.sh + .github/scripts/generate_latest_report_redirect.sh ${{steps.report-details.outputs.report_number}} + + - name: Deploy report to Github Pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + ssh-key: ${{ secrets.DEPLOY_KEY }} + repository-name: ${{vars.GH_PAGES}} + branch: gh-pages + folder: build + target-folder: ${{ env.REPORT_NAME }} + + env: + REPORT_NAME: frontend + GH_PAGES: ${{vars.GH_PAGES}}