Add a Gitea Actions workflow that pushes main and the v* tags to the GitHub mirror after a push to the canonical repository. The job uses the host runner and only git: the official runner images ship no node and builtin:checkout was removed in runner v6, so no uses: is used. A branch push mirrors main plus every tag, while a tag push mirrors only that tag so a tag behind main cannot rewind the mirror. Pushes never force, so a diverged mirror fails the run instead of losing commits that exist only on GitHub. Co-authored-by: opencode v2.3.0
44 lines
1.3 KiB
YAML
44 lines
1.3 KiB
YAML
name: mirror
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: mirror-github
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
mirror:
|
|
runs-on: host
|
|
steps:
|
|
- name: Push the default branch and tags to GitHub
|
|
shell: bash
|
|
env:
|
|
MIRROR_TOKEN: ${{ secrets.MIRROR_TOKEN }}
|
|
REF: ${{ gitea.ref }}
|
|
run: |
|
|
set -euo pipefail
|
|
export GIT_TERMINAL_PROMPT=0
|
|
|
|
src="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
|
dst="https://github.com/duzhaokun123/opencode-command-window.git"
|
|
auth="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$MIRROR_TOKEN" | base64 | tr -d '\n')"
|
|
|
|
work="$(mktemp -d)"
|
|
trap 'rm -rf "$work"' EXIT
|
|
|
|
git init --quiet "$work/repo"
|
|
cd "$work/repo"
|
|
git fetch --quiet --no-tags "$src" '+refs/heads/*:refs/remotes/src/*'
|
|
git fetch --quiet --no-tags "$src" '+refs/tags/*:refs/tags/*'
|
|
|
|
if [ "${REF#refs/tags/}" != "$REF" ]; then
|
|
git -c "http.https://github.com/.extraheader=$auth" push --quiet "$dst" "${REF}:${REF}"
|
|
else
|
|
git -c "http.https://github.com/.extraheader=$auth" push --quiet "$dst" \
|
|
'refs/remotes/src/main:refs/heads/main' 'refs/tags/*:refs/tags/*'
|
|
fi
|