-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (163 loc) · 5.45 KB
/
build.yml
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Build, test, and deploy
on:
push:
pull_request:
schedule:
# Run once per week to ensure that the pipeline is okay.
- cron: "23 13 * * 0"
permissions:
contents: read
env:
ARTIFACT_NAME: jdkcomparison-site
# Use Node.js LTS. Schedule: https://nodejs.org/en/about/releases/
NODE_VERSION: 22.x
jobs:
common-checks:
name: Run common checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run shellcheck on shell scripts
run: find . -name node_modules -prune -o -type f -name "*.sh" -exec shellcheck {} \;
- name: Run Prettier to ensure files are properly formatted
run: npx prettier@`node -p -e "require('./package.json').devDependencies['prettier']"` --check .
build:
name: Build and test
runs-on: ubuntu-latest
needs:
- common-checks
permissions:
contents: read
checks: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- name: Install dependencies
run: npm install
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Lint
run: npm run lint
- name: Run unit tests
run: npm run jest
# Starts the Next.js development server and puts it into the background before running the tests. Afterwards, the
# development server is stopped.
- name: Run E2E tests
run: |
npm run dev > /dev/null 2>&1 &
PID=$!
npm run e2e
kill "$PID"
- name: Build
run: npx @cloudflare/next-on-pages@`node -p -e "require('./package.json').devDependencies['@cloudflare/next-on-pages']"`
# Upload build output before anything can alter it.
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: .vercel/output/static
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: Test Results of Node.js ${{ env.NODE_VERSION }}
files: |
build/reports/*.xml
deploy-preview:
name: Deploy preview
runs-on: ubuntu-latest
needs:
- build
permissions:
contents: read
deployments: write
pull-requests: write
outputs:
preview-url: ${{ steps.cloudflare-deployment.outputs.deployment-url }}
steps:
- name: Set PREVIEW_NAME for main branch
if: github.ref == 'refs/heads/main'
run: |
echo "PREVIEW_NAME=main-preview" >> $GITHUB_ENV
- name: Set PREVIEW_NAME for all branches other than main
if: github.ref != 'refs/heads/main'
run: |
echo "PREVIEW_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: site
- name: Publish to Cloudflare Pages
id: cloudflare-deployment
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy site --project-name=jdkcomparison --branch=${{ env.PREVIEW_NAME }}
- uses: mshick/add-pr-comment@v2
with:
message: |
### <span aria-hidden="true">✅</span> Your deployment is ready!
| Name | Link |
|-|-|
|Deployed Commit | ${{ github.sha }} |
|Workflow Log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
|Preview URL | ${{ steps.cloudflare-deployment.outputs.deployment-url }} |
---
acceptance:
name: Run acceptance tests
runs-on: ubuntu-latest
needs:
- build
- deploy-preview
permissions:
contents: read
checks: write
pull-requests: write
env:
PLAYWRIGHT_BASE_URL: ${{ needs.deploy-preview.outputs.preview-url }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- name: Install dependencies
run: npm install
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run acceptance tests
run: |
echo "Run acceptance tests against ${{ env.PLAYWRIGHT_BASE_URL }}"
npm run acceptance
deploy-to-production:
name: Deploy to production
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- build
- acceptance
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: site
- name: Publish to Cloudflare Pages
id: cloudflare-deployment
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy site --project-name=jdkcomparison --branch=${{ github.ref_name }}