Skip to content

Commit

Permalink
Cypress reports (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Jan 15, 2025
1 parent 9d0e69c commit cd5c601
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 13 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
})
117 changes: 117 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -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
<!DOCTYPE html>
<html>
<head>
<title>Cypress Test Reports</title>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
margin: 2em auto;
max-width: 800px;
line-height: 1.6;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #eee;
padding-bottom: 0.5em;
}
.report {
margin: 1em 0;
padding: 0.8em;
background: #f8f9fa;
border-radius: 4px;
}
.report a {
color: #3498db;
text-decoration: none;
}
.report a:hover {
text-decoration: underline;
}
.latest {
background: #e8f5e9;
border-left: 4px solid #4caf50;
}
</style>
</head>
<body>
<h1>Cypress Test Reports</h1>
<div class='report'>
<a href='latest-master/'>Latest Master Report</a>
</div>
<h2>All Reports</h2>
<div id="reports">
$(for d in _site/reports/*/; do
name=$(basename "$d")
if [ "$name" != "latest-master" ]; then
echo "<div class='report'><a href='$name/'>$name</a></div>"
fi
done)
</div>
</body>
</html>
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
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- name: Publish Unit Test Results
uses: dorny/[email protected]
if: always()
continue-on-error: true
with:
name: Test Results
path: "tests/*.xml"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cypress/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM cypress/included:13.17.0
RUN apt-get update && apt-get install fonts-noto-color-emoji -y
2 changes: 1 addition & 1 deletion cypress/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
cypress:
image: cypress/included:13.17.0
build: .
profiles:
- ci
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit cd5c601

Please sign in to comment.