aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangcat_Dev <f20091219@outlook.com>2026-08-17 11:06:55 +0000
committerFangcat_Dev <f20091219@outlook.com>2026-08-17 11:06:55 +0000
commit163424e241b082a59408a6a1f17af9c72dae1a1a (patch)
treec0d1d28f8c6d0be775528446e3e18c6a259dc7a4
parentfixed format (diff)
feat: preview for pull requests
-rw-r--r--.forgejo/workflows/mkdocs-deploy.yml24
1 files changed, 23 insertions, 1 deletions
diff --git a/.forgejo/workflows/mkdocs-deploy.yml b/.forgejo/workflows/mkdocs-deploy.yml
index cc13ac6..f56c558 100644
--- a/.forgejo/workflows/mkdocs-deploy.yml
+++ b/.forgejo/workflows/mkdocs-deploy.yml
@@ -54,4 +54,26 @@ jobs:
git config user.email "f20091219@outlook.com"
git add .
git commit -m "Deploy site $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
- git push --force "https://Fangcat_Dev:${DEPLOY_TOKEN}@codeberg.org/LinuxCabin/handbook-site.git" HEAD:pages \ No newline at end of file
+ git push --force "https://Fangcat_Dev:${DEPLOY_TOKEN}@codeberg.org/LinuxCabin/handbook-site.git" HEAD:pages
+ - name: Deploy to preview
+ if: github.event_name == 'pull_request'
+ env:
+ DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
+ run: |
+ cd site
+
+ # 获取 PR 信息与构建时间
+ PR_NUMBER="${{ github.event.pull_request.number }}"
+ PR_AUTHOR="${{ github.event.pull_request.user.login }}"
+ BUILD_TIME="$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
+
+ # 在 <body> 标签后插入横幅(保留原有属性)
+ sed -i "s/<body\([^>]*\)>/<body\1><div style=\"background-color:#f8d7da; color:#721c24; padding:10px; text-align:center; border-bottom:1px solid #f5c6cb;\">Preview: PR #${PR_NUMBER} by ${PR_AUTHOR} | Built: ${BUILD_TIME}<\/div>/" index.html
+
+ echo "preview.hb.linuxcabin.top" > CNAME
+ git init
+ git config user.name "Fangcat_Dev"
+ git config user.email "f20091219@outlook.com"
+ git add .
+ git commit -m "Deploy site $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
+ git push --force "https://Fangcat_Dev:${DEPLOY_TOKEN}@codeberg.org/LinuxCabin/handbook-preview.git" HEAD:pages \ No newline at end of file