Skip to content

Commit

Permalink
update dependencies, add dependabot, remove gatsby cloud build button…
Browse files Browse the repository at this point in the history
…, add cloudflare worker build, add PR checks
  • Loading branch information
CiotkaCierpienia committed Apr 18, 2024
1 parent 9ae7211 commit 03d32ba
Show file tree
Hide file tree
Showing 9 changed files with 3,292 additions and 4,371 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: '/'
schedule:
interval: 'weekly'
36 changes: 36 additions & 0 deletions .github/workflows/cloudflare_worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy Cloudflare Worker
on:
repository_dispatch:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js {{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Check if Flotiq API key is set.
env:
GATSBY_FLOTIQ_API_KEY: ${{ secrets.GATSBY_FLOTIQ_API_KEY }}
run: |
if [ -z "$GATSBY_FLOTIQ_API_KEY" ]; then
echo "Flotiq API Key is not set, using a starter one." && echo "GATSBY_FLOTIQ_API_KEY=74df34da6d8fd27cfc04c35f995a57d4" >> $GITHUB_ENV
else
echo "Using user-provided Flotiq API Key. Importing starter data to Flotiq." && echo "GATSBY_FLOTIQ_API_KEY=$GATSBY_FLOTIQ_API_KEY" >> $GITHUB_ENV
npm install -g flotiq-cli
flotiq import . $GATSBY_FLOTIQ_API_KEY
fi
- run: npm install -g gatsby-cli
- run: yarn install
- run: gatsby build
- name: Build & Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
45 changes: 45 additions & 0 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PR workflow
on: pull_request

permissions:
pull-requests: write

jobs:
test-build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x ]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install -g gatsby-cli
- run: npm install -g flotiq-cli
- run: flotiq import . ${{ secrets.GATSBY_FLOTIQ_API_KEY }}
- run: yarn install
- run: gatsby build
env:
GATSBY_FLOTIQ_API_KEY: ${{ secrets.GATSBY_FLOTIQ_API_KEY }}
SNIPCART_API_KEY: 'test'
GA_MEASUREMENT_ID: ''
dependabot:
needs: test-build
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
8 changes: 6 additions & 2 deletions .github/workflows/test.yml → .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: test-build
on: push
name: Push workflow
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -22,4 +25,5 @@ jobs:
- run: gatsby build
env:
GATSBY_FLOTIQ_API_KEY: ${{ secrets.GATSBY_FLOTIQ_API_KEY }}
SNIPCART_API_KEY: 'test'
GA_MEASUREMENT_ID: ''
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,23 @@ This project works on node >=18.0.0, as require Gatsby 5.
## Deploy
Deploy this starter with one click on [Gatsby Cloud](https://www.gatsbyjs.com/cloud/):
[<img src="https://www.gatsbyjs.com/deploynow.svg" alt="Deploy to Gatsby Cloud">](https://www.gatsbyjs.com/dashboard/deploynow?url=https://github.com/flotiq/gatsby-starter-boilerplate)
You can also deploy this project to [Heroku](https://www.heroku.com/) in 3 minutes:
Deploy his project to [Heroku](https://www.heroku.com/) in 3 minutes:
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/flotiq/gatsby-starter-boilerplate)
Or to [Netlify](https://www.netlify.com/):
[![Deploy](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/flotiq/gatsby-starter-boilerplate)
Or to [Cloudflare Workers](https://workers.cloudflare.com/):
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/flotiq/flotiq-gatsby-shop-1)
### Note
Cloudflare Workers deployment uses Flotiq starter API key, if you want to deploy a worker with your own Flotiq API key, after deployment go to your forked repository on GitHub and add a GATSBY_FLOTIQ_API secret in repository's settings, then in Actions, select "Deploy Cloudflare Worker" workflow and click "Run workflow" to deploy the worker again.
More information about GitHub secrets can be found [here](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
## What's inside?
Expand Down
72 changes: 36 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,53 @@
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"@fontsource/inter": "^4.5.4",
"@headlessui/react": "^1.4.2",
"@heroicons/react": "^1.0.5",
"@popperjs/core": "^2.11.0",
"flotiq-components-react": "^1.0.0",
"gatsby": "^5.3.3",
"gatsby-plugin-google-gtag": "^5.3.0",
"gatsby-plugin-image": "^3.3.2",
"gatsby-plugin-manifest": "^5.3.1",
"gatsby-plugin-react-helmet": "^6.3.0",
"@fontsource/inter": "^5.0.17",
"@headlessui/react": "^1.7.19",
"@heroicons/react": "1.0.6",
"@popperjs/core": "^2.11.8",
"flotiq-components-react": "^1.1.5",
"gatsby": "^5.13.4",
"gatsby-plugin-google-gtag": "^5.13.1",
"gatsby-plugin-image": "^3.13.1",
"gatsby-plugin-manifest": "^5.13.1",
"gatsby-plugin-react-helmet": "^6.13.1",
"gatsby-plugin-robots-txt": "^1.8.0",
"gatsby-plugin-sharp": "^5.3.2",
"gatsby-plugin-sitemap": "^6.3.1",
"gatsby-source-filesystem": "^5.3.1",
"gatsby-source-flotiq": "^5.0.0",
"gatsby-transformer-sharp": "^5.3.1",
"gatsby-plugin-sharp": "^5.13.1",
"gatsby-plugin-sitemap": "^6.13.1",
"gatsby-source-filesystem": "^5.13.1",
"gatsby-source-flotiq": "^5.2.0",
"gatsby-transformer-sharp": "^5.13.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"typescript": "^4.5.5",
"webpack": "^5.85.0"
"typescript": "^5.4.5",
"webpack": "^5.91.0"
},
"devDependencies": {
"@babel/core": "^7.17.4",
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-syntax-flow": "^7.16.7",
"@babel/plugin-transform-react-jsx": "^7.17.3",
"@babel/preset-react": "^7.16.7",
"@babel/core": "^7.24.4",
"@babel/eslint-parser": "^7.24.1",
"@babel/plugin-syntax-flow": "^7.24.1",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/preset-react": "^7.24.1",
"@hot-loader/react-dom": "17.0.2",
"@typescript-eslint/parser": "^5.12.0",
"autoprefixer": "^10.4.2",
"@typescript-eslint/parser": "^7.7.0",
"autoprefixer": "^10.4.19",
"babel-eslint": "^10.1.0",
"cross-env": "^7.0.3",
"dotenv": "^16.0.0",
"eslint": "^8.9.0",
"dotenv": "^16.4.5",
"eslint": "^9.0.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-react-app": "^7.0.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx": "^0.1.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"gatsby-plugin-postcss": "^6.3.0",
"postcss": "^8.4.6",
"prettier": "^2.5.1",
"tailwindcss": "^3.0.23"
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"gatsby-plugin-postcss": "^6.13.1",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.3"
},
"repository": {
"type": "git",
Expand All @@ -71,6 +71,6 @@
"url": "https://github.com/flotiq/gatsby-starter-boilerplate/issues"
},
"resolutions": {
"webpack": "^5.85.0"
"webpack": "^5.91.0"
}
}
80 changes: 80 additions & 0 deletions worker-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'

/**
* The DEBUG flag will do two things that help during development:
* 1. we will skip caching on the edge, which makes it easier to
* debug.
* 2. we will return an error message on exception in your Response rather
* than the default 404.html page.
*/
const DEBUG = false

addEventListener('fetch', event => {
try {
event.respondWith(handleEvent(event))
} catch (e) {
if (DEBUG) {
return event.respondWith(
new Response(e.message || e.toString(), {
status: 500,
}),
)
}
event.respondWith(new Response('Internal Error', { status: 500 }))
}
})

async function handleEvent(event) {
const url = new URL(event.request.url)
let options = {}

/**
* You can add custom logic to how we fetch your assets
* by configuring the function `mapRequestToAsset`
*/
// options.mapRequestToAsset = handlePrefix(/^\/docs/)

try {
if (DEBUG) {
// customize caching
options.cacheControl = {
bypassCache: true,
}
}
return await getAssetFromKV(event, options)
} catch (e) {
// if an error is thrown try to serve the asset at 404.html
if (!DEBUG) {
try {
let notFoundResponse = await getAssetFromKV(event, {
mapRequestToAsset: req => new Request(`${new URL(req.url).origin}/404.html`, req),
})

return new Response(notFoundResponse.body, { ...notFoundResponse, status: 404 })
} catch (e) {}
}

return new Response(e.message || e.toString(), { status: 500 })
}
}

/**
* Here's one example of how to modify a request to
* remove a specific prefix, in this case `/docs` from
* the url. This can be useful if you are deploying to a
* route on a zone, or if you only want your static content
* to exist at a specific path.
*/
function handlePrefix(prefix) {
return request => {
// compute the default (e.g. / -> index.html)
let defaultAssetKey = mapRequestToAsset(request)
let url = new URL(defaultAssetKey.url)

// strip the prefix from the path for lookup
url.pathname = url.pathname.replace(prefix, '/')

// inherit all other props from the default request
return new Request(url.toString(), defaultAssetKey)
}
}
7 changes: 7 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "flotiq-gatsby-shop-1"
main = "worker-index.js"
compatibility_date = "2024-03-27"
workers_dev = true

[site]
bucket = "./public"
Loading

0 comments on commit 03d32ba

Please sign in to comment.