Skip to content

Commit

Permalink
ci: deploy to GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatLady committed Nov 20, 2024
1 parent 8eaca3a commit a63307b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main

jobs:
build:
name: Build Docusaurus
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website
run: yarn build

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

deploy:
name: Deploy to GitHub Pages
needs: build

permissions:
pages: write
id-token: write

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
10 changes: 6 additions & 4 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import versions from './versions.json';

const isDev = process.env.NODE_ENV === 'development';
const isBuildFast = isDev || !!process.env.BUILD_FAST;
const isNetlify = !!process.env.NETLIFY;
const isProd = isNetlify && process.env.CONTEXT === 'production';
const isProd =
process.env.CURRENT_BRANCH === 'main' && process.env.CONTEXT === 'production';

const config: Config = {
organizationName: 'someengineering',
projectName: 'inventory.fix.security',
deploymentBranch: 'gh-pages',
title: 'Fix Inventory by Some Engineering Inc.',
url: 'https://inventory.fix.security',
baseUrl: '/',
Expand All @@ -29,14 +32,13 @@ const config: Config = {
noIndex: !isProd,
customFields: {
isDev,
isNetlify,
isProd,
posthogProjectApiKey: process.env.POSTHOG_PROJECT_API_KEY,
},
scripts: isProd
? [
{
src: 'https://inventory.fix.security/js/script.js',
src: 'https://plausible.io/js/script.js',
defer: true,
'data-domain': 'inventory.fix.security',
},
Expand Down
6 changes: 3 additions & 3 deletions src/providers/posthog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export default function PosthogProvider({
}) {
const {
siteConfig: {
customFields: { isDev, isNetlify, isProd, posthogProjectApiKey },
customFields: { isDev, isProd, posthogProjectApiKey },
},
} = useDocusaurusContext();

useEffect(() => {
if (posthogProjectApiKey && !posthog.__loaded) {
posthog.init(posthogProjectApiKey as string, {
api_host: isNetlify ? '/api/ingest' : 'https://eu.posthog.com',
api_host: 'https://eu.posthog.com',
ui_host: 'https://eu.posthog.com',
cross_subdomain_cookie: !!isProd,
secure_cookie: !!isNetlify,
Expand All @@ -33,7 +33,7 @@ export default function PosthogProvider({
enable_recording_console_log: false,
});
}
}, [isDev, isNetlify, isProd, posthogProjectApiKey]);
}, [isDev, isProd, posthogProjectApiKey]);

return <Provider client={posthog}>{children}</Provider>;
}

0 comments on commit a63307b

Please sign in to comment.