From cd5c6012b5ed2e926364ba04001cfb694029dd45 Mon Sep 17 00:00:00 2001 From: Chris Malloy Date: Tue, 14 Jan 2025 19:26:12 -0400 Subject: [PATCH] Cypress reports (#325) --- .github/workflows/cypress.yml | 39 +++++++++--- .github/workflows/pages.yml | 117 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 1 - README.md | 2 +- cypress/Dockerfile | 2 + cypress/docker-compose.yaml | 2 +- package.json | 2 +- 7 files changed, 152 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/pages.yml create mode 100644 cypress/Dockerfile diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 551e0ea20..abc331191 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -7,27 +7,48 @@ on: branches: [ master ] workflow_dispatch: +permissions: + contents: read + pull-requests: write + jobs: cypress-run: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 18 cache: 'npm' - - name: Install lockfile run: npm ci - - name: Run Cypress Tests + id: cypress run: npm run cy:ci - - - name: Publish Report + - name: Upload PR Report + if: github.event_name == 'pull_request' && always() uses: actions/upload-artifact@v4 - if: always() with: - name: cypress + name: cypress-reports-pr-${{ github.event.pull_request.number }} path: cypress/reports/html + retention-days: 7 + - name: Upload Reports + if: github.event_name != 'pull_request' && always() + uses: actions/upload-artifact@v4 + with: + name: cypress-reports-${{ github.ref_name }}-${{ github.run_number }} + path: cypress/reports/html + retention-days: 28 + - name: Comment on PR + if: github.event_name == 'pull_request' && always() + uses: actions/github-script@v7 + with: + script: | + const emoji = '${{ steps.cypress.outcome }}' === 'success' ? '✅' : '❌'; + const url = `https://${context.repo.owner}.github.io/${context.repo.repo}/reports/cypress-reports-pr-${context.issue.number}/` + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `${emoji} Cypress report available at: ${url}` + }) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..e6667dcf6 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,117 @@ +name: GitHub Pages + +on: + push: + branches: [ master ] + workflow_run: + workflows: ["Cypress"] + types: + - completed + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/configure-pages@v5 + + # Create site directory + - name: Create site directory + run: | + mkdir -p _build _site + cp README.md _build/ + cp -r docs _build/ + + # Build docs from root + - uses: actions/jekyll-build-pages@v1 + with: + source: ./_build + destination: ./_site + + # Download and merge any test reports + - name: Process Reports + run: | + mkdir -p "_site/reports" + gh auth login --with-token <<< "${{ github.token }}" + gh run download --pattern "cypress-reports-*" --dir _site/reports + # Create copy of latest master report + latest_master=$(ls -td _site/reports/cypress-reports-master-* 2>/dev/null | head -1) + if [ -n "$latest_master" ] && [ -d "$latest_master" ]; then + mkdir -p _site/reports/latest-master + cp -r "$latest_master/." _site/reports/latest-master/ + fi + cat > _site/reports/index.html << EOF + + + + Cypress Test Reports + + + +

Cypress Test Reports

+
+ Latest Master Report +
+

All Reports

+
+ $(for d in _site/reports/*/; do + name=$(basename "$d") + if [ "$name" != "latest-master" ]; then + echo "" + fi + done) +
+ + + EOF + + # Upload combined site + - uses: actions/upload-pages-artifact@v3 + + deploy: + needs: build + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - uses: actions/deploy-pages@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61bc97188..15ad42213 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,6 @@ jobs: - name: Publish Unit Test Results uses: dorny/test-reporter@v1.9.1 if: always() - continue-on-error: true with: name: Test Results path: "tests/*.xml" diff --git a/README.md b/README.md index 7919dfbef..b688e091a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Reference client for Jasper KM. [![Build & Test](https://github.com/cjmalloy/jasper-ui/actions/workflows/test.yml/badge.svg)](https://github.com/cjmalloy/jasper-ui/actions/workflows/test.yml) -[![Cypress](https://github.com/cjmalloy/jasper-ui/actions/workflows/cypress.yml/badge.svg)](https://github.com/cjmalloy/jasper-ui/actions/workflows/cypress.yml) +[![Cypress](https://github.com/cjmalloy/jasper-ui/actions/workflows/cypress.yml/badge.svg)](https://cjmalloy.github.io/jasper-ui/reports/latest-master) [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/jasper)](https://artifacthub.io/packages/helm/jasper/jasper-ui) Jasper-UI is the reference client for the diff --git a/cypress/Dockerfile b/cypress/Dockerfile new file mode 100644 index 000000000..e3a0f1549 --- /dev/null +++ b/cypress/Dockerfile @@ -0,0 +1,2 @@ +FROM cypress/included:13.17.0 +RUN apt-get update && apt-get install fonts-noto-color-emoji -y diff --git a/cypress/docker-compose.yaml b/cypress/docker-compose.yaml index 1e19a9ef8..fb15c047b 100644 --- a/cypress/docker-compose.yaml +++ b/cypress/docker-compose.yaml @@ -1,6 +1,6 @@ services: cypress: - image: cypress/included:13.17.0 + build: . profiles: - ci depends_on: diff --git a/package.json b/package.json index 4df4c77bc..f1ca510d0 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "test": "ng test", "e2e": "ng e2e", "cy:open": "(cd cypress; docker compose pull && docker compose up --build -d) && cypress open && (cd cypress; docker compose down)", - "cy:ci": "docker compose --profile ci -f 'cypress/docker-compose.yaml' up --build --exit-code-from cypress" + "cy:ci": "(cd cypress; docker compose pull && docker compose up web repl-web -d) && docker compose --profile ci -f 'cypress/docker-compose.yaml' up --build --exit-code-from cypress" }, "private": true, "dependencies": {