Skip to content

Commit

Permalink
Add deploy preview action
Browse files Browse the repository at this point in the history
  • Loading branch information
dallyh committed Jan 1, 2024
1 parent 6a7c014 commit 8886cea
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/deploy-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Build and deploy new PR site preview

on:
pull_request:
types: [opened, reopened]
branches: [main]
workflow_dispatch:

permissions:
pull-requests: write # GitHub Actions bot permissions

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Comment on PR
uses: hasura/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "Starting deployment of preview ⏳..."
- name: Checkout and setup node
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
cache-dependency-path: "./package-lock.json"

- name: Create dotenv
run: |
echo "SITE_URL=https://dallyh.github.io/" >> .env
echo "SITE_BASE=/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/" >> .env
- name: Install Node dependencies
run: npm install

- name: Build the site
run: npm run build

- name: Upload site artifact
uses: actions/upload-artifact@v3
with:
name: site
path: ./dist/

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: pull-request-preview
url: https://dallyh.github.io/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/

steps:
- name: Download the artifact
uses: actions/download-artifact@v3
with:
name: site
path: ./dist/

- name: Upload files to GitHub Pages
uses: cpina/[email protected]
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: "./dist/"
destination-github-username: ${{ github.actor }}
destination-repository-name: "deploy-previews"
target-branch: main
target-directory: "${{ github.event.repository.name }}/${{ github.event.pull_request.number }}"

- name: Output the URL
run: echo "https://dallyh.github.io/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/"

- name: Update comment
uses: hasura/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ https://dallyh.github.io/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/ ✨\n\nPlease note that it may take a few seconds for GitHub Pages to build and deploy."
11 changes: 9 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { defineConfig } from "astro/config";
import { i18n, filterSitemapByDefaultLocale } from "astro-i18n-aut/integration";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import { loadEnv } from "vite";
const { SITE_URL, SITE_BASE } = loadEnv(process.env.NODE_ENV, process.cwd(), "");

const URL = SITE_URL ?? "https://www.daliborhon.dev"

console.log(`Using SITE_URL: '${URL}'`);
console.log(`Using SITE_BASE: '${SITE_BASE}'`)

// i18n
const defaultLocale = "cs";
Expand All @@ -12,8 +19,8 @@ const locales = {

// https://astro.build/config
export default defineConfig({
site: "https://www.daliborhon.dev",
base: "",
site: URL,
base: SITE_BASE,
trailingSlash: "always",
build: {
format: "directory",
Expand Down

0 comments on commit 8886cea

Please sign in to comment.