Skip to content

Commit

Permalink
Github pages workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Aug 6, 2024
1 parent 04cd101 commit be3d312
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
- develop

permissions:
contents: write

jobs:
build-and-deploy:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install

- name: Set branch subpath variable (for vite)
# This is the URL subpath where a branch is deployed.
# Empty for main branch (root), otherwise <branch-name>.
run: |
if [ "${{ github.ref_name }}" == "main" ]; then
echo "BRANCH_SUBPATH=" >> $GITHUB_ENV
else
echo "BRANCH_SUBPATH=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build project with development backend
if: github.ref_name != 'main'
run: npm run build:be-dev

- name: Build project with production backend
if: github.ref_name == 'main'
run: npm run build:be-prod

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./dist
# Deploy main branch to root, other branches to their subfolders
target-folder: ${{ env.BRANCH_SUBPATH }}
# when deploying main to root, keep `dev` folder, as other branches
# are deployed there
clean-exclude: "develop"
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ Preview either locally with
```
> npm run preview
```

## Branches and deployment

The following branches are automatically deployed via Github actions in the following manner:

- `main`
- deployed to https://mc3d.materialscloud.org
- and is running on the production backend.
- `develop`
- deployed to https://mc3d.materialscloud.org/develop
- and is running on the dev backend.
7 changes: 5 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
// `base:` is the full subpath of the URL.
// Set it dynamically from an env variable,
// as different gh branches are deployed to different subpaths

export default defineConfig({
plugins: [react()],
base: "/discover-mc3d-react/",
base: process.env.BRANCH_SUBPATH || "",
});

0 comments on commit be3d312

Please sign in to comment.