From 0cc0a11d9de367fe1ee2b7d231d1d614bc1c83d2 Mon Sep 17 00:00:00 2001 From: bishsh Date: Tue, 12 Aug 2025 12:31:39 +0800 Subject: [PATCH 1/4] Create main.yml --- .github/workflows/main.yml | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..11c9e54 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,65 @@ +name: 自动部署 + +on: + push: + branches: + - main + + release: + types: + - published + + workflow_dispatch: + +env: + TZ: Asia/Shanghai + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: 检查分支 + uses: actions/checkout@v3 + with: + ref: main + + - name: 缓存项目 npm 包 + id: cache-node-modules + uses: actions/cache@v3 + with: + path: node_modules + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-nodeModules- + + - name: 安装 Node + uses: actions/setup-node@v3 + with: + node-version: "20.x" + + - name: 安装 Hexo + run: | + npm install hexo-cli --global + + - name: 安装依赖 + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: | + npm install + + - name: 清理文件树 + run: | + npm run clean + + - name: 生成静态文件并压缩 + run: | + npm run build + + - name: 部署 + run: | + cd ./public + git init + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor }}@users.noreply.github.com" + git add . + git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]" + git push --force --quiet "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" master:page From 05ea09100c3863b3bd2c4cdcd533d4ae6e2acfbb Mon Sep 17 00:00:00 2001 From: bishsh Date: Tue, 12 Aug 2025 13:00:26 +0800 Subject: [PATCH 2/4] Update main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11c9e54..8fb127f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,7 @@ jobs: uses: actions/checkout@v3 with: ref: main + token: ${{ secrets.GITHUB_TOKEN }} - name: 缓存项目 npm 包 id: cache-node-modules From 155d360383cd9eec7df3f144e41d9e36955a3cb2 Mon Sep 17 00:00:00 2001 From: bishsh Date: Tue, 12 Aug 2025 13:14:03 +0800 Subject: [PATCH 3/4] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fb127f..68de42f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - name: 检查分支 uses: actions/checkout@v3 with: - ref: main + ref: master token: ${{ secrets.GITHUB_TOKEN }} - name: 缓存项目 npm 包 From 1ec4e64303b03b3c0061de234678eea1df5cab86 Mon Sep 17 00:00:00 2001 From: bishsh Date: Tue, 12 Aug 2025 15:14:33 +0800 Subject: [PATCH 4/4] Update main.yml --- .github/workflows/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68de42f..ec583a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,3 +64,18 @@ jobs: git add . git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]" git push --force --quiet "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" master:page + - name: 服务器执行拉取命令 + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + port: ${{ secrets.PORT }} + script: | + cd /opt/1panel/www/sites/blog.biss.click/index/ + git config --global --add safe.directory "$(pwd)" + git fetch --all --depth=1 + git reset --hard origin/main + git pull --depth=1 + echo "✅ 已拉取 page 分支最新内容"