Skip to content

Commit

Permalink
Add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 committed Sep 2, 2023
1 parent 5864b2e commit 97cd40d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Deploy worker (prod)

on:
workflow_dispatch:

jobs:
deploy-prod:
runs-on: ubuntu-latest
steps:
- name: Code checkout
uses: actions/checkout@v2
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: deploy --env prod
18 changes: 18 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy worker (staging)

on:
push:
branches:
- main

jobs:
deploy-staging:
runs-on: ubuntu-latest
steps:
- name: Code checkout
uses: actions/checkout@v2
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
command: deploy --env staging
22 changes: 22 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Format

on:
pull_request:
branches: [ main ]

jobs:
format-ts:
runs-on: ubuntu-latest
steps:
- name: Code checkout
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/workflows/prettier.yml') }}
restore-keys: ${{ runner.os }}-npm-
- name: Install dependencies
run: npm install
- name: Run Prettier
run: npm run check-format
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"deploy:staging": "wrangler deploy -e staging",
"deploy:prod": "wrangler deploy -e prod",
"start": "wrangler dev",
"format": "prettier -u --write \"**/*.{ts,json}\""
"format": "prettier -u --write \"**/*.{ts,js,json}\"",
"check-format": "prettier -u --check \"**/*.{ts,js,json}\""
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230419.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/origin/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ENDPOINT=https://$1.r2.cloudflarestorage.com
DIST=/home/dist/

aws s3 sync $DIST s3://node-poc-dev/ --endpoint-url=$ENDPOINT --profile staging
aws s3 sync $DIST s3://node-poc-staging/ --endpoint-url=$ENDPOINT --profile staging
aws s3 sync $DIST s3://node-poc-prod/ --endpoint-url=$ENDPOINT --profile prod

if [[ -v DIST_WORKER_API_KEY ]];
Expand Down
6 changes: 4 additions & 2 deletions scripts/rotate-api-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

const { randomUUID } = require('crypto');

console.log(`New api key: ${randomUUID()}`)
console.log('Now, run `wrangler secrets put PURGE_API_KEY` and enter it in the prompt.')
console.log(`New api key: ${randomUUID()}`);
console.log(
'Now, run `wrangler secrets put PURGE_API_KEY` and enter it in the prompt.'
);
45 changes: 44 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ name = "node-dist-worker-poc"
main = "src/worker.ts"
compatibility_date = "2023-08-07"

# Dev (default)
[vars]
DIRECTORY_LISTING = 'restricted'
workers_dev = true
ENVIRONMENT = 'dev'
DIRECTORY_LISTING = 'on'
CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400'
DIRECTORY_CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400'
COMMONLY_UPDATED_PATHS = [
Expand All @@ -16,4 +19,44 @@ COMMONLY_UPDATED_PATHS = [
[[r2_buckets]]
binding = "R2_BUCKET"
preview_bucket_name = "node-poc-dev"
bucket_name = "node-poc-dev"

# Staging
[env.staging]
[env.staging.vars]
workers_dev = true
ENVIRONMENT = 'staging'
DIRECTORY_LISTING = 'restricted'
CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400'
DIRECTORY_CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400'
COMMONLY_UPDATED_PATHS = [
'/dist',
'/dist/',
'/dist/latest',
'/dist/latest/',
]

[[env.staging.r2_buckets]]
binding = "R2_BUCKET"
preview_bucket_name = "node-poc-dev"
bucket_name = "node-poc-staging"

# Prod
[env.prod]
[env.prod.vars]
workers_dev = true # for now we're using a workers.dev domain
ENVIRONMENT = 'prod'
DIRECTORY_LISTING = 'restricted'
CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400'
DIRECTORY_CACHE_CONTROL = 'public, max-age=3600, s-maxage=14400'
COMMONLY_UPDATED_PATHS = [
'/dist',
'/dist/',
'/dist/latest',
'/dist/latest/',
]

[[env.prod.r2_buckets]]
binding = "R2_BUCKET"
preview_bucket_name = "node-poc-prod"
bucket_name = "node-poc-prod"

0 comments on commit 97cd40d

Please sign in to comment.