Skip to content

Commit

Permalink
use Cloudflare Pages (#1035)
Browse files Browse the repository at this point in the history
* use cloudflare pages

* remove cf workers setup

* Get youtube api key from context env

* Update workflows

* Lets/try long url withnum 123214bers and stuff one two three (#1069)

* set slug-maxlength to 28 and use GITHUB_REF_SLUG_URL

* Use dist/client instead of public in previews

* api routes for dev server

---------

Co-authored-by: lorcan-codes <[email protected]>
  • Loading branch information
thecotne and lorcan-codes authored Jul 25, 2023
1 parent 9352528 commit dc05db4
Show file tree
Hide file tree
Showing 48 changed files with 203 additions and 311 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/netlify-cms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
jobs:
build-and-deploy:
name: Build and Deploy
environment: "netlify-cms"
environment:
name: Netlify CMS ${{ github.ref_name }}
url: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-netlify-cms.pages.dev
permissions:
contents: read
deployments: write
Expand Down Expand Up @@ -40,15 +42,15 @@ jobs:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
slug-maxlength: 40
slug-maxlength: 28

- name: Build Netlify CMS
run: yarn workspace @starknet-io/netlify-cms build
env:
VITE_LIVE_PREVIEW_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev
VITE_LIVE_PREVIEW_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev
VITE_GIT_BRANCH_NAME: ${{ github.ref_name }}
VITE_API_BASE_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev/api
VITE_DATA_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev/data
VITE_API_BASE_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev/api
VITE_DATA_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev/data

- name: Deploy Netlify CMS
uses: cloudflare/pages-action@1
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
jobs:
build-and-deploy:
name: Build and Deploy
environment: "storybook"
environment:
name: Storybook ${{ github.ref_name }}
url: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-storybook.pages.dev
permissions:
contents: read
deployments: write
Expand Down Expand Up @@ -37,6 +39,11 @@ jobs:
- name: Install dependencies
run: yarn

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
slug-maxlength: 28

- name: Build storybook
run: yarn workspace @starknet-io/storybook build-storybook

Expand Down
33 changes: 14 additions & 19 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Build and Deploy
environment:
name: Starknet Website ${{ github.ref_name }}
url: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev
url: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down Expand Up @@ -48,31 +48,26 @@ jobs:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
slug-maxlength: 40

- name: Create Env
run: echo -e "\n[env.${{ env.GITHUB_REF_SLUG }}]\n" >> workspaces/website/wrangler.toml

- name: Create secrets.json
run: echo '{"YOUTUBE_API_KEY":"${{ secrets.YOUTUBE_API_KEY }}"}' > workspaces/website/secrets.json

- name: Upload secrets
run: yarn workspace @starknet-io/website exec wrangler secret:bulk secrets.json --env ${{ env.GITHUB_REF_SLUG }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
slug-maxlength: 28

- name: Build project
run: yarn workspace @starknet-io/website build
env:
VITE_SITE_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev
VITE_SITE_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev
VITE_ALGOLIA_INDEX: ${{ github.ref_name == 'production' && 'production' || 'dev' }}
VITE_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
VITE_ALGOLIA_SEARCH_API_KEY: ${{ secrets.ALGOLIA_SEARCH_API_KEY }}
VITE_CF_STREAM_URL: ${{ secrets.CF_STREAM_URL }}

- name: Publish
run: yarn workspace @starknet-io/website exec wrangler publish --env ${{ env.GITHUB_REF_SLUG }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: starknet-website
directory: dist/client
workingDirectory: workspaces/website
wranglerVersion: '3'
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}

8 changes: 4 additions & 4 deletions workspaces/cms-data/src/announcements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export interface AnnouncementsPost extends Meta, AnnouncementDetails {

export async function getAnnouncementDetails(
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<AnnouncementDetails[]> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON(`data/announcements-details/${value}`, event)
(value) => async () => getJSON(`data/announcements-details/${value}`, context)
)
);
} catch (cause) {
Expand All @@ -33,12 +33,12 @@ export async function getAnnouncementDetails(
export async function getAnnouncementsPostBySlug(
locale: string,
slug: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<AnnouncementsPost> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON(`data/announcements/${value}/${slug}`, event)
(value) => async () => getJSON(`data/announcements/${value}/${slug}`, context)
)
);
} catch (cause) {
Expand Down
4 changes: 2 additions & 2 deletions workspaces/cms-data/src/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export interface Category {

export async function getCategories(
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<readonly Category[]> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON("data/categories/" + value, event)
(value) => async () => getJSON("data/categories/" + value, context)
)
);
} catch (cause) {
Expand Down
4 changes: 2 additions & 2 deletions workspaces/cms-data/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export interface Event {

export async function getEvents(
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<readonly Event[]> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON("data/events/" + value, event)
(value) => async () => getJSON("data/events/" + value, context)
)
);
} catch (cause) {
Expand Down
6 changes: 3 additions & 3 deletions workspaces/cms-data/src/getSharedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type SharedData = {
}
export async function getSharedData(
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"],
context: EventContext<{}, any, Record<string, unknown>>,
): Promise<SharedData> {
return getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON("data/shared-data/" + value, event)
(value) => async () => getJSON("data/shared-data/" + value, context)
)
);
}
}
10 changes: 5 additions & 5 deletions workspaces/cms-data/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export interface Page extends Meta {
const getPageWithRandomizedData = (data: Page): Page => {
const randomizedData = {...data}
randomizedData.blocks?.forEach((block: TopLevelBlock) => {

if (block.type === 'link_list' && block.randomize) {
//@ts-expect-error
block.blocks = getShuffledArray(block.blocks || []);
Expand All @@ -218,13 +218,13 @@ const getPageWithRandomizedData = (data: Page): Page => {
export async function getPageBySlug(
slug: string,
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<Page> {
try {
const data = await getFirst(
...[locale, defaultLocale].map(
(value) => async () =>
getJSON("data/pages/" + value + "/" + slug, event)
getJSON("data/pages/" + value + "/" + slug, context)
)
);

Expand All @@ -239,12 +239,12 @@ export async function getPageBySlug(
export async function getPageById(
id: string,
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<Page> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON("data/pages/" + value + "/" + id, event)
(value) => async () => getJSON("data/pages/" + value + "/" + id, context)
)
);
} catch (cause) {
Expand Down
8 changes: 4 additions & 4 deletions workspaces/cms-data/src/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export interface Post extends Meta {
export async function getPostBySlug(
slug: string,
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<Post> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () =>
getJSON("data/posts/" + value + "/" + slug, event)
getJSON("data/posts/" + value + "/" + slug, context)
),
async () => {
const client = algoliasearch(
Expand Down Expand Up @@ -70,12 +70,12 @@ export async function getPostBySlug(
export async function getPostById(
id: string | string[] | undefined,
locale: string | string[],
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<Post> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON("data/posts/" + value + "/" + id, event)
(value) => async () => getJSON("data/posts/" + value + "/" + id, context)
),
async () => {
const client = algoliasearch(
Expand Down
12 changes: 6 additions & 6 deletions workspaces/cms-data/src/roadmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export interface RoadmapVersion extends Meta {

export async function getRoadmapDetails(
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<readonly RoadmapDetails[]> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON(`data/roadmap-details/${value}`, event)
(value) => async () => getJSON(`data/roadmap-details/${value}`, context)
)
);
} catch (cause) {
Expand All @@ -43,12 +43,12 @@ export async function getRoadmapDetails(
export async function getRoadmapPostBySlug(
locale: string,
slug: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<RoadmapPost> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON(`data/roadmap-posts/${value}/${slug}`, event)
(value) => async () => getJSON(`data/roadmap-posts/${value}/${slug}`, context)
)
);
} catch (cause) {
Expand All @@ -60,12 +60,12 @@ export async function getRoadmapPostBySlug(

export async function getRoadmapVersions(
locale: string,
event: null | WorkerGlobalScopeEventMap["fetch"]
context: EventContext<{}, any, Record<string, unknown>>
): Promise<readonly RoadmapVersion[]> {
try {
return await getFirst(
...[locale, defaultLocale].map(
(value) => async () => getJSON("data/roadmap-versions/" + value, event)
(value) => async () => getJSON("data/roadmap-versions/" + value, context)
)
);
} catch (cause) {
Expand Down
Loading

0 comments on commit dc05db4

Please sign in to comment.