| 1 |
name: E2E tests |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: [main, master, next] |
| 6 |
pull_request: |
| 7 |
workflow_dispatch: |
| 8 |
|
| 9 |
jobs: |
| 10 |
install: |
| 11 |
name: Install |
| 12 |
runs-on: ubuntu-latest |
| 13 |
timeout-minutes: 5 |
| 14 |
outputs: |
| 15 |
playwright-version: ${{ steps.playwright-version.outputs.version }} |
| 16 |
steps: |
| 17 |
- name: Check out repository |
| 18 |
uses: actions/checkout@v5 |
| 19 |
|
| 20 |
- name: Set up node |
| 21 |
uses: actions/setup-node@v5 |
| 22 |
with: |
| 23 |
node-version: 20 |
| 24 |
cache: 'npm' |
| 25 |
|
| 26 |
- name: Install dependencies |
| 27 |
run: npm ci |
| 28 |
|
| 29 |
- name: Bundle library |
| 30 |
run: npm run build |
| 31 |
|
| 32 |
- name: Get playwright version |
| 33 |
id: playwright-version |
| 34 |
run: echo "version=$(cat ./package-lock.json | jq -re '.packages["node_modules/@playwright/test"].version')" >> $GITHUB_OUTPUT |
| 35 |
|
| 36 |
- name: Upload dist folder |
| 37 |
uses: actions/upload-artifact@v4 |
| 38 |
if: always() |
| 39 |
with: |
| 40 |
name: dist-folder |
| 41 |
path: dist |
| 42 |
retention-days: 1 |
| 43 |
|
| 44 |
test: |
| 45 |
name: Run playwright tests (${{ matrix.shard }}) |
| 46 |
runs-on: ubuntu-latest |
| 47 |
container: |
| 48 |
image: mcr.microsoft.com/playwright:v${{ needs.install.outputs.playwright-version }}-jammy |
| 49 |
timeout-minutes: 20 |
| 50 |
needs: install |
| 51 |
strategy: |
| 52 |
fail-fast: false |
| 53 |
matrix: |
| 54 |
shard: [1/4, 2/4, 3/4, 4/4] |
| 55 |
# project: [chromium, firefox, webkit] |
| 56 |
steps: |
| 57 |
- name: Check out repository |
| 58 |
uses: actions/checkout@v5 |
| 59 |
|
| 60 |
- name: Set up node |
| 61 |
uses: actions/setup-node@v5 |
| 62 |
with: |
| 63 |
node-version: 20 |
| 64 |
cache: 'npm' |
| 65 |
|
| 66 |
- name: Install dependencies |
| 67 |
run: npm ci |
| 68 |
|
| 69 |
- name: Download dist folder |
| 70 |
uses: actions/download-artifact@v4 |
| 71 |
with: |
| 72 |
name: dist-folder |
| 73 |
path: dist |
| 74 |
|
| 75 |
- name: Run tests |
| 76 |
run: HOME=/root npx playwright test --config ./tests/config/playwright.config.ts --shard ${{ matrix.shard }} # --workers 1 |
| 77 |
|
| 78 |
- name: Sanitize shard name |
| 79 |
id: sanitize-shard |
| 80 |
run: echo "shard=$(echo ${{ matrix.shard }} | tr -d '/')" >> $GITHUB_OUTPUT |
| 81 |
|
| 82 |
- name: Upload blob report |
| 83 |
uses: actions/upload-artifact@v4 |
| 84 |
if: always() |
| 85 |
with: |
| 86 |
name: blob-report-${{ steps.sanitize-shard.outputs.shard }} |
| 87 |
path: tests/reports/blobs |
| 88 |
retention-days: 1 |
| 89 |
|
| 90 |
report: |
| 91 |
name: Create report |
| 92 |
if: always() |
| 93 |
runs-on: ubuntu-latest |
| 94 |
timeout-minutes: 5 |
| 95 |
needs: test |
| 96 |
permissions: |
| 97 |
pull-requests: write |
| 98 |
contents: write |
| 99 |
steps: |
| 100 |
- name: Check out repository |
| 101 |
uses: actions/checkout@v5 |
| 102 |
|
| 103 |
- name: Set up node |
| 104 |
uses: actions/setup-node@v5 |
| 105 |
with: |
| 106 |
node-version: 20 |
| 107 |
cache: 'npm' |
| 108 |
|
| 109 |
- name: Install dependencies |
| 110 |
run: npm ci |
| 111 |
|
| 112 |
- name: Download blob reports |
| 113 |
uses: actions/download-artifact@v4 |
| 114 |
with: |
| 115 |
pattern: blob-report-* |
| 116 |
path: playwright-blob-reports |
| 117 |
merge-multiple: true |
| 118 |
|
| 119 |
- name: Merge blob reports |
| 120 |
run: PLAYWRIGHT_JSON_OUTPUT_NAME=results.json npx playwright merge-reports --reporter html,json ./playwright-blob-reports |
| 121 |
|
| 122 |
- name: Upload HTML report |
| 123 |
uses: actions/upload-artifact@v4 |
| 124 |
if: always() |
| 125 |
with: |
| 126 |
name: html-report # --attempt-${{ github.run_attempt }} |
| 127 |
path: playwright-report |
| 128 |
retention-days: 14 |
| 129 |
|
| 130 |
- name: Check repo context |
| 131 |
id: context-check |
| 132 |
run: | |
| 133 |
if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 134 |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then |
| 135 |
echo "internal=true" >> $GITHUB_OUTPUT |
| 136 |
else |
| 137 |
echo "internal=false" >> $GITHUB_OUTPUT |
| 138 |
fi |
| 139 |
else |
| 140 |
echo "internal=true" >> $GITHUB_OUTPUT |
| 141 |
fi |
| 142 |
|
| 143 |
- name: Check out reports branch |
| 144 |
if: steps.context-check.outputs.internal == 'true' |
| 145 |
uses: actions/checkout@v5 |
| 146 |
with: |
| 147 |
ref: test-reports |
| 148 |
path: test-reports-branch |
| 149 |
fetch-depth: 0 |
| 150 |
|
| 151 |
- name: Generate report name and URL |
| 152 |
id: report-id |
| 153 |
if: steps.context-check.outputs.internal == 'true' |
| 154 |
run: | |
| 155 |
name=$(date +"%Y-%m-%d-%H-%M-%S") |
| 156 |
echo "name=$name" >> $GITHUB_OUTPUT |
| 157 |
echo "path=reports/$name" >> $GITHUB_OUTPUT |
| 158 |
echo "url=https://swup.github.io/swup/reports/$name/" >> $GITHUB_OUTPUT |
| 159 |
|
| 160 |
- name: Copy html report and push reports branch |
| 161 |
if: steps.context-check.outputs.internal == 'true' |
| 162 |
run: | |
| 163 |
mkdir -p test-reports-branch/${{ steps.report-id.outputs.path }} |
| 164 |
cp -r playwright-report/. test-reports-branch/${{ steps.report-id.outputs.path }} |
| 165 |
cd test-reports-branch |
| 166 |
git config user.name github-actions |
| 167 |
git config user.email [email protected] |
| 168 |
git add reports |
| 169 |
git commit -m "Add test report for run ${{ github.run_id }} (attempt: ${{ github.run_attempt }})" |
| 170 |
while true; do |
| 171 |
git pull --rebase |
| 172 |
if [ $? -ne 0 ]; then |
| 173 |
echo "Failed to rebase. Please review manually." |
| 174 |
exit 1 |
| 175 |
fi |
| 176 |
git push |
| 177 |
if [ $? -eq 0 ]; then |
| 178 |
echo "Successfully pushed HTML report to repo." |
| 179 |
exit 0 |
| 180 |
fi |
| 181 |
done |
| 182 |
|
| 183 |
- name: Output report url |
| 184 |
if: steps.context-check.outputs.internal == 'true' |
| 185 |
run: | |
| 186 |
echo "::notice title=Published Playwright test report::${{ steps.report-id.outputs.url }}" |
| 187 |
|
| 188 |
- name: Create report comment |
| 189 |
id: report-summary |
| 190 |
uses: daun/[email protected] |
| 191 |
with: |
| 192 |
report-file: results.json |
| 193 |
report-url: ${{ steps.report-id.outputs.url }} |
| 194 |
job-summary: true |