Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github action to deploy automatically #37

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/deploy.yml
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 }}
8 changes: 0 additions & 8 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,3 @@ node config/preparePublish.js
npm run build
npm publish --access public
```


## Deploy demo instance

```bash
cd packages/r2-explorer-demo/
wrangler deploy
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "r2-explorer-demo",
"name": "r2-explorer-github-action",
"version": "0.0.1",
"private": true,
"devDependencies": {
Expand Down
73 changes: 73 additions & 0 deletions packages/github-action/prepareDeploy.js
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});
`);
7 changes: 0 additions & 7 deletions packages/r2-explorer-demo/src/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/r2-explorer-demo/wrangler.toml

This file was deleted.