-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (135 loc) · 4.56 KB
/
deploy.yml
File metadata and controls
158 lines (135 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Deploy to GitHub Pages
on:
push:
branches: 'main'
workflow_dispatch:
jobs:
get_pages_url_job:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
pages_url: ${{ steps.get_url.outputs.PAGES_URL }}
steps:
- name: Get GitHub Pages URL
id: get_url
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -z "$ACT" ]; then
PAGES_URL=$(gh api "repos/${{ github.repository }}/pages" --jq '.html_url')
echo "PAGES_URL=$PAGES_URL" >> "$GITHUB_OUTPUT"
else
echo "PAGES_URL=rrmistry.ca" >> "$GITHUB_OUTPUT"
fi
get_playwright_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Playwright version from package.json
id: get_version
run: |
PLAYWRIGHT_VERSION=$(node -p "require('./package.json').devDependencies['@playwright/test'].replace(/[\^~]/, '')")
echo "version=$PLAYWRIGHT_VERSION" >> "$GITHUB_OUTPUT"
echo "Using Playwright version: $PLAYWRIGHT_VERSION"
build_and_test:
needs: [get_pages_url_job, get_playwright_version]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v${{ needs.get_playwright_version.outputs.version }}-noble
options: --user 1001
env:
DEV_SERVER_PORT: 8080
steps:
- name: Checkout
uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# if: ${{ !env.ACT }}
# with:
# node-version: lts/*
# cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Sync SvelteKit
run: npx svelte-kit sync
- name: Run unit tests
run: npm run test:unit
- name: build
env:
BASE_PATH: '/'
run: npm run build
- name: Start SvelteKit dev server and download sitemap.xml
run: |
# Start dev server in background
npm run dev -- --port $DEV_SERVER_PORT &
SERVER_PID=$!
# Wait for server to be ready
for i in $(seq 1 30); do
if curl -s http://localhost:$DEV_SERVER_PORT/ > /dev/null; then
echo "Server is ready!"
break
fi
echo "Waiting for server to start... attempt $i/30"
sleep 2
done
# Download sitemap.xml
for i in $(seq 1 10); do
if curl http://localhost:$DEV_SERVER_PORT/sitemap.xml -o build/sitemap.xml; then
echo "Successfully downloaded sitemap.xml"
break
fi
echo "Attempt $i failed, waiting..."
sleep 5
done
# Kill the server and wait for it to stop
echo "Stopping dev server..."
kill $SERVER_PID || true
# Wait for the port to be free
for i in $(seq 1 10); do
if ! curl -s http://localhost:$DEV_SERVER_PORT/ > /dev/null 2>&1; then
echo "Server stopped successfully"
break
fi
echo "Waiting for server to stop... attempt $i/10"
sleep 1
done
working-directory: .
- name: Replace page_url in sitemap and other SEO files
run: |
# Right-trim trailing slash from pages_url if it exists
PAGES_URL="${{ needs.get_pages_url_job.outputs.pages_url }}"
PAGES_URL="${PAGES_URL%/}" # Remove trailing slash if present
sed -i "s|http://localhost:${{ env.DEV_SERVER_PORT }}|${PAGES_URL}|g" build/sitemap.xml
node scripts/generate-seo-files.mjs "${PAGES_URL}"
- name: Upload Artifacts
if: ${{ !env.ACT }} # skip during local actions testing
uses: actions/upload-pages-artifact@v3
with:
# this should match the `pages` option in your adapter-static options
path: 'build/'
- name: Run Playwright tests
run: npm run test:e2e
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() && !env.ACT }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
deploy:
needs: [build_and_test]
# needs: build_and_test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4