Skip to content

Commit 808d2a6

Browse files
committed
add .gitginore and gh actions workflow
1 parent 7b01f71 commit 808d2a6

File tree

3 files changed

+537
-8
lines changed

3 files changed

+537
-8
lines changed

.github/workflows/preview.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Vercel Preview Deployment
2+
env:
3+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
4+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
5+
on:
6+
push:
7+
branches-ignore:
8+
- main
9+
- production
10+
jobs:
11+
Deploy-Preview:
12+
runs-on:
13+
labels: ubuntu-22.04-2cpu-8ram-75ssd
14+
environment: preview
15+
outputs:
16+
deploymentUrl: ${{ steps.deploy.outputs.deploymentUrl }}
17+
steps:
18+
- name: Checkout the Codebase
19+
uses: actions/checkout@v4
20+
- name: Install Vercel CLI
21+
run: npm install --global vercel@latest
22+
- name: Deploy on Vercel
23+
id: deploy
24+
run: |
25+
vercel deploy --token=${{ secrets.VERCEL_ACCESS_TOKEN }} > deploy.log
26+
URL=$(cat deploy.log | grep -o 'https://[^ ]*.vercel.app' | head -n1)
27+
echo "deploymentUrl=$URL" >> $GITHUB_OUTPUT
28+
- name: Extract branch name
29+
shell: bash
30+
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
31+
id: extract_branch
32+
- name: Assign Custom Domain
33+
if: ${{ steps.extract_branch.outputs.branch == 'remove-basepath-2' }}
34+
run: |
35+
vercel alias set --token=${{ secrets.VERCEL_ACCESS_TOKEN }} ${{ steps.deploy.outputs.deploymentUrl }} ab-test-next-jwt-io.vercel.app --scope=okta
36+
37+
Add-Comment:
38+
runs-on:
39+
labels: ubuntu-22.04-2cpu-8ram-75ssd
40+
needs: Deploy-Preview
41+
permissions:
42+
issues: write
43+
pull-requests: write
44+
steps:
45+
- name: Comment URL to PR
46+
uses: actions/github-script@v6
47+
id: comment-deployment-url-script
48+
env:
49+
DEPLOYMENT_URL: ${{ needs.Deploy-Preview.outputs.deploymentUrl }}
50+
with:
51+
script: |
52+
// Get pull requests that are open for current ref.
53+
const pullRequests = await github.rest.pulls.list({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
state: 'open',
57+
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`
58+
})
59+
60+
// Set issue number for following calls from context (if on pull request event) or from above variable.
61+
const issueNumber = context.issue.number || pullRequests.data[0].number
62+
63+
// Retrieve existing bot comments for the PR
64+
const {data: comments} = await github.rest.issues.listComments({
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
issue_number: issueNumber,
68+
})
69+
const botComment = comments.find(comment => {
70+
return comment.user.type === 'Bot' && comment.body.includes('Preview URL at')
71+
})
72+
73+
const output = "Preview URL " + process.env.DEPLOYMENT_URL
74+
75+
// If we have a comment, update it, otherwise create a new one
76+
if (botComment) {
77+
github.rest.issues.updateComment({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
comment_id: botComment.id,
81+
body: output
82+
})
83+
} else {
84+
github.rest.issues.createComment({
85+
issue_number: issueNumber,
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
body: output
89+
})
90+
}

.github/workflows/production.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Vercel Production Deployment
2+
env:
3+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
4+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
5+
on:
6+
push:
7+
branches:
8+
- main
9+
- production
10+
jobs:
11+
Deploy-Production:
12+
runs-on:
13+
labels: ubuntu-22.04-2cpu-8ram-75ssd
14+
steps:
15+
- name: Checkout the Codebase
16+
uses: actions/checkout@v4
17+
- name: Install Vercel CLI
18+
run: npm install --global vercel@latest
19+
- name: Deploy on Vercel
20+
id: deploy
21+
run: |
22+
vercel deploy --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }}

0 commit comments

Comments
 (0)