diff --git a/.github/workflows/deploy-static.yml b/.github/workflows/deploy-static.yml index e959b00..a5b7a14 100644 --- a/.github/workflows/deploy-static.yml +++ b/.github/workflows/deploy-static.yml @@ -20,8 +20,6 @@ jobs: runs-on: ubuntu-latest env: - DEPLOY_ENV: "CDN" - CDN_BASEURL: "https://cdn.jsdelivr.net/gh/scarletborder/bloggerv2@static/" API_ENDPOINT: "https://blog.scarletborder.cn" steps: @@ -45,12 +43,26 @@ jobs: run: pnpm install --frozen-lockfile - name: Build project - run: pnpm run build + run: DEPLOY_ENV='CDN' pnpm run build + + - name: Deploy to static branch and get commit hash + id: deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./dist + publish_branch: static + force_orphan: true + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" + commit_message: "Deploy static assets from release branch" - name: Find built assets and generate report id: generate-report run: | - CDN_BASE="${{ env.CDN_BASEURL }}" + COMMIT_HASH="${{ steps.deploy.outputs.commit_hash }}" + CDN_BASE="https://cdn.jsdelivr.net/gh/${{ github.repository }}@${COMMIT_HASH}/" + echo "Generated CDN Base URL: ${CDN_BASE}" REPORT_FILE="build_report.txt" # 清空报告文件,以便重新写入 @@ -74,6 +86,14 @@ jobs: echo "" >> "$REPORT_FILE" done + echo "--- Injecting global __CDN_URL__ variable ---" + # 使用 cat <> "$REPORT_FILE" + + EOF + echo "--- Build Report Generated ---" cat "$REPORT_FILE" @@ -98,24 +118,3 @@ jobs: else echo "branch_exists=false" >> $GITHUB_OUTPUT fi - - - name: Create static branch if not exists - if: steps.check-branch.outputs.branch_exists == 'false' - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git checkout --orphan static - git reset --hard - git commit --allow-empty -m "Initial commit for static branch" - git push origin static - - - name: Deploy to static branch - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./dist - publish_branch: static - force_orphan: true - user_name: "github-actions[bot]" - user_email: "github-actions[bot]@users.noreply.github.com" - commit_message: "Deploy static assets from release branch" diff --git a/eslint.config.js b/eslint.config.js index ec943c2..82a4498 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,6 +8,7 @@ import tencentEslintConfig from 'eslint-config-tencent/flat'; const GlobalConstants = { __API_ENDPOINT__: 'readonly', + __CDN_URL__: 'readonly', }; export default tseslint.config([ diff --git a/index.html b/index.html index fc8beef..73756a2 100644 --- a/index.html +++ b/index.html @@ -37,10 +37,7 @@ color: #212529 !important; } - + -