build(ci): added CI to build the website preview and deploy to Netlify #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |