docs: sync 37-03 wording updates #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync to Gitee | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: sync-gitee-main | |
| cancel-in-progress: false | |
| jobs: | |
| sync: | |
| name: Push GitHub main to Gitee | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 需要在 GitHub 仓库的 Actions secrets 中配置: | |
| # - GITEE_REPO_SSH:Gitee 仓库 SSH 地址,例如 git@gitee.com:owner/repo.git | |
| # - GITEE_SSH_PRIVATE_KEY:拥有该 Gitee 仓库写权限的 SSH 私钥 | |
| # 可选配置 GitHub repository variable: | |
| # - GITEE_TARGET_BRANCH:Gitee 目标分支,未配置时使用 main | |
| # 未配置时跳过同步,避免公开仓库在 secrets 配好前每次 push 都显示失败。 | |
| - name: Check Gitee mirror configuration | |
| id: config | |
| shell: bash | |
| env: | |
| GITEE_REPO_SSH: ${{ secrets.GITEE_REPO_SSH }} | |
| GITEE_SSH_PRIVATE_KEY: ${{ secrets.GITEE_SSH_PRIVATE_KEY }} | |
| run: | | |
| if [ -z "$GITEE_REPO_SSH" ] || [ -z "$GITEE_SSH_PRIVATE_KEY" ]; then | |
| echo "enabled=false" >> "$GITHUB_OUTPUT" | |
| echo "::warning::GITEE_REPO_SSH or GITEE_SSH_PRIVATE_KEY is not configured; skipping Gitee sync." | |
| else | |
| echo "enabled=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Checkout GitHub repository | |
| if: steps.config.outputs.enabled == 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure SSH for Gitee | |
| if: steps.config.outputs.enabled == 'true' | |
| shell: bash | |
| env: | |
| GITEE_SSH_PRIVATE_KEY: ${{ secrets.GITEE_SSH_PRIVATE_KEY }} | |
| run: | | |
| install -m 700 -d ~/.ssh | |
| printf '%s\n' "$GITEE_SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/gitee_sync_key | |
| chmod 600 ~/.ssh/gitee_sync_key | |
| ssh-keyscan -t rsa,ecdsa,ed25519 gitee.com >> ~/.ssh/known_hosts | |
| git config core.sshCommand "ssh -i ~/.ssh/gitee_sync_key -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" | |
| - name: Push main and tags to Gitee | |
| if: steps.config.outputs.enabled == 'true' | |
| shell: bash | |
| env: | |
| GITEE_REPO_SSH: ${{ secrets.GITEE_REPO_SSH }} | |
| GITEE_TARGET_BRANCH: ${{ vars.GITEE_TARGET_BRANCH }} | |
| run: | | |
| target_branch="${GITEE_TARGET_BRANCH:-main}" | |
| git remote add gitee "$GITEE_REPO_SSH" | |
| git push gitee HEAD:"$target_branch" | |
| git push gitee --tags |