-
Notifications
You must be signed in to change notification settings - Fork 62
61 lines (61 loc) · 2.05 KB
/
ci-pr-docs.yaml
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
name: ci pr docs
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_DOCS_PROJECT_ID }}
on:
pull_request:
paths:
- 'docs/**'
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
url: ${{ steps.deploy.outputs.deployment_url }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install PNPM
uses: pnpm/action-setup@v4
with:
version: 8
- name: Install Vercel CLI
run: pnpm install --global vercel@latest
- name: Check if External PR
id: check_external
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "external=true" >> $GITHUB_ENV
else
echo "external=false" >> $GITHUB_ENV
fi
- name: Deploy with Vercel
id: deploy
if: env.external == 'false'
run: |
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
vercel build --token=${{ secrets.VERCEL_TOKEN }}
echo "deployment_url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
comment:
needs: deploy
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Comment on PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const isExternal = process.env.external === 'true';
const deploymentUrl = isExternal ? null : '${{ needs.deploy.outputs.url }}';
const message = isExternal
? "Preview deployment skipped for external pull requests."
: `Docs preview complete 🚀 see it here: ${deploymentUrl}`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: message,
});