Skip to content

Commit 1d3b37c

Browse files
committed
build: refactor Vercel deployments (#349)
Signed-off-by: Gabor Boros <[email protected]>
1 parent 483cbcf commit 1d3b37c

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Deploy API Docs to Vercel
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'api/**'
9+
- 'redocly.yaml'
10+
- '.github/workflows/deploy-api-docs.yml'
11+
12+
jobs:
13+
check-docs-changes:
14+
name: Check API Docs Changes
15+
runs-on: ubuntu-latest
16+
outputs:
17+
should-deploy: ${{ steps.check-changes.outputs.should-deploy }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 2
22+
23+
- name: Check if API docs have changes
24+
id: check-changes
25+
run: |
26+
if git diff --name-only HEAD~1 HEAD | grep -q -E "^(api/|redocly\.yaml)"; then
27+
echo "should-deploy=true" >> $GITHUB_OUTPUT
28+
echo "API documentation has changes, will deploy"
29+
else
30+
echo "should-deploy=false" >> $GITHUB_OUTPUT
31+
echo "No changes in API documentation, skipping deployment"
32+
fi
33+
34+
deploy-docs:
35+
name: Deploy API Docs to Vercel
36+
runs-on: ubuntu-latest
37+
needs: check-docs-changes
38+
if: needs.check-docs-changes.outputs.should-deploy == 'true'
39+
environment:
40+
name: production
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Setup Node.js
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: "20.x"
48+
49+
- name: Install Redocly CLI
50+
run: npm install -g @redocly/cli
51+
52+
- name: Build API Documentation
53+
run: |
54+
redocly build-docs api/openapi/openapi.yaml --output api/openapi/index.html
55+
56+
- name: Install Vercel CLI
57+
run: npm install -g vercel@latest
58+
59+
- name: Deploy API Docs to Vercel
60+
id: deploy
61+
run: |
62+
cd api/openapi
63+
vercel link --token ${{ secrets.VERCEL_TOKEN }} --scope ${{ secrets.VERCEL_ORG_ID }} --project ${{ secrets.VERCEL_DOCS_PROJECT_ID }} --yes
64+
vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --yes
65+
env:
66+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
67+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
68+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_DOCS_PROJECT_ID }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Deploy Website to Vercel
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'website/**'
9+
- '.github/workflows/deploy-website.yml'
10+
11+
jobs:
12+
check-website-changes:
13+
name: Check Website Changes
14+
runs-on: ubuntu-latest
15+
outputs:
16+
should-deploy: ${{ steps.check-changes.outputs.should-deploy }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Check if website directory has changes
23+
id: check-changes
24+
run: |
25+
if git diff --name-only HEAD~1 HEAD | grep -q "^website/"; then
26+
echo "should-deploy=true" >> $GITHUB_OUTPUT
27+
echo "Website directory has changes, will deploy"
28+
else
29+
echo "should-deploy=false" >> $GITHUB_OUTPUT
30+
echo "No changes in website directory, skipping deployment"
31+
fi
32+
33+
deploy-website:
34+
name: Deploy Website to Vercel
35+
runs-on: ubuntu-latest
36+
needs: check-website-changes
37+
if: needs.check-website-changes.outputs.should-deploy == 'true'
38+
environment:
39+
name: production
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Setup Node.js
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: "20.x"
47+
48+
- name: Install pnpm
49+
run: npm install -g pnpm
50+
51+
- name: Install dependencies
52+
run: |
53+
cd website
54+
pnpm install --frozen-lockfile
55+
56+
- name: Build Astro website
57+
run: |
58+
cd website
59+
pnpm run build
60+
61+
- name: Install Vercel CLI
62+
run: npm install -g vercel@latest
63+
64+
- name: Deploy Website to Vercel
65+
id: deploy
66+
run: |
67+
cd website
68+
vercel link --token ${{ secrets.VERCEL_TOKEN }} --scope ${{ secrets.VERCEL_ORG_ID }} --project ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }} --yes
69+
vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --yes
70+
env:
71+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
72+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
73+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }}

api/openapi/vercel.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://openapi.vercel.sh/vercel.json",
3+
"git": {
4+
"deploymentEnabled": {
5+
"main": false
6+
}
7+
},
8+
"headers": [
9+
{
10+
"source": "/(.*)",
11+
"headers": [
12+
{
13+
"key": "X-Content-Type-Options",
14+
"value": "nosniff"
15+
},
16+
{
17+
"key": "X-Frame-Options",
18+
"value": "DENY"
19+
},
20+
{
21+
"key": "X-XSS-Protection",
22+
"value": "1; mode=block"
23+
}
24+
]
25+
}
26+
]
27+
}

website/vercel.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://openapi.vercel.sh/vercel.json",
3+
"git": {
4+
"deploymentEnabled": {
5+
"main": false
6+
}
7+
},
8+
"headers": [
9+
{
10+
"source": "/(.*)",
11+
"headers": [
12+
{
13+
"key": "X-Content-Type-Options",
14+
"value": "nosniff"
15+
},
16+
{
17+
"key": "X-Frame-Options",
18+
"value": "DENY"
19+
},
20+
{
21+
"key": "X-XSS-Protection",
22+
"value": "1; mode=block"
23+
}
24+
]
25+
}
26+
]
27+
}

0 commit comments

Comments
 (0)