Mirror GitHub to diffinery.com instead of the other way round
Development happens on github.com/codician-team/diffinery, but diffinery.com's "Mirror to GitHub" job still force-pushed its own, older main over GitHub's every 6 hours, which twice undid the GitHub merges (00:25 and 06:25 UTC on Oct 31). The job is replaced by "Mirror from GitHub": every 15 minutes, on Diffinery only, it copies GitHub's main and tags to codician/diffinery as they are, with a person's admin-scoped Diffinery token (DIFFINERY_MIRROR_TOKEN in the github-mirror environment). Deploy skips that mirror by name, since GitHub deploys diffinery.com and the mirror lacks the GitHub App's variables. AGENTS.md, CONTRIBUTING.md and the README say where development happens now, and scripts/use-diffinery.sh, which pointed GitHub checkouts at Diffinery, is gone.
10 files changed+112−256
Files (10)
- .github/workflows/deploy.yml+4−2
- .github/workflows/mirror-from-github.yml+42−0
- .github/workflows/mirror-to-github.yml+0−51
- AGENTS.md+2−2
- CONTRIBUTING.md+7−12
- README.md+2−2
- apps/diffinery/docs/self-hosting/deploy.md+1−1
- scripts/mirror-from-github.sh+54−0
- scripts/mirror-to-github.sh+0−138
- scripts/use-diffinery.sh+0−48
modified.github/workflows/deploy.yml+4−2View file
| @@ -38,8 +38,10 @@ | ||
| 38 | 38 | gate: |
| 39 | 39 | name: Main's current tip |
| 40 | 40 | # Every push to main deploys once CI passes on it, on GitHub or on a Diffinery |
| 41 | - # instance, and so does running this workflow by hand. | |
| 42 | - if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push') }} | |
| 41 | + # instance, and so does running this workflow by hand. Except on diffinery.com's | |
| 42 | + # codician/diffinery: it mirrors GitHub (mirror-from-github.yml), which deploys | |
| 43 | + # diffinery.com, and lacks the GitHub App's variables a deploy needs. | |
| 44 | + if: ${{ !(github.server_url == 'https://diffinery.com' && github.repository == 'codician/diffinery') && (github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')) }} | |
| 43 | 45 | runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} |
| 44 | 46 | timeout-minutes: 5 |
| 45 | 47 | outputs: |
added.github/workflows/mirror-from-github.yml+42−0View file
| @@ -1,0 +1,42 @@ | ||
| 1 | +name: Mirror from GitHub | |
| 2 | + | |
| 3 | +# Keeps diffinery.com/codician/diffinery in step with github.com/codician-team/diffinery, | |
| 4 | +# where development happens, through scripts/mirror-from-github.sh: GitHub's main and tags | |
| 5 | +# are copied as they are, and Diffinery runs CI on each copied commit. Runs on Diffinery | |
| 6 | +# only. Uses DIFFINERY_MIRROR_TOKEN (a Diffinery token with the admin scope, of a person who | |
| 7 | +# is an admin of codician/diffinery), a secret of the github-mirror environment. That | |
| 8 | +# environment is limited to protected branches, so only main's runs get it. Without the | |
| 9 | +# token the job says so and does nothing. | |
| 10 | +on: | |
| 11 | + schedule: | |
| 12 | + - cron: "*/15 * * * *" | |
| 13 | + workflow_dispatch: | |
| 14 | + | |
| 15 | +permissions: | |
| 16 | + contents: read | |
| 17 | + | |
| 18 | +concurrency: | |
| 19 | + group: mirror-from-github | |
| 20 | + cancel-in-progress: false | |
| 21 | + | |
| 22 | +jobs: | |
| 23 | + mirror: | |
| 24 | + name: Copy GitHub's main to Diffinery | |
| 25 | + if: ${{ github.server_url != 'https://github.com' && github.repository == 'codician/diffinery' }} | |
| 26 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 27 | + environment: github-mirror | |
| 28 | + timeout-minutes: 10 | |
| 29 | + env: | |
| 30 | + DIFFINERY_TOKEN: ${{ secrets.DIFFINERY_MIRROR_TOKEN }} | |
| 31 | + steps: | |
| 32 | + - name: Check the Diffinery token | |
| 33 | + id: token | |
| 34 | + run: | | |
| 35 | + if [ -z "$DIFFINERY_TOKEN" ]; then | |
| 36 | + echo "::notice::DIFFINERY_MIRROR_TOKEN is not set, so Diffinery is not updated." | |
| 37 | + echo "skip=true" >> "$GITHUB_OUTPUT" | |
| 38 | + fi | |
| 39 | + - uses: actions/checkout@v4 | |
| 40 | + if: steps.token.outputs.skip != 'true' | |
| 41 | + - if: steps.token.outputs.skip != 'true' | |
| 42 | + run: scripts/mirror-from-github.sh |
deleted.github/workflows/mirror-to-github.yml+0−51
| @@ -1,51 +1,0 @@ | ||
| 1 | -name: Mirror to GitHub | |
| 2 | - | |
| 3 | -# Keeps the public copy at github.com/codician-team/diffinery in step with main, | |
| 4 | -# through the deterministic rewrite in scripts/mirror-to-github.sh. Runs on Diffinery | |
| 5 | -# only. Uses MIRROR_TOKEN (a fine-grained GitHub token with Contents and | |
| 6 | -# Workflows write on that one repository), a secret of the github-mirror environment. | |
| 7 | -# That environment is limited to protected branches, so the token also reaches runs | |
| 8 | -# after an agent's merge. Without the token the job says so and does nothing. | |
| 9 | -on: | |
| 10 | - push: | |
| 11 | - branches: [main] | |
| 12 | - schedule: | |
| 13 | - - cron: "23 */6 * * *" | |
| 14 | - workflow_dispatch: | |
| 15 | - | |
| 16 | -permissions: | |
| 17 | - contents: read | |
| 18 | - | |
| 19 | -concurrency: | |
| 20 | - group: mirror-to-github | |
| 21 | - cancel-in-progress: false | |
| 22 | - | |
| 23 | -jobs: | |
| 24 | - mirror: | |
| 25 | - name: Push main to the GitHub mirror | |
| 26 | - if: ${{ github.server_url != 'https://github.com' && github.repository == 'codician/diffinery' }} | |
| 27 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 28 | - environment: github-mirror | |
| 29 | - timeout-minutes: 10 | |
| 30 | - env: | |
| 31 | - MIRROR_TOKEN: ${{ secrets.MIRROR_TOKEN }} | |
| 32 | - steps: | |
| 33 | - - name: Check the GitHub token | |
| 34 | - id: token | |
| 35 | - run: | | |
| 36 | - if [ -z "$MIRROR_TOKEN" ]; then | |
| 37 | - echo "::notice::MIRROR_TOKEN is not set, so GitHub is not updated." | |
| 38 | - echo "skip=true" >> "$GITHUB_OUTPUT" | |
| 39 | - fi | |
| 40 | - - uses: actions/checkout@v4 | |
| 41 | - if: steps.token.outputs.skip != 'true' | |
| 42 | - with: | |
| 43 | - ref: main | |
| 44 | - fetch-depth: 0 | |
| 45 | - - if: steps.token.outputs.skip != 'true' | |
| 46 | - # Pinned: another filter-repo version could write different commits. | |
| 47 | - run: python3 -m pip install --quiet --break-system-packages git-filter-repo==2.47.0 || python3 -m pip install --quiet git-filter-repo==2.47.0 | |
| 48 | - - if: steps.token.outputs.skip != 'true' | |
| 49 | - run: scripts/mirror-to-github.sh | |
| 50 | - env: | |
| 51 | - MIRROR_SRC: ${{ github.workspace }} |
modifiedAGENTS.md+2−2View file
| @@ -10,8 +10,8 @@ | ||
| 10 | 10 | Cloudflare. One Cloudflare Worker serves the web UI, git over HTTPS, a GitHub-compatible |
| 11 | 11 | REST and GraphQL API and an MCP server; each repository is a Durable Object with its own |
| 12 | 12 | SQLite database; CI jobs run in Cloudflare Containers. Development happens at |
| 13 | -https://diffinery.com/codician/diffinery; https://github.com/codician-team/diffinery is a | |
| 14 | -mirror. | |
| 13 | +https://github.com/codician-team/diffinery; https://diffinery.com/codician/diffinery is a | |
| 14 | +mirror of its `main`, so push branches and open pull requests on GitHub. | |
| 15 | 15 | |
| 16 | 16 | ## Layout |
| 17 | 17 |
modifiedCONTRIBUTING.md+7−12View file
| @@ -6,19 +6,14 @@ | ||
| 6 | 6 | |
| 7 | 7 | ## Where development happens |
| 8 | 8 | |
| 9 | -Diffinery is developed on Diffinery itself, at | |
| 10 | -[diffinery.com/codician/diffinery](https://diffinery.com/codician/diffinery). Its CI, | |
| 11 | -pull requests, code review and deploys all run there. | |
| 12 | -[github.com/codician-team/diffinery](https://github.com/codician-team/diffinery) is a | |
| 13 | -mirror that follows `main`. | |
| 9 | +Diffinery is developed at | |
| 10 | +[github.com/codician-team/diffinery](https://github.com/codician-team/diffinery). Open | |
| 11 | +issues and pull requests there. Its CI runs on Diffinery's own runners for GitHub, and | |
| 12 | +merges to `main` deploy diffinery.com. | |
| 14 | 13 | |
| 15 | -- **If you have an account on diffinery.com**, open issues and pull requests there. | |
| 16 | -- **If you don't**, open them on the GitHub mirror. Accounts on diffinery.com are by | |
| 17 | - invitation for now, so this is the usual path for new contributors. A maintainer lands | |
| 18 | - accepted pull requests on Diffinery and they come back to GitHub with the next sync; | |
| 19 | - the GitHub pull request is then closed with a link to the change. The mirror rewrites | |
| 20 | - commit authorship, so look for the change by its title or pull request number rather | |
| 21 | - than by commit SHA. | |
| 14 | +[diffinery.com/codician/diffinery](https://diffinery.com/codician/diffinery) is a mirror | |
| 15 | +that follows GitHub's `main` every 15 minutes, with the same commits, and runs the same CI | |
| 16 | +on Diffinery. Changes pushed to its `main` are overwritten, so land them on GitHub. | |
| 22 | 17 | |
| 23 | 18 | Security problems are the exception: report them privately, never in an issue or pull |
| 24 | 19 | request. See [SECURITY.md](SECURITY.md). |
modifiedREADME.md+2−2View file
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | Diffinery is built for the way software gets written with agents. Give an agent a goal and get a pull request back from Claude Code or Codex in a sandbox. Have another agent review every pull request for bugs. Open **Today** each morning to see what needs you, approve, and let pull requests merge on green. Plugins for Claude Code and Codex, an MCP server in the [official MCP Registry](https://registry.modelcontextprotocol.io/v0/servers?search=com.diffinery/diffinery), editor extensions and `gh` support bring all of it to the tools you already use. [What agents can do on Diffinery ↓](#built-for-ai-coding-agents) |
| 21 | 21 | |
| 22 | -- **Source:** [diffinery.com/codician/diffinery](https://diffinery.com/codician/diffinery), where development, CI and deploys happen, mirrored to [github.com/codician-team/diffinery](https://github.com/codician-team/diffinery). | |
| 22 | +- **Source:** [github.com/codician-team/diffinery](https://github.com/codician-team/diffinery), where development happens, with CI on Diffinery's runners, mirrored to [diffinery.com/codician/diffinery](https://diffinery.com/codician/diffinery). | |
| 23 | 23 | - **Documentation:** [diffinery.com/docs](https://diffinery.com/docs), also as Markdown and in [llms.txt](https://diffinery.com/llms.txt) and [llms-full.txt](https://diffinery.com/llms-full.txt) for AI assistants. |
| 24 | 24 | |
| 25 | 25 | If Diffinery is useful to you, [a star on GitHub](https://github.com/codician-team/diffinery) helps other people find it. |
| @@ -321,7 +321,7 @@ | ||
| 321 | 321 | No. Other open-source projects run Git or CI on Cloudflare too, and [Built on Cloudflare](https://diffinery.com/built-on-cloudflare#other-git-and-ci-projects-on-cloudflare) lists how they differ. As far as we know, Diffinery is the one where Git hosting, pull requests with reviews in a web UI and GitHub Actions–compatible CI with marketplace actions all run on Cloudflare (checked October 25, 2026). |
| 322 | 322 | |
| 323 | 323 | **Where is development happening?** |
| 324 | -On Diffinery itself, at [diffinery.com/codician/diffinery](https://diffinery.com/codician/diffinery). Diffinery's own CI, deploys and pull requests run there. The GitHub repository is a mirror, and issues and pull requests are welcome in either place; see [CONTRIBUTING.md](CONTRIBUTING.md). | |
| 324 | +On GitHub, at [github.com/codician-team/diffinery](https://github.com/codician-team/diffinery), where issues and pull requests go. Its CI jobs run on Diffinery's own [GitHub runners](https://diffinery.com/docs/actions/github-runners), and [diffinery.com/codician/diffinery](https://diffinery.com/codician/diffinery) mirrors it and runs the same CI on Diffinery; see [CONTRIBUTING.md](CONTRIBUTING.md). | |
| 325 | 325 | |
| 326 | 326 | ## Contributing, security and license |
| 327 | 327 |
modifiedapps/diffinery/docs/self-hosting/deploy.md+1−1View file
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | - `DIFFINERY_ZONE`, if the Cloudflare zone that holds your hostname is not its last two labels. For `git.example.com` the default zone is `example.com`, which is right; for `git.example.co.uk` the default would be `co.uk`, so set `DIFFINERY_ZONE` to `example.co.uk`. |
| 69 | 69 | - `MAIL_DOMAIN`, if email should come from another domain than your hostname, for example `example.com` to send from `[email protected]`. |
| 70 | 70 | |
| 71 | -The Deploy job runs on every push to `main` once the CI workflow passes on that commit, on GitHub or on a Diffinery instance, and whenever you start it by hand (`workflow_dispatch`). A GitHub mirror of a repository that already deploys from Diffinery would deploy too, so keep Actions or the Cloudflare secrets off on such a mirror. | |
| 71 | +The Deploy job runs on every push to `main` once the CI workflow passes on that commit, on GitHub or on a Diffinery instance, and whenever you start it by hand (`workflow_dispatch`). A mirror of a repository that already deploys would deploy too, on GitHub or on Diffinery, so keep Actions or the Cloudflare secrets off on such a mirror. The upstream project's own Diffinery mirror, `codician/diffinery` on diffinery.com, is skipped by name. | |
| 72 | 72 | |
| 73 | 73 | The workflow doesn't pass `BOOTSTRAP_ADMINS`. Set the list with a first deploy from your machine (`scripts/setup.sh`), or put it under `vars` in your copy's `wrangler.jsonc`; after that, workflow deploys keep it. |
| 74 | 74 |
addedscripts/mirror-from-github.sh+54−0View file
| @@ -1,0 +1,54 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +# Mirror github.com/codician-team/diffinery to Diffinery's codician/diffinery. | |
| 3 | +# | |
| 4 | +# Development happens on GitHub. Its main and tags are copied to Diffinery as they are, so | |
| 5 | +# both have the same commits and Diffinery's main always ends up where GitHub's is: anything | |
| 6 | +# pushed to Diffinery's main by other means is overwritten. Diffinery's other branches, and | |
| 7 | +# its issues, pull requests and releases, are left alone. | |
| 8 | +# | |
| 9 | +# Pushes with DIFFINERY_TOKEN when set, otherwise with whatever credentials git already has | |
| 10 | +# for diffinery.com. It must be a person's token with the admin scope: only an admin's push | |
| 11 | +# goes past main's branch protection, agents can't push to main, and a workflow's own token | |
| 12 | +# can't push changes to workflow files. | |
| 13 | +# | |
| 14 | +# Usage: scripts/mirror-from-github.sh [--dry-run] | |
| 15 | +# | |
| 16 | +# MIRROR_WORKDIR=<empty dir> keeps the fetched repository for inspection. | |
| 17 | +set -euo pipefail | |
| 18 | + | |
| 19 | +SRC=${MIRROR_SRC:-https://github.com/codician-team/diffinery.git} | |
| 20 | +DST=${MIRROR_DST:-https://diffinery.com/codician/diffinery.git} | |
| 21 | +dry_run=${1:-} | |
| 22 | + | |
| 23 | +auth=() | |
| 24 | +if [ -n "${DIFFINERY_TOKEN:-}" ]; then | |
| 25 | + # The helper reads the token from the environment, so it never lands on a command line. | |
| 26 | + auth=(-c 'credential.https://diffinery.com.helper=!f() { [ "$1" = get ] && printf "username=x-token\npassword=%s\n" "$DIFFINERY_TOKEN"; }; f') | |
| 27 | +fi | |
| 28 | + | |
| 29 | +# main and the tags, one "<sha>\t<ref>" line each (peeled tag lines dropped), sorted for comm. | |
| 30 | +refs() { git ${auth[@]+"${auth[@]}"} ls-remote "$1" refs/heads/main 'refs/tags/*' | grep -v '\^{}$' | LC_ALL=C sort; } | |
| 31 | +want=$(refs "$SRC") | |
| 32 | +have=$(refs "$DST") | |
| 33 | +# Diffinery may have tags GitHub doesn't; only GitHub's refs have to match. | |
| 34 | +stale=$(LC_ALL=C comm -23 <(printf '%s\n' "$want") <(printf '%s\n' "$have")) | |
| 35 | +if [ -z "$stale" ]; then | |
| 36 | + echo "Diffinery is up to date with GitHub." | |
| 37 | + exit 0 | |
| 38 | +fi | |
| 39 | +echo "To copy from GitHub:" | |
| 40 | +printf '%s\n' "$stale" | |
| 41 | +if [ "$dry_run" = "--dry-run" ]; then | |
| 42 | + exit 0 | |
| 43 | +fi | |
| 44 | + | |
| 45 | +work=${MIRROR_WORKDIR:-} | |
| 46 | +if [ -z "$work" ]; then | |
| 47 | + work=$(mktemp -d) | |
| 48 | + trap 'rm -rf "$work"' EXIT | |
| 49 | +fi | |
| 50 | +git init --quiet --bare "$work/repo.git" | |
| 51 | +cd "$work/repo.git" | |
| 52 | +git fetch --quiet "$SRC" '+refs/heads/main:refs/heads/main' '+refs/tags/*:refs/tags/*' | |
| 53 | +# GitHub wins: main and the tags move to where GitHub has them, fast-forward or not. | |
| 54 | +git ${auth[@]+"${auth[@]}"} push --force "$DST" 'refs/heads/main:refs/heads/main' 'refs/tags/*:refs/tags/*' |
deletedscripts/mirror-to-github.sh+0−138
| @@ -1,138 +1,0 @@ | ||
| 1 | -#!/usr/bin/env bash | |
| 2 | -# Mirror Diffinery's codician/diffinery main to github.com/codician-team/diffinery. | |
| 3 | -# | |
| 4 | -# Every author and committer becomes codician-team and the attribution trailers | |
| 5 | -# (Co-authored-by, Claude-Session, Signed-off-by) are dropped, so GitHub lists no | |
| 6 | -# personal contributors. | |
| 7 | -# The rewrite is deterministic: the same Diffinery history always gives the same | |
| 8 | -# GitHub commits, so a sync is a fast-forward unless Diffinery's own history was | |
| 9 | -# rewritten (then GitHub follows it). Only main, the tags on it and their releases | |
| 10 | -# are mirrored. | |
| 11 | -# | |
| 12 | -# Reads Diffinery with DIFFINERY_TOKEN when set (not needed once the repo is public); | |
| 13 | -# MIRROR_SRC can also be a local clone that has main. Pushes with MIRROR_TOKEN | |
| 14 | -# when set, otherwise with whatever credentials git already has for github.com. | |
| 15 | -# Needs git-filter-repo 2.47.0 (pip install git-filter-repo==2.47.0); another | |
| 16 | -# version could write different commits. | |
| 17 | -# | |
| 18 | -# Usage: scripts/mirror-to-github.sh [--dry-run] | |
| 19 | -# | |
| 20 | -# MIRROR_WORKDIR=<empty dir> keeps the rewritten repository for inspection. | |
| 21 | -set -euo pipefail | |
| 22 | - | |
| 23 | -SRC=${MIRROR_SRC:-https://diffinery.com/codician/diffinery.git} | |
| 24 | -DST=${MIRROR_DST:-https://github.com/codician-team/diffinery.git} | |
| 25 | -NAME=${MIRROR_NAME:-codician-team} | |
| 26 | -EMAIL=${MIRROR_EMAIL:-hi@codician.com} | |
| 27 | -dry_run=${1:-} | |
| 28 | - | |
| 29 | -work=${MIRROR_WORKDIR:-} | |
| 30 | -if [ -z "$work" ]; then | |
| 31 | - work=$(mktemp -d) | |
| 32 | - trap 'rm -rf "$work"' EXIT | |
| 33 | -fi | |
| 34 | - | |
| 35 | -auth=() | |
| 36 | -if [ -n "${DIFFINERY_TOKEN:-}" ]; then | |
| 37 | - # The helper reads the token from the environment, so it never lands on a command line. | |
| 38 | - auth=(-c 'credential.https://diffinery.com.helper=!f() { [ "$1" = get ] && printf "username=x-token\npassword=%s\n" "$DIFFINERY_TOKEN"; }; f') | |
| 39 | -fi | |
| 40 | -if [ -n "${MIRROR_TOKEN:-}" ]; then | |
| 41 | - auth+=(-c 'credential.https://github.com.helper=!f() { [ "$1" = get ] && printf "username=x-access-token\npassword=%s\n" "$MIRROR_TOKEN"; }; f') | |
| 42 | -fi | |
| 43 | -git "${auth[@]}" clone --quiet --bare --single-branch --branch main "$SRC" "$work/repo.git" | |
| 44 | -cd "$work/repo.git" | |
| 45 | -src_head=$(git rev-parse main) | |
| 46 | - | |
| 47 | -export MIRROR_NAME="$NAME" MIRROR_EMAIL="$EMAIL" | |
| 48 | -git filter-repo --force --quiet --refs main --replace-refs delete-no-add \ | |
| 49 | - --name-callback 'return os.environ["MIRROR_NAME"].encode()' \ | |
| 50 | - --email-callback 'return os.environ["MIRROR_EMAIL"].encode()' \ | |
| 51 | - --message-callback ' | |
| 52 | -import re | |
| 53 | -drop = re.compile(r"^(co-authored-by|claude-session|signed-off-by):|^\U0001f916 generated with \[claude code\]|^https://claude\.ai/code/session_", re.I) | |
| 54 | -text = message.decode("utf-8", "surrogateescape") | |
| 55 | -lines = [l for l in text.split("\n") if not drop.match(l.strip())] | |
| 56 | -return ("\n".join(lines).rstrip() + "\n").encode("utf-8", "surrogateescape")' | |
| 57 | - | |
| 58 | -dst_head=$(git rev-parse main) | |
| 59 | -echo "Diffinery main $src_head -> GitHub main $dst_head" | |
| 60 | -if [ "$dry_run" = "--dry-run" ]; then | |
| 61 | - git log --format='%h %an <%ae> %s' -3 main | |
| 62 | - exit 0 | |
| 63 | -fi | |
| 64 | -remote=$(git "${auth[@]}" ls-remote "$DST" refs/heads/main | cut -f1) | |
| 65 | -if [ "$remote" = "$dst_head" ]; then | |
| 66 | - echo "GitHub main is up to date." | |
| 67 | -else | |
| 68 | - git "${auth[@]}" push --force "$DST" main:main | |
| 69 | -fi | |
| 70 | - | |
| 71 | -# Tags on main follow their commits, as lightweight tags (so no tagger identity). | |
| 72 | -declare -A rewritten | |
| 73 | -while read -r old new; do rewritten[$old]=$new; done < <(tail -n +2 filter-repo/commit-map) | |
| 74 | -remote_tags=$(git "${auth[@]}" ls-remote --tags "$DST") | |
| 75 | -mirrored=() | |
| 76 | -for tag in $(git tag); do | |
| 77 | - target=${rewritten[$(git rev-parse "$tag^{commit}")]:-} | |
| 78 | - [ -n "$target" ] && [ "$target" != 0000000000000000000000000000000000000000 ] || continue | |
| 79 | - if grep -qx "$target"$'\t'"refs/tags/$tag" <<<"$remote_tags" || git "${auth[@]}" push --force "$DST" "$target:refs/tags/$tag"; then | |
| 80 | - mirrored+=("$tag") | |
| 81 | - else | |
| 82 | - echo "warning: could not push tag $tag" >&2 | |
| 83 | - fi | |
| 84 | -done | |
| 85 | - | |
| 86 | -# Releases on the mirrored tags get the same name, notes and flags on GitHub (assets aren't copied). | |
| 87 | -# Needs MIRROR_TOKEN for GitHub's API. | |
| 88 | -if [ -n "${MIRROR_TOKEN:-}" ] && [ ${#mirrored[@]} -gt 0 ]; then | |
| 89 | - MIRROR_TAGS="${mirrored[*]}" python3 - <<'PY' | |
| 90 | -import json, os, urllib.error, urllib.request | |
| 91 | - | |
| 92 | -src = os.environ.get("MIRROR_SRC_API", "https://diffinery.com/api/v3/repos/codician/diffinery") | |
| 93 | -dst = os.environ.get("MIRROR_DST_API", "https://api.github.com/repos/codician-team/diffinery") | |
| 94 | -tags = set(os.environ["MIRROR_TAGS"].split()) | |
| 95 | - | |
| 96 | -def call(method, url, body=None, token=None): | |
| 97 | - req = urllib.request.Request(url, method=method, data=None if body is None else json.dumps(body).encode()) | |
| 98 | - req.add_header("Accept", "application/vnd.github+json") | |
| 99 | - req.add_header("User-Agent", "diffinery-mirror") | |
| 100 | - req.add_header("Content-Type", "application/json") | |
| 101 | - if token: | |
| 102 | - req.add_header("Authorization", f"Bearer {token}") | |
| 103 | - try: | |
| 104 | - with urllib.request.urlopen(req, timeout=30) as r: | |
| 105 | - data = r.read() | |
| 106 | - return r.status, json.loads(data) if data else None | |
| 107 | - except urllib.error.HTTPError as e: | |
| 108 | - return e.code, None | |
| 109 | - | |
| 110 | -token = os.environ["MIRROR_TOKEN"] | |
| 111 | -status, me = call("GET", f"{dst.split('/repos/')[0]}/user", token=token) | |
| 112 | -me = me.get("login") if status == 200 else None | |
| 113 | -status, releases = call("GET", f"{src}/releases?per_page=100", token=os.environ.get("DIFFINERY_TOKEN")) | |
| 114 | -if status != 200: | |
| 115 | - raise SystemExit(f"could not list Diffinery releases ({status})") | |
| 116 | -for r in releases: | |
| 117 | - if r["draft"] or r["tag_name"] not in tags: | |
| 118 | - continue | |
| 119 | - want = {"name": r["name"], "body": r["body"] or "", "prerelease": r["prerelease"]} | |
| 120 | - status, have = call("GET", f"{dst}/releases/tags/{r['tag_name']}", token=token) | |
| 121 | - if status == 200 and me and (have.get("author") or {}).get("login") != me: | |
| 122 | - # A mirrored release belongs to the mirror's account: one made by anyone else is made again. | |
| 123 | - status, _ = call("DELETE", f"{dst}/releases/{have['id']}", token=token) | |
| 124 | - if status != 204: | |
| 125 | - print(f"warning: could not replace GitHub release {r['tag_name']} ({status})") | |
| 126 | - continue | |
| 127 | - print(f"release {r['tag_name']}: deleted the copy {have['author']['login']} made") | |
| 128 | - status = 404 | |
| 129 | - if status == 404: | |
| 130 | - status, _ = call("POST", f"{dst}/releases", {"tag_name": r["tag_name"], **want}, token) | |
| 131 | - print(f"release {r['tag_name']}: created ({status})") | |
| 132 | - elif status == 200 and any(have.get(k) != v for k, v in want.items()): | |
| 133 | - status, _ = call("PATCH", f"{dst}/releases/{have['id']}", want, token) | |
| 134 | - print(f"release {r['tag_name']}: updated ({status})") | |
| 135 | - elif status != 200: | |
| 136 | - print(f"warning: could not read GitHub release {r['tag_name']} ({status})") | |
| 137 | -PY | |
| 138 | -fi |
deletedscripts/use-diffinery.sh+0−48
| @@ -1,48 +1,0 @@ | ||
| 1 | -#!/usr/bin/env bash | |
| 2 | -# Points a checkout cloned from the GitHub mirror (github.com/codician-team/diffinery) at | |
| 3 | -# the project's home on Diffinery (https://diffinery.com/codician/diffinery), where | |
| 4 | -# branches are pushed and pull requests are opened. The mirror follows Diffinery, so | |
| 5 | -# changes go to Diffinery first. | |
| 6 | -# | |
| 7 | -# DIFFINERY_TOKEN=dfy_... scripts/use-diffinery.sh | |
| 8 | -# | |
| 9 | -# DIFFINERY_TOKEN is a Diffinery token with the `write` scope (Settings -> Tokens). | |
| 10 | -# DIFFINERY_REPO_URL points the checkout at another copy, such as your fork or your own | |
| 11 | -# instance (default https://diffinery.com/codician/diffinery.git). | |
| 12 | -# | |
| 13 | -# What it changes: | |
| 14 | -# - Adds a git credential helper for the Diffinery host to your global git config. The | |
| 15 | -# helper reads DIFFINERY_TOKEN from the environment when git asks, so the token is never | |
| 16 | -# written to disk or put on a command line. | |
| 17 | -# - Renames the GitHub remote to "github", fetch-only (pushes there would be overwritten | |
| 18 | -# by the mirror), and makes "origin" the Diffinery repository. | |
| 19 | -# - When the checkout is clean, moves the current branch forward to Diffinery's copy of | |
| 20 | -# it, or to Diffinery's main if the branch is new and starts from the mirror's main. | |
| 21 | -set -euo pipefail | |
| 22 | -[ -n "${DIFFINERY_TOKEN:-}" ] || { echo "DIFFINERY_TOKEN is not set" >&2; exit 1; } | |
| 23 | -url=${DIFFINERY_REPO_URL:-https://diffinery.com/codician/diffinery.git} | |
| 24 | - | |
| 25 | -host=${url#*://}; host=${host%%/*} | |
| 26 | -git config --global "credential.https://$host.helper" \ | |
| 27 | - '!f() { [ "$1" = get ] && printf "username=x-token\npassword=%s\n" "$DIFFINERY_TOKEN"; }; f' | |
| 28 | - | |
| 29 | -if [ "$(git remote get-url origin 2>/dev/null || true)" != "$url" ]; then | |
| 30 | - if git remote get-url origin >/dev/null 2>&1 && ! git remote get-url github >/dev/null 2>&1; then git remote rename origin github; fi | |
| 31 | - if git remote get-url origin >/dev/null 2>&1; then git remote set-url origin "$url"; else git remote add origin "$url"; fi | |
| 32 | -fi | |
| 33 | -git remote get-url github >/dev/null 2>&1 && git remote set-url --push github nothing-goes-back-to-github | |
| 34 | -git fetch -q origin | |
| 35 | -git remote set-head origin -a >/dev/null 2>&1 || true | |
| 36 | - | |
| 37 | -branch=$(git symbolic-ref -q --short HEAD || true) | |
| 38 | -if [ -n "$branch" ] && [ -z "$(git status --porcelain)" ]; then | |
| 39 | - for base in "origin/$branch" origin/main; do | |
| 40 | - if git rev-parse -q --verify "$base" >/dev/null && git merge-base --is-ancestor HEAD "$base"; then | |
| 41 | - git merge -q --ff-only "$base" | |
| 42 | - echo "$branch is now at $base ($(git rev-parse --short HEAD))" | |
| 43 | - break | |
| 44 | - fi | |
| 45 | - done | |
| 46 | - if git rev-parse -q --verify "origin/$branch" >/dev/null; then git branch -q --set-upstream-to="origin/$branch"; fi | |
| 47 | -fi | |
| 48 | -echo "origin is $url. Push there; open pull requests on https://$host, or through https://$host/api/v3 with the same token." |