-
Notifications
You must be signed in to change notification settings - Fork 3
55 lines (47 loc) · 1.97 KB
/
build-preview.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
name: Build preview
# This job builds and deploys a preview of the overall website.
# It runs on every push to main as well as any PR.
on:
pull_request:
push:
branches:
- main
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Setup Node.js 🔧
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Install Netlify CLI 🔧
run: npm install -g netlify-cli
- name: Deploy to Netlify 🚀
id: deploy-netlify
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
OUTPUT=$(netlify deploy --build --context deploy-preview --message 'Deployment from GitHub Actions')
NETLIFY_PREVIEW_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*')
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT"
NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*')
echo "NETLIFY_LOGS_URL=$NETLIFY_LOGS_URL" >> "$GITHUB_OUTPUT"
- name: Netlify Preview URL 👓
if: github.event_name == 'pull_request'
uses: unsplash/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OUTPUT: "This pull request is being automatically deployed to Netlify.\n\n🔍 Inspect: ${{ steps.deploy-netlify.outputs.NETLIFY_LOGS_URL }}\n✅ Preview: ${{ steps.deploy-netlify.outputs.NETLIFY_PREVIEW_URL }}"
with:
msg: ${{ env.OUTPUT }}
check_for_duplicate_msg: false
- name: Create status check 📝
uses: Sibz/[email protected]
with:
authToken: ${{ secrets.GITHUB_TOKEN }}
context: Netlify preview
state: success
target_url: ${{ steps.deploy-netlify.outputs.NETLIFY_PREVIEW_URL }}