From a63307bcb09e88787159fe4459e18b8bf642e7a6 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:19:20 -0800 Subject: [PATCH] ci: deploy to GitHub Pages --- .github/workflows/deploy.yml | 47 ++++++++++++++++++++++++++++++++++++ docusaurus.config.ts | 10 +++++--- src/providers/posthog.tsx | 6 ++--- 3 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..da440fa5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 2a62c97d..5e916239 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -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: '/', @@ -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', }, diff --git a/src/providers/posthog.tsx b/src/providers/posthog.tsx index 13f2ac8d..168a61e0 100644 --- a/src/providers/posthog.tsx +++ b/src/providers/posthog.tsx @@ -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, @@ -33,7 +33,7 @@ export default function PosthogProvider({ enable_recording_console_log: false, }); } - }, [isDev, isNetlify, isProd, posthogProjectApiKey]); + }, [isDev, isProd, posthogProjectApiKey]); return {children}; }