Skip to content

Commit 1e0f780

Browse files
feat: add GitHub Actions CI/CD pipeline for production deployment
1 parent f4fbcc3 commit 1e0f780

1 file changed

Lines changed: 175 additions & 0 deletions

File tree

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: Production Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
env:
13+
NODE_VERSION: '18.18.0'
14+
PNPM_VERSION: '8.15.6'
15+
16+
jobs:
17+
quality-checks:
18+
name: Quality Checks
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 15
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v2
30+
with:
31+
version: ${{ env.PNPM_VERSION }}
32+
33+
- name: Setup Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: ${{ env.NODE_VERSION }}
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install --frozen-lockfile
41+
42+
- name: Run linter
43+
run: pnpm lint
44+
continue-on-error: true
45+
46+
- name: Run tests
47+
run: pnpm test
48+
continue-on-error: true
49+
50+
build:
51+
name: Build Application
52+
runs-on: ubuntu-latest
53+
needs: quality-checks
54+
timeout-minutes: 20
55+
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
- name: Setup pnpm
61+
uses: pnpm/action-setup@v2
62+
with:
63+
version: ${{ env.PNPM_VERSION }}
64+
65+
- name: Setup Node.js
66+
uses: actions/setup-node@v4
67+
with:
68+
node-version: ${{ env.NODE_VERSION }}
69+
cache: 'pnpm'
70+
71+
- name: Install dependencies
72+
run: pnpm install --frozen-lockfile
73+
74+
- name: Build packages
75+
run: pnpm build
76+
env:
77+
NODE_OPTIONS: '--max-old-space-size=4096'
78+
ASTRO_TELEMETRY_DISABLED: '1'
79+
80+
- name: Build documentation site
81+
run: pnpm docs:build
82+
env:
83+
NODE_OPTIONS: '--max-old-space-size=4096'
84+
ASTRO_TELEMETRY_DISABLED: '1'
85+
86+
- name: Verify build output
87+
run: |
88+
if [ ! -d "docs/tutorialkit.dev/dist" ]; then
89+
echo "Error: Build output directory not found"
90+
exit 1
91+
fi
92+
echo "Build output verified successfully"
93+
ls -la docs/tutorialkit.dev/dist
94+
95+
- name: Upload build artifacts
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: build-output
99+
path: docs/tutorialkit.dev/dist
100+
retention-days: 7
101+
102+
deploy-vercel:
103+
name: Deploy to Vercel
104+
runs-on: ubuntu-latest
105+
needs: build
106+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
107+
timeout-minutes: 10
108+
environment:
109+
name: production
110+
url: ${{ steps.deploy.outputs.url }}
111+
112+
steps:
113+
- name: Checkout repository
114+
uses: actions/checkout@v4
115+
116+
- name: Download build artifacts
117+
uses: actions/download-artifact@v4
118+
with:
119+
name: build-output
120+
path: docs/tutorialkit.dev/dist
121+
122+
- name: Deploy to Vercel
123+
id: deploy
124+
uses: amondnet/vercel-action@v25
125+
with:
126+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
127+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
128+
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
129+
vercel-args: '--prod'
130+
working-directory: ./
131+
132+
- name: Deployment summary
133+
run: |
134+
echo "### 🚀 Deployment Successful" >> $GITHUB_STEP_SUMMARY
135+
echo "" >> $GITHUB_STEP_SUMMARY
136+
echo "**URL:** ${{ steps.deploy.outputs.url }}" >> $GITHUB_STEP_SUMMARY
137+
echo "**Environment:** Production" >> $GITHUB_STEP_SUMMARY
138+
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
139+
140+
deploy-preview:
141+
name: Deploy Preview
142+
runs-on: ubuntu-latest
143+
needs: build
144+
if: github.event_name == 'pull_request'
145+
timeout-minutes: 10
146+
147+
steps:
148+
- name: Checkout repository
149+
uses: actions/checkout@v4
150+
151+
- name: Download build artifacts
152+
uses: actions/download-artifact@v4
153+
with:
154+
name: build-output
155+
path: docs/tutorialkit.dev/dist
156+
157+
- name: Deploy Preview to Vercel
158+
id: deploy-preview
159+
uses: amondnet/vercel-action@v25
160+
with:
161+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
162+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
163+
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
164+
working-directory: ./
165+
166+
- name: Comment PR
167+
uses: actions/github-script@v7
168+
with:
169+
script: |
170+
github.rest.issues.createComment({
171+
issue_number: context.issue.number,
172+
owner: context.repo.owner,
173+
repo: context.repo.repo,
174+
body: `### 🔍 Preview Deployment\n\n**URL:** ${{ steps.deploy-preview.outputs.url }}\n**Commit:** ${{ github.sha }}`
175+
})

0 commit comments

Comments
 (0)