Compare commits
6 Commits
v1.0.2
...
6d590673ae
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d590673ae | |||
| 89c7782768 | |||
| 59bbda7189 | |||
| 1c87a56081 | |||
| a4902897dd | |||
| 1af468c2ff |
@@ -1,36 +1,48 @@
|
|||||||
name: 发布-云端
|
name: 发布-云端
|
||||||
# 审核 = 人工决定打不打 tag:push v* 标签即发布公网
|
# 审核 = 人工在 Gitea Actions 点 Run workflow,填入已推送的 tag 版本 → 部署公网
|
||||||
# 发布历史 = git tag 列表(git tag -l 'v*'),发布版本号 = tag 名
|
# 发布历史 = git tag 列表(git tag -l 'v*'),发布版本号 = tag 名
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_dispatch:
|
||||||
tags: ['v*']
|
inputs:
|
||||||
|
version:
|
||||||
|
description: '发布版本(已推送的 tag,如 v1.0.4)'
|
||||||
|
required: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: build-runner
|
runs-on: build-runner
|
||||||
|
env:
|
||||||
|
VERSION: ${{ inputs.version }}
|
||||||
steps:
|
steps:
|
||||||
|
- name: 校验版本号
|
||||||
|
run: |
|
||||||
|
if ! printf '%s' "$VERSION" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||||
|
echo "❌ 版本号格式应为 vX.Y.Z,例如 v1.0.4"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: 拉取代码(tag 版本)
|
- name: 拉取代码(tag 版本)
|
||||||
run: |
|
run: |
|
||||||
git clone --depth 1 --branch "${GITHUB_REF_NAME}" "http://dafe:${{ secrets.GITHUB_TOKEN }}@192.168.51.66:3000/dafe/homepage.git" site
|
git clone --depth 1 --branch "$VERSION" "http://dafe:${{ secrets.GITHUB_TOKEN }}@192.168.51.66:3000/dafe/homepage.git" site
|
||||||
|
|
||||||
- name: 注入发布版本号(缓存击穿,版本=tag 名)
|
- name: 注入发布版本号(缓存击穿,版本=tag 名)
|
||||||
run: |
|
run: |
|
||||||
cd site
|
cd site
|
||||||
sed -i "s/?v=[0-9]*/?v=${GITHUB_REF_NAME}/g" index.html
|
sed -i "s/?v=[0-9]*/?v=${VERSION}/g" index.html
|
||||||
|
|
||||||
- name: 发布到 ubuntu3(公网 www.shashann.com)
|
- name: 发布到 ubuntu2(阿里云正式机,公网 www.shashann.com)
|
||||||
env:
|
env:
|
||||||
DEPLOY_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
DEPLOY_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
||||||
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/id_ed25519
|
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/id_ed25519
|
||||||
chmod 600 ~/.ssh/id_ed25519
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
ssh-keyscan -H 124.222.157.76 >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -H 101.133.145.181 >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
cd site
|
cd site
|
||||||
ssh ubuntu@124.222.157.76 'mkdir -p /var/www/shashann-homepage && find /var/www/shashann-homepage -mindepth 1 -maxdepth 1 -exec rm -rf {} +'
|
ssh root@101.133.145.181 'mkdir -p /var/www/shashann-homepage && find /var/www/shashann-homepage -mindepth 1 -maxdepth 1 -exec rm -rf {} +'
|
||||||
tar czf - index.html assets robots.txt sitemap.xml llms.txt | ssh ubuntu@124.222.157.76 'tar xzf - -C /var/www/shashann-homepage'
|
tar czf - index.html assets robots.txt sitemap.xml llms.txt | ssh root@101.133.145.181 'tar xzf - -C /var/www/shashann-homepage'
|
||||||
|
|
||||||
- name: 上线验证
|
- name: 上线验证
|
||||||
run: |
|
run: |
|
||||||
curl -s -f -o /dev/null --resolve www.shashann.com:443:124.222.157.76 https://www.shashann.com/ || { echo "❌ 公网验证失败"; exit 1; }
|
curl -s -f -o /dev/null --noproxy '*' --resolve www.shashann.com:443:101.133.145.181 https://www.shashann.com/ || { echo "❌ 公网验证失败"; exit 1; }
|
||||||
echo "✅ 云端已发布 ${GITHUB_REF_NAME} $(date '+%H:%M:%S')"
|
echo "✅ 云端已发布 ${VERSION} $(date '+%H:%M:%S')"
|
||||||
|
|||||||
29
tools/finish-feature.sh
Executable file
29
tools/finish-feature.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# 在 feature 分支上执行:合并到 main、推送、删除本地和远端分支
|
||||||
|
# 用法:bash tools/finish-feature.sh
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
BRANCH=$(git branch --show-current)
|
||||||
|
if [[ ! "$BRANCH" =~ ^feature/ ]]; then
|
||||||
|
echo "❌ 当前分支不是 feature/*:${BRANCH}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||||
|
echo "❌ 工作区有未提交改动,先提交或暂存"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "== 合并 ${BRANCH} → main"
|
||||||
|
git checkout main
|
||||||
|
git pull --ff-only origin main
|
||||||
|
git merge --no-ff "$BRANCH" -m "Merge branch '${BRANCH}'"
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
echo "== 清理分支 ${BRANCH}"
|
||||||
|
git branch -d "$BRANCH"
|
||||||
|
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
|
||||||
|
git push origin --delete "$BRANCH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ 已合并并清理 ${BRANCH}"
|
||||||
Reference in New Issue
Block a user