Skip to content

Commit

Permalink
template
Browse files Browse the repository at this point in the history
  • Loading branch information
GRCmade committed Mar 7, 2025
1 parent c355a75 commit 2ef1435
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
90 changes: 90 additions & 0 deletions .github/workflows/save-readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Save README on Branch Push

on:
push:
branches:
- "**" # 监听所有分支的推送事件

jobs:
save-readme:
runs-on: [self-hosted, linux]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up environment
id: setup
run: |
# 获取当前分支名称
BRANCH_NAME=$(echo "$GITHUB_REF" | sed 's/refs\/heads\///')
echo "Current branch: $BRANCH_NAME"
# 创建目标目录
TARGET_DIR="main/$BRANCH_NAME"
mkdir -p "$TARGET_DIR"
# 检查 README.md 是否存在
if [ -f "README.md" ]; then
# 将 README.md 复制到目标目录
cp README.md "$TARGET_DIR/README.md"
echo "README.md saved to $TARGET_DIR/README.md"
else
echo "README.md not found in branch $BRANCH_NAME"
fi
# 检查 youtrack.json 是否存在
if [ -f "youtrack.json" ]; then
# 将 youtrack.json 复制到目标目录
cp youtrack.json "$TARGET_DIR/youtrack.json"
echo "youtrack.json saved to $TARGET_DIR/youtrack.json"
else
echo "youtrack.json not found in branch $BRANCH_NAME"
fi
# 输出目标目录路径
echo "TARGET_DIR=$TARGET_DIR" >> $GITHUB_ENV
- name: Sync to main branch
run: |
BRANCH_NAME=$(echo "$GITHUB_REF" | sed 's/refs\/heads\///')
REPO_URL="https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git"
# 检查远程是否存在 main 分支
if git ls-remote --heads "$REPO_URL" main | grep -q 'refs/heads/main'; then
echo "克隆现有的 main 分支..."
git clone -b main "$REPO_URL" target
else
echo "创建新的 main 分支..."
rm -rf target
mkdir -p target
cd target
git init
git remote add origin "$REPO_URL"
git checkout -b main
touch .gitkeep
git add .gitkeep
git config user.name "GitHub Action"
git config user.email "[email protected]"
git commit -m "初始化 main 分支"
git push origin main
cd ..
fi
# 进入 target 目录并配置用户信息
cd target
git config user.name "GitHub Action"
git config user.email "[email protected]"
# 拉取最新的 main 分支更改
git pull origin main --rebase
# 将生成的 main 目录内容复制到 target 仓库
cp -r ../main .
# 提交更改
git add .
git commit -m "Sync README from branch $BRANCH_NAME" || echo "没有变更,无需提交"
# 推送更改
git push origin main
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
> uniapp-bugs https://github.com/GRCmade/uniapp-bugs
# 问题
2025 年 3 月 7 日 13:55:03
======== END ========

0 comments on commit 2ef1435

Please sign in to comment.