This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* copy workflows from dpgraham-server for building and pushing docker images * quick add error handling in DpgMarkdownArticle, use new backend URL * useTitle custom hook * utilize useTitle hook in features
- Loading branch information
1 parent
5ff9ff5
commit 82b82d9
Showing
14 changed files
with
222 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Reusable Workflow to deploy a new revision to Cloud Run | ||
|
||
name: Deploy to Cloud Run | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
description: 'The environment to deploy to' | ||
required: true | ||
type: string | ||
default: 'production' | ||
version: | ||
description: 'The version of the image to deploy' | ||
required: true | ||
type: string | ||
default: 'latest' | ||
service: | ||
description: 'The name of the Cloud Run service to deploy to' | ||
required: true | ||
type: string | ||
default: 'dpgraham-client' | ||
|
||
env: | ||
PROJECT_ID: ${{ vars.PROJECT_ID }} | ||
REPOSITORY: ${{ vars.REPOSITORY }} | ||
IMAGE_NAME: ${{ vars.IMAGE_NAME }} | ||
GOOGLE_REGISTRY_LOCATION: ${{ vars.GOOGLE_REGISTRY_LOCATION }} | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
|
||
steps: | ||
- uses: 'actions/checkout@v3' | ||
|
||
|
||
- name: Authenticate Google Cloud | ||
uses: google-github-actions/auth@v1 | ||
id: auth | ||
with: | ||
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} | ||
token_format: 'access_token' | ||
|
||
- name: Deploy to Cloud Run | ||
id: deploy | ||
uses: 'google-github-actions/deploy-cloudrun@v1' | ||
with: | ||
service: ${{ inputs.service }} | ||
image: ${{ env.GOOGLE_REGISTRY_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ inputs.version }} | ||
region: ${{ env.GOOGLE_REGISTRY_LOCATION }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This Workflow deploys a Docker image to Google Cloud Run | ||
|
||
name: On Release | ||
|
||
on: | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
build_gcp_image: | ||
name: Build Image for GCP | ||
uses: ./.github/workflows/build-gcp-image.yaml | ||
with: | ||
environment: production | ||
secrets: inherit | ||
|
||
deploy_to_cloud_run: | ||
name: Deploy to Cloud Run | ||
uses: ./.github/workflows/cloud-run-deploy.yaml | ||
needs: build_gcp_image | ||
with: | ||
environment: production | ||
version: ${{ needs.build_gcp_image.outputs.version }} | ||
service: dpgraham-server | ||
secrets: inherit | ||
|
||
build_ghcr_image: | ||
name: Build Image for GHCR | ||
uses: ./.github/workflows/build-ghcr-image.yaml | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { useTitle } from "components/hooks/useTitle"; | ||
|
||
export { useTitle }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { cleanup, fireEvent, render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
import { useTitle } from "components/hooks"; | ||
|
||
const originalPageTitle = "originalPageTitle"; | ||
const newPageTitle = "newPageTitle"; | ||
|
||
interface TestCompProps { | ||
prevailOnUnmount?: boolean; | ||
excludeAppend?: boolean; | ||
} | ||
|
||
function TestComponent({ prevailOnUnmount, excludeAppend }: TestCompProps) { | ||
const [pageTitle, setPageTitle] = useTitle( | ||
originalPageTitle, | ||
prevailOnUnmount, | ||
excludeAppend | ||
); | ||
return ( | ||
<> | ||
<p>Hello!</p> | ||
<button onClick={() => setPageTitle(newPageTitle)}>Change Title</button> | ||
<p>{pageTitle ? pageTitle : "undefined"}</p> | ||
</> | ||
); | ||
} | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
describe("useTitle", () => { | ||
it('sets the initial page title, plus " | David Paul Graham"', () => { | ||
render(<TestComponent />); | ||
expect(document.title).toContain(originalPageTitle); | ||
}); | ||
it("changes the page title", () => { | ||
render(<TestComponent />); | ||
fireEvent.click(screen.getByText(/Change Title/i)); | ||
expect(document.title).toContain(newPageTitle); | ||
}); | ||
it("The state is updated when the title is changed", () => { | ||
render(<TestComponent />); | ||
expect(screen.getByText(/undefined/i)).toBeInTheDocument(); | ||
fireEvent.click(screen.getByText(/Change Title/i)); | ||
expect(screen.getByText(newPageTitle)).toBeInTheDocument(); | ||
}); | ||
it("appends Global site title to each page title by default", () => { | ||
render(<TestComponent />); | ||
expect(document.title).toContain("David Paul Graham"); | ||
}); | ||
it("does not appends Global site title if specified", () => { | ||
render(<TestComponent excludeAppend={true} />); | ||
expect(document.title).not.toContain("David Paul Graham"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
/** | ||
* Hook to set document title | ||
* | ||
* @description Can be used to page the title dynamically or just once per page. | ||
* By default, it reset the title to the previous title when the component using this hook unmounts | ||
* @param title {string} | ||
* @param resetOnUnmount {boolean} | ||
* @param excludeSuffix {boolean} | ||
*/ | ||
export function useTitle( | ||
title: string, | ||
resetOnUnmount = false, | ||
excludeSuffix = false | ||
) { | ||
const defaultTitle = useRef(document.title); | ||
const [dynTitle, setDynTitle] = useState<string | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
document.title = `${title}${excludeSuffix ? "" : " | David Paul Graham"}`; | ||
}, [excludeSuffix, title]); | ||
|
||
useEffect(() => { | ||
if (typeof dynTitle === "string") | ||
document.title = `${dynTitle}${ | ||
excludeSuffix ? "" : " | David Paul Graham" | ||
}`; | ||
}, [dynTitle, excludeSuffix]); | ||
|
||
useEffect( | ||
// run on unmount | ||
() => () => { | ||
if (!resetOnUnmount) { | ||
document.title = defaultTitle.current; | ||
} | ||
}, | ||
[resetOnUnmount] | ||
); | ||
return [dynTitle, setDynTitle] as const; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters