Sync Gitee Mirror workflow (huangwb8/ChineseResearchLaTeX)
The Sync Gitee Mirror workflow from huangwb8/ChineseResearchLaTeX, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Sync Gitee Mirror workflow from the huangwb8/ChineseResearchLaTeX repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Sync Gitee Mirror
on:
push:
branches:
- main
schedule:
- cron: "17 * * * *"
workflow_dispatch:
inputs:
branch:
description: "Branch to sync to Gitee"
required: false
default: "main"
tag:
description: "Tag to sync; defaults to latest local tag"
required: false
default: ""
dry_run:
description: "Only print the sync plan without pushing"
required: false
default: "false"
permissions:
contents: read
concurrency:
group: sync-gitee-mirror-${{ inputs.branch || github.ref_name || github.event.repository.default_branch || 'main' }}
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
env:
TARGET_BRANCH: ${{ inputs.branch || github.ref_name || github.event.repository.default_branch || 'main' }}
GITEE_REPO: ${{ vars.GITEE_REPO }}
GITEE_REMOTE_URL: ${{ vars.GITEE_REMOTE_URL }}
steps:
- name: Validate configuration
env:
GITEE_SSH_PRIVATE_KEY: ${{ secrets.GITEE_SSH_PRIVATE_KEY }}
run: |
if [ -z "$GITEE_SSH_PRIVATE_KEY" ]; then
echo "Missing secret: GITEE_SSH_PRIVATE_KEY"
exit 1
fi
if [ -z "$GITEE_REPO" ] && [ -z "$GITEE_REMOTE_URL" ]; then
echo "Missing repository target: configure GITEE_REPO or GITEE_REMOTE_URL"
exit 1
fi
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name || github.event.repository.default_branch }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Start SSH agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.GITEE_SSH_PRIVATE_KEY }}
- name: Trust Gitee host key
run: |
mkdir -p ~/.ssh
ssh-keyscan -H gitee.com >> ~/.ssh/known_hosts
- name: Run sync regression tests
run: |
python -m pip install --upgrade pip
python -m pip install pytest
pytest -q scripts/test_sync_gitee_mirror.py
- name: Sync latest branch commit to Gitee
run: |
cmd=(python scripts/sync_gitee_mirror.py --branch "$TARGET_BRANCH")
if [ -n "${{ inputs.tag }}" ]; then
cmd+=(--tag "${{ inputs.tag }}")
fi
if [ "${{ inputs.dry_run }}" = "true" ]; then
cmd+=(--dry-run)
fi
"${cmd[@]}"
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Sync Gitee Mirror on: push: branches: - main schedule: - cron: "17 * * * *" workflow_dispatch: inputs: branch: description: "Branch to sync to Gitee" required: false default: "main" tag: description: "Tag to sync; defaults to latest local tag" required: false default: "" dry_run: description: "Only print the sync plan without pushing" required: false default: "false" permissions: contents: read concurrency: group: sync-gitee-mirror-${{ inputs.branch || github.ref_name || github.event.repository.default_branch || 'main' }} cancel-in-progress: false jobs: sync: timeout-minutes: 30 runs-on: latchkey-small env: TARGET_BRANCH: ${{ inputs.branch || github.ref_name || github.event.repository.default_branch || 'main' }} GITEE_REPO: ${{ vars.GITEE_REPO }} GITEE_REMOTE_URL: ${{ vars.GITEE_REMOTE_URL }} steps: - name: Validate configuration env: GITEE_SSH_PRIVATE_KEY: ${{ secrets.GITEE_SSH_PRIVATE_KEY }} run: | if [ -z "$GITEE_SSH_PRIVATE_KEY" ]; then echo "Missing secret: GITEE_SSH_PRIVATE_KEY" exit 1 fi if [ -z "$GITEE_REPO" ] && [ -z "$GITEE_REMOTE_URL" ]; then echo "Missing repository target: configure GITEE_REPO or GITEE_REMOTE_URL" exit 1 fi - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 ref: ${{ github.ref_name || github.event.repository.default_branch }} - name: Setup Python uses: actions/setup-python@v5 with: cache: 'pip' python-version: "3.11" - name: Start SSH agent uses: webfactory/ssh-agent@v0.9.0 with: ssh-private-key: ${{ secrets.GITEE_SSH_PRIVATE_KEY }} - name: Trust Gitee host key run: | mkdir -p ~/.ssh ssh-keyscan -H gitee.com >> ~/.ssh/known_hosts - name: Run sync regression tests run: | python -m pip install --upgrade pip python -m pip install pytest pytest -q scripts/test_sync_gitee_mirror.py - name: Sync latest branch commit to Gitee run: | cmd=(python scripts/sync_gitee_mirror.py --branch "$TARGET_BRANCH") if [ -n "${{ inputs.tag }}" ]; then cmd+=(--tag "${{ inputs.tag }}") fi if [ "${{ inputs.dry_run }}" = "true" ]; then cmd+=(--dry-run) fi "${cmd[@]}"
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.