-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action to deploy automatically
- Loading branch information
Showing
7 changed files
with
102 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
name: Deploy | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Setup R2-Explorer | ||
run: node packages/github-action/prepareDeploy.js | ||
with: | ||
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | ||
- name: Deploy | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CF_API_TOKEN }} |
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
4 changes: 2 additions & 2 deletions
4
packages/r2-explorer-demo/package-lock.json → packages/github-action/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/r2-explorer-demo/package.json → packages/github-action/package.json
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,73 @@ | ||
// @ts-ignore | ||
const fs = require("fs"); | ||
|
||
const R2EXPLORER_WORKER_NAME = process.env.R2EXPLORER_WORKER_NAME; | ||
const R2EXPLORER_BUCKETS = process.env.R2EXPLORER_BUCKETS; | ||
const R2EXPLORER_CONFIG = process.env.R2EXPLORER_CONFIG; | ||
const R2EXPLORER_DOMAIN = process.env.R2EXPLORER_DOMAIN; | ||
const CF_API_TOKEN = process.env.CF_API_TOKEN; | ||
|
||
if (!R2EXPLORER_WORKER_NAME) { | ||
console.error("R2EXPLORER_WORKER_NAME variable is required to continue!"); | ||
process.exit(1); | ||
} | ||
|
||
if (!R2EXPLORER_BUCKETS) { | ||
console.error("R2EXPLORER_BUCKETS variable is required to continue!"); | ||
process.exit(1); | ||
} | ||
|
||
if (!R2EXPLORER_CONFIG) { | ||
console.error("R2EXPLORER_CONFIG variable is required to continue!"); | ||
process.exit(1); | ||
} | ||
|
||
if (!CF_API_TOKEN) { | ||
console.error("CF_API_TOKEN variable is required to continue!"); | ||
process.exit(1); | ||
} | ||
|
||
let wranglerConfig = ` | ||
name = "${R2EXPLORER_WORKER_NAME}" | ||
compatibility_date = "2023-05-12" | ||
main = "src/index.ts" | ||
`; | ||
|
||
if (R2EXPLORER_DOMAIN) { | ||
wranglerConfig += ` | ||
workers_dev = false | ||
routes = [ | ||
{ pattern = "${R2EXPLORER_DOMAIN}", custom_domain = true } | ||
] | ||
`; | ||
} else { | ||
wranglerConfig += ` | ||
workers_dev = true | ||
`; | ||
} | ||
|
||
for (const bucket of R2EXPLORER_BUCKETS.split("\n")) { | ||
const split = bucket.split(":"); | ||
if (split.length !== 2) { | ||
console.error("R2EXPLORER_BUCKETS is not set correctly!"); | ||
console.error(`"${split}" is not in the correct format`); | ||
process.exit(1); | ||
} | ||
|
||
wranglerConfig += ` | ||
[[r2_buckets]] | ||
binding = '${split[0]}' | ||
bucket_name = '${split[1]}' | ||
preview_bucket_name = '${split[1]}' | ||
`; | ||
|
||
} | ||
|
||
fs.writeFileSync("wrangler.toml", wranglerConfig); | ||
|
||
|
||
fs.writeFileSync("src/index.ts", ` | ||
import { R2Explorer } from "r2-explorer"; | ||
export default R2Explorer(${R2EXPLORER_CONFIG}); | ||
`); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.