Skip to content

Commit

Permalink
Implemented pr preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-Beta committed Oct 11, 2024
1 parent b817213 commit ad47a28
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 62 deletions.
53 changes: 10 additions & 43 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
name: Deploy to GitHub Pages

# .github/workflows/deploy.yml
name: Deploy PR previews
on:
push:
branches:
- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

jobs:
build:
name: Build Docusaurus
deploy-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- run: npm i && npm run build
- uses: JamesIves/github-pages-deploy-action@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm

- name: Install dependencies
run: npm ci
- name: Build website
run: npm run build

- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3
with:
path: build

deploy:
name: Deploy to GitHub Pages
needs: build

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
folder: ./build/
branch: gh-pages
clean-exclude: pr-preview
force: false
27 changes: 9 additions & 18 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# .github/workflows/preview.yml
name: Deploy PR previews

on:
Expand All @@ -12,31 +13,21 @@ concurrency: preview-${{ github.ref }}

jobs:
deploy-preview:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: npm install
- name: Install and Build

- name: Build Docusaurus
run: npm run build

- name: Deploy preview
if: github.event.action != 'closed'
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./build/
preview-branch: main
umbrella-dir: pr-preview
action: deploy
env:
PR_NUMBER: ${{ github.event.number }}
run: |
npm install
npm run build
- name: Remove PR Preview
if: github.event.action == 'closed' && !github.event.pull_request.merged
- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./build/
preview-branch: main
umbrella-dir: pr-preview
action: remove
7 changes: 6 additions & 1 deletion docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { themes as prismThemes } from "prism-react-renderer";
import type { Config } from "@docusaurus/types";
import type * as Preset from "@docusaurus/preset-classic";

const BASE_URL =
process.env.PR_NUMBER !== undefined
? `/website/pr-preview/pr-${process.env.PR_NUMBER}/`
: "/website/";

const config: Config = {
title: "Betalectic",
tagline: "Dinosaurs are cool",
Expand All @@ -11,7 +16,7 @@ const config: Config = {
url: "https://github.com",
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: process.env.BASE_URL || "/website/",
baseUrl: BASE_URL,

// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
Expand Down

0 comments on commit ad47a28

Please sign in to comment.