mirror of
https://github.com/katelya77/K-Vault.git
synced 2026-05-07 06:22:03 +08:00
feat: 增强 Cloudflare Pages 部署工作流,添加秘密验证步骤
This commit is contained in:
37
.github/workflows/pages-deploy.yml
vendored
37
.github/workflows/pages-deploy.yml
vendored
@@ -11,13 +11,34 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
if: ${{ secrets.CF_API_TOKEN != '' && secrets.CF_ACCOUNT_ID != '' && secrets.CF_PAGES_PROJECT != '' }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
|
||||
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
CF_PAGES_PROJECT: ${{ secrets.CF_PAGES_PROJECT }}
|
||||
steps:
|
||||
- name: Validate Cloudflare secrets
|
||||
id: validate
|
||||
shell: bash
|
||||
run: |
|
||||
missing=()
|
||||
[ -n "$CF_API_TOKEN" ] || missing+=("CF_API_TOKEN")
|
||||
[ -n "$CF_ACCOUNT_ID" ] || missing+=("CF_ACCOUNT_ID")
|
||||
[ -n "$CF_PAGES_PROJECT" ] || missing+=("CF_PAGES_PROJECT")
|
||||
|
||||
if [ "${#missing[@]}" -gt 0 ]; then
|
||||
echo "ready=false" >> "$GITHUB_OUTPUT"
|
||||
echo "::warning::Skipping Pages deploy. Missing secrets: ${missing[*]}"
|
||||
else
|
||||
echo "ready=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Checkout
|
||||
if: ${{ steps.validate.outputs.ready == 'true' }}
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
if: ${{ steps.validate.outputs.ready == 'true' }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
@@ -25,24 +46,32 @@ jobs:
|
||||
cache-dependency-path: frontend/package-lock.json
|
||||
|
||||
- name: Install frontend deps
|
||||
if: ${{ steps.validate.outputs.ready == 'true' }}
|
||||
run: npm --prefix frontend ci
|
||||
|
||||
- name: Build frontend dist
|
||||
if: ${{ steps.validate.outputs.ready == 'true' }}
|
||||
run: npm --prefix frontend run build
|
||||
|
||||
- name: Verify dist output
|
||||
if: ${{ steps.validate.outputs.ready == 'true' }}
|
||||
run: |
|
||||
test -f frontend/dist/index.html
|
||||
test -f frontend/dist/app/index.html
|
||||
test -f frontend/dist/_redirects
|
||||
|
||||
- name: Deploy to Cloudflare Pages with Wrangler
|
||||
if: ${{ steps.validate.outputs.ready == 'true' }}
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
apiToken: ${{ env.CF_API_TOKEN }}
|
||||
accountId: ${{ env.CF_ACCOUNT_ID }}
|
||||
command: >
|
||||
pages deploy frontend/dist
|
||||
--project-name=${{ secrets.CF_PAGES_PROJECT }}
|
||||
--project-name=${{ env.CF_PAGES_PROJECT }}
|
||||
--branch=${{ github.ref_name }}
|
||||
--functions=functions
|
||||
|
||||
- name: Skip notice
|
||||
if: ${{ steps.validate.outputs.ready != 'true' }}
|
||||
run: echo "Cloudflare Pages deploy skipped because required secrets are missing."
|
||||
|
||||
Reference in New Issue
Block a user