diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3816e52..c183b59 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,6 +16,41 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Check Required Secrets + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} + ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }} + OAUTH_ALLOWED_USERS: ${{ secrets.OAUTH_ALLOWED_USERS }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_D1_DATABASE_ID: ${{ secrets.CLOUDFLARE_D1_DATABASE_ID }} + run: | + REQUIRED_VARS=( + "JWT_SECRET" + "ENCRYPTION_KEY" + "OAUTH_ALLOWED_USERS" + "CLOUDFLARE_API_TOKEN" + "CLOUDFLARE_ACCOUNT_ID" + "CLOUDFLARE_D1_DATABASE_ID" + ) + + MISSING_VARS=() + for VAR in "${REQUIRED_VARS[@]}"; do + if [ -z "${!VAR}" ]; then + MISSING_VARS+=("$VAR") + fi + done + + if [ ${#MISSING_VARS[@]} -ne 0 ]; then + echo "❌ Error: The following required secrets are missing or empty:" + for VAR in "${MISSING_VARS[@]}"; do + echo " - $VAR" + done + echo "Please configure them in your repository's Settings > Secrets and variables > Actions." + exit 1 + fi + echo "✅ All required secrets are present." + - name: Setup Node.js uses: actions/setup-node@v4 with: @@ -46,9 +81,11 @@ jobs: CLOUDFLARE_D1_DATABASE_ID: ${{ secrets.CLOUDFLARE_D1_DATABASE_ID }} CLOUDFLARE_D1_DATABASE_NAME: ${{ secrets.CLOUDFLARE_D1_DATABASE_NAME || '2fauth-db' }} run: | - # 仅替换第一个匹配到的 database_id (对应生产环境配置),保留 dev 环境配置 - sed -i "0,/database_id =/s/database_id = \".*\"/database_id = \"$CLOUDFLARE_D1_DATABASE_ID\"/" "wrangler.toml" - sed -i "0,/database_name =/s/database_name = \".*\"/database_name = \"$CLOUDFLARE_D1_DATABASE_NAME\"/" "wrangler.toml" + sed -i '/^\[\[d1_databases\]\]/d; /^[[:space:]]*database_name[[:space:]]*=/d; /^[[:space:]]*database_id[[:space:]]*=/d' wrangler.toml + if grep -q "\[env.dev\]" wrangler.toml; then + sed -i '/\[env.dev\]/,$d' wrangler.toml + fi + printf "\n[[d1_databases]]\nbinding = \"DB\"\ndatabase_name = \"$CLOUDFLARE_D1_DATABASE_NAME\"\ndatabase_id = \"$CLOUDFLARE_D1_DATABASE_ID\"\n" >> wrangler.toml # 更新数据库结构 - name: Update Database Schema diff --git a/README.md b/README.md index 038c326..446627e 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,12 @@ 这是最省心的方式,完全不需要自己的服务器,由 Cloudflare 免费为你托管。 #### 1. 一键全自动部署 -[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/nap0o/2fauth-worker) +1. Fork 本项目仓库,发财小手点`Star`! ⭐ +2. 点击下方部署按钮
+[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://dash.cloudflare.com/?to=/:account/workers-and-pages/create) -#### 2. 注意事项与授权指引 -* 在部署向导中,你需要授权 Cloudflare 读取该仓库(系统会自动在你的 GitHub 账号下创建一个私有克隆)。 +#### 2. 授权指引 +* 在部署向导中,你需要授权 Cloudflare 读取该仓库。
点击查看:授权指引示意图 @@ -72,7 +74,19 @@
-#### 3. 添加如下变量和机密 +#### 3. 部署流程 +依次点击:Continue with GitHub -> 选择你 Fork 后的仓库(2fauth-worker)-> 下一步 -> 部署 -> 继续处理项目 -> 设置 + +
+点击查看:详细部署步骤示意图 +
+
+
+ + +
+ +#### 4. 在`设置`添加如下变量和机密 * `ENCRYPTION_KEY`:32位以上随机密钥。 * `JWT_SECRET`:32位以上随机JWT密钥。 * `OAUTH_ALLOWED_USERS`:你的邮箱@example.com diff --git a/README_EN.md b/README_EN.md index 3facc11..569d6bb 100644 --- a/README_EN.md +++ b/README_EN.md @@ -62,10 +62,12 @@ Whether you're leveraging Cloudflare's free tier or deploying on your own NAS/mi The most hassle-free way. No server required; Cloudflare hosts it for you for free. #### 1. One-click Auto Deploy -[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/nap0o/2fauth-worker) +1. Fork this repository, and give it a `Star`! ⭐ +2. Click the deploy button below
+[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://dash.cloudflare.com/?to=/:account/workers-and-pages/create) #### 2. Notes & Authorization -* During the deployment wizard, you'll need to authorize Cloudflare to read this repository (it will automatically create a private fork in your account). +* In the deployment wizard, you need to authorize Cloudflare to read this repository.
Click to view: Authorization Guide Diagrams @@ -74,7 +76,19 @@ The most hassle-free way. No server required; Cloudflare hosts it for you for fr
-#### 3. Add the following Variables and Secrets +#### 3. Deployment Flow +Click in sequence: Continue with GitHub -> Select your forked repository (2fauth-worker) -> Next -> Deploy -> Continue to project -> Settings + +
+Click to view: Detailed deployment steps diagram +
+
+
+ + +
+ +#### 4. Add the following Variables and Secrets in `Settings` * `ENCRYPTION_KEY`: A random key with at least 32 characters. * `JWT_SECRET`: A random JWT secret with at least 32 characters. * `OAUTH_ALLOWED_USERS`: your_email@example.com diff --git a/wrangler.demo.toml b/wrangler.demo.toml index 250e8d6..6a24c93 100644 --- a/wrangler.demo.toml +++ b/wrangler.demo.toml @@ -14,7 +14,6 @@ command = "npm run build --prefix frontend" [[d1_databases]] binding = "DB" database_name = "2fauth-db-demo" -database_id = "082530be-db1b-4346-b4f2-dbeeb6305c51" [triggers] crons = ["0 2 * * *"] diff --git a/wrangler.dev.toml b/wrangler.dev.toml index 2e591c2..7308bec 100644 --- a/wrangler.dev.toml +++ b/wrangler.dev.toml @@ -15,7 +15,6 @@ not_found_handling = "single-page-application" [build] command = "npm run build --prefix ../frontend" - [[d1_databases]] binding = "DB" database_name = "2fauth-db-dev" diff --git a/wrangler.toml b/wrangler.toml index 1683be2..5c0d76f 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -14,7 +14,6 @@ command = "npm run build --prefix frontend" [[d1_databases]] binding = "DB" database_name = "2fauth-db" -database_id = "9e591736-5dbb-4f09-8769-0270d7257731" [triggers] crons = ["0 2 * * *"] @@ -23,4 +22,4 @@ crons = ["0 2 * * *"] [[env.dev.d1_databases]] binding = "DB" database_name = "2fauth-db-dev" -database_id = "9e591736-5dbb-4f09-8769-0270d7257731" \ No newline at end of file +database_id = "9e591736-5dbb-4f09-8769-0270d7257731"