# This workflow is managed by gh actions-lock. # SPDX-License-Identifier: MPL-2.0 # This workflow is managed by gh actions-lock. # mirror-reusable.yml — Reusable git-forge mirror bundle. # # Consolidates the per-repo `mirror.yml` workflow (estate-wide: 289 # deployments with 76% SHA drift across a 100-repo sample, top SHA # covering only 16% of sampled repos). All sampled variants carried the # same 7 forge jobs; drift was almost entirely SHA-pin / whitespace # churn, not feature variance — exactly the shape that consolidates # cleanly behind a `workflow_call` reusable. # # Each mirror job is gated on the per-repo variable # `vars._MIRROR_ENABLED == 'true'`, so forge selection is # configured per-repo via Actions vars — no per-call inputs required. # # Callers pass the per-forge SSH keys and optional R2 backup secrets # EXPLICITLY, by the names declared in `workflow_call.secrets` below # (GITLAB_SSH_KEY, BITBUCKET_SSH_KEY, CODEBERG_SSH_KEY, SOURCEHUT_SSH_KEY, # DISROOT_SSH_KEY, GITEA_SSH_KEY, RADICLE_KEY, R2_ACCESS_KEY_ID, # R2_SECRET_ACCESS_KEY, R2_AGE_RECIPIENT). Do not use `secrets: inherit`: # it forwards every repo/org secret the caller can see, not just these ten # (standards#1108 §6b). Without a passed secret, `${{ secrets.X }}` inside # the reusable evaluates to empty and that forge's job no-ops. # # Caller example (wrapper): # # SPDX-License-Identifier: MPL-2.0 # name: Mirror to Git Forges # on: # push: # branches: [main] # workflow_dispatch: # permissions: # contents: read # jobs: # mirror: # uses: metadatastician/standards/.github/workflows/mirror-reusable.yml@ # secrets: # GITLAB_SSH_KEY: ${{ secrets.GITLAB_SSH_KEY }} # BITBUCKET_SSH_KEY: ${{ secrets.BITBUCKET_SSH_KEY }} # CODEBERG_SSH_KEY: ${{ secrets.CODEBERG_SSH_KEY }} # SOURCEHUT_SSH_KEY: ${{ secrets.SOURCEHUT_SSH_KEY }} # DISROOT_SSH_KEY: ${{ secrets.DISROOT_SSH_KEY }} # GITEA_SSH_KEY: ${{ secrets.GITEA_SSH_KEY }} # RADICLE_KEY: ${{ secrets.RADICLE_KEY }} # R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} # R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} # R2_AGE_RECIPIENT: ${{ secrets.R2_AGE_RECIPIENT }} name: Mirror to Git Forges (reusable) on: workflow_call: inputs: runs-on: description: Runner label for all mirror jobs type: string required: false default: ubuntu-latest secrets: GITLAB_SSH_KEY: required: false BITBUCKET_SSH_KEY: required: false CODEBERG_SSH_KEY: required: false SOURCEHUT_SSH_KEY: required: false DISROOT_SSH_KEY: required: false GITEA_SSH_KEY: required: false RADICLE_KEY: required: false R2_ACCESS_KEY_ID: required: false R2_SECRET_ACCESS_KEY: required: false R2_AGE_RECIPIENT: required: false permissions: actions: read contents: read jobs: # Visibility guard (owner ruling 2026-11-13, standards CASE-038 / hypatia # WF030 mirror_without_visibility_guard). Every forge job force-pushes main. # Before this guard, a PRIVATE repository with _MIRROR_ENABLED=true was # pushed to that forge whatever the forge copy's visibility, so private code # could land in a public repository. The forges' visibility cannot be read # from here with the deploy keys the callers pass, so the rule is: # * a public source mirrors as before; # * a private source (or one whose visibility cannot be read) mirrors to a # forge only when the repo variable _MIRROR_PRIVATE_CONFIRMED is # 'true', set by a person after checking that the forge copy is private; # * every enabled forge that is refused is named in an error annotation and # in the summary, and this job fails, so the run is red, not silent. # The R2 bundle is exempt: it is age-encrypted before it leaves the runner. visibility-guard: timeout-minutes: 5 runs-on: ${{ inputs.runs-on }} permissions: {} outputs: public: ${{ steps.vis.outputs.public }} steps: - name: Read the source repository's visibility id: vis env: SRC_PRIVATE: ${{ github.event.repository.private }} run: | set -euo pipefail # Only an explicit "false" counts as public. An absent value (an event # without a repository object) is treated as private: fail closed. if [ "$SRC_PRIVATE" = "false" ]; then echo "public=true" >> "$GITHUB_OUTPUT" else echo "public=false" >> "$GITHUB_OUTPUT" fi echo "source private: '${SRC_PRIVATE:-}'" - name: Refuse unconfirmed forges for a private source if: steps.vis.outputs.public != 'true' env: EN_GITLAB: ${{ vars.GITLAB_MIRROR_ENABLED }} OK_GITLAB: ${{ vars.GITLAB_MIRROR_PRIVATE_CONFIRMED }} EN_BITBUCKET: ${{ vars.BITBUCKET_MIRROR_ENABLED }} OK_BITBUCKET: ${{ vars.BITBUCKET_MIRROR_PRIVATE_CONFIRMED }} EN_CODEBERG: ${{ vars.CODEBERG_MIRROR_ENABLED }} OK_CODEBERG: ${{ vars.CODEBERG_MIRROR_PRIVATE_CONFIRMED }} EN_SOURCEHUT: ${{ vars.SOURCEHUT_MIRROR_ENABLED }} OK_SOURCEHUT: ${{ vars.SOURCEHUT_MIRROR_PRIVATE_CONFIRMED }} EN_DISROOT: ${{ vars.DISROOT_MIRROR_ENABLED }} OK_DISROOT: ${{ vars.DISROOT_MIRROR_PRIVATE_CONFIRMED }} EN_GITEA: ${{ vars.GITEA_MIRROR_ENABLED }} OK_GITEA: ${{ vars.GITEA_MIRROR_PRIVATE_CONFIRMED }} EN_RADICLE: ${{ vars.RADICLE_MIRROR_ENABLED }} OK_RADICLE: ${{ vars.RADICLE_MIRROR_PRIVATE_CONFIRMED }} run: | set -euo pipefail refused=0 for forge in GITLAB BITBUCKET CODEBERG SOURCEHUT DISROOT GITEA RADICLE; do en_var="EN_${forge}"; ok_var="OK_${forge}" [ "${!en_var:-}" = "true" ] || continue if [ "${!ok_var:-}" != "true" ]; then refused=$((refused + 1)) msg="Not mirroring this PRIVATE repository to ${forge}: ${forge}_MIRROR_ENABLED is true but ${forge}_MIRROR_PRIVATE_CONFIRMED is not. Check that the ${forge} copy is private, then set ${forge}_MIRROR_PRIVATE_CONFIRMED=true, or turn the mirror off." echo "::error::$msg" printf -- '- %s\n' "$msg" >> "$GITHUB_STEP_SUMMARY" fi done if [ "$refused" -gt 0 ]; then echo "$refused forge mirror(s) refused by the visibility guard." >&2 exit 1 fi echo "Private source: every enabled forge is confirmed private." mirror-gitlab: # Advisory mirror: verification still fails closed and skips the push. continue-on-error: true timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.GITLAB_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.GITLAB_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.GITLAB_MIRROR_PRIVATE_CONFIRMED == 'true') }} # Map the secret to env so step `if:`s can gate on its presence: the # `secrets` context is NOT available in `if:` (using it is an # "Unrecognized named-value: 'secrets'" startup failure). `env` IS # available in step `if:`, and secrets are valid in job-level `env`. env: GITLAB_KEY: ${{ secrets.GITLAB_SSH_KEY }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0 if: ${{ env.GITLAB_KEY != '' }} with: ssh-private-key: ${{ secrets.GITLAB_SSH_KEY }} - name: Verify gitlab SSH host if: ${{ env.GITLAB_KEY != '' }} env: MIRROR_HOST: gitlab.com APPROVED_FINGERPRINT: ${{ vars.GITLAB_SSH_FINGERPRINT || 'SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8' }} run: | set -euo pipefail # Approved independently of ssh-keyscan; source: https://docs.gitlab.com/user/gitlab_com/#ssh-host-keys-fingerprints if [[ ! "$MIRROR_HOST" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*$ ]] || [[ ! "$APPROVED_FINGERPRINT" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then echo "::error::Configure a valid GITLAB_SSH_FINGERPRINT and mirror hostname" exit 1 fi CANDIDATE="$RUNNER_TEMP/mirror-gitlab-known-hosts" ssh-keyscan -T 10 -t ed25519 "$MIRROR_HOST" > "$CANDIDATE" ACTUAL=$(ssh-keygen -lf "$CANDIDATE" -E sha256 | awk '{print $2}' | sort -u) if [ "$ACTUAL" != "$APPROVED_FINGERPRINT" ]; then echo "::error::Mirror SSH host fingerprint mismatch; refusing push" exit 1 fi printf 'GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=yes -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=%s\n' "$CANDIDATE" >> "$GITHUB_ENV" - name: Mirror to GitLab # continue-on-error: GitLab branch protection on the mirror repo may block # force-push even for a deploy key. Owner action required: in GitLab go to # Settings → Repository → Protected branches → main and either allow force-push # for Maintainers/Developers or remove the protection on the mirror repo. # Until then this step is advisory-only; failures do not red main. continue-on-error: true if: ${{ env.GITLAB_KEY != '' }} env: MIRROR_ORG: ${{ vars.GITLAB_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} MIRROR_HOST: gitlab.com run: | git remote add gitlab "git@gitlab.com:${MIRROR_ORG}/${REPO_NAME}.git" || true git push --force gitlab main - name: Skipped (GITLAB_SSH_KEY not configured) if: ${{ env.GITLAB_KEY == '' }} run: | echo "::notice::GITLAB_MIRROR_ENABLED=true but secrets.GITLAB_SSH_KEY is empty. Skipping GitLab mirror. Configure the GITLAB_SSH_KEY org/repo secret to enable." mirror-bitbucket: timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.BITBUCKET_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.BITBUCKET_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.BITBUCKET_MIRROR_PRIVATE_CONFIRMED == 'true') }} # See mirror-gitlab: the `secrets` context is not valid in step `if:`; # hoist to job-level `env` and gate steps on `env.BITBUCKET_KEY`. env: BITBUCKET_KEY: ${{ secrets.BITBUCKET_SSH_KEY }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0 if: ${{ env.BITBUCKET_KEY != '' }} with: ssh-private-key: ${{ secrets.BITBUCKET_SSH_KEY }} - name: Verify bitbucket SSH host if: ${{ env.BITBUCKET_KEY != '' }} env: MIRROR_HOST: bitbucket.org APPROVED_FINGERPRINT: ${{ vars.BITBUCKET_SSH_FINGERPRINT || 'SHA256:ybgmFkzwOSotHTHLJgHO0QN8L0xErw6vd0VhFA9m3SM' }} run: | set -euo pipefail # Approved independently of ssh-keyscan; source: https://support.atlassian.com/bitbucket-cloud/docs/configure-ssh-and-two-step-verification/ if [[ ! "$MIRROR_HOST" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*$ ]] || [[ ! "$APPROVED_FINGERPRINT" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then echo "::error::Configure a valid BITBUCKET_SSH_FINGERPRINT and mirror hostname" exit 1 fi CANDIDATE="$RUNNER_TEMP/mirror-bitbucket-known-hosts" ssh-keyscan -T 10 -t ed25519 "$MIRROR_HOST" > "$CANDIDATE" ACTUAL=$(ssh-keygen -lf "$CANDIDATE" -E sha256 | awk '{print $2}' | sort -u) if [ "$ACTUAL" != "$APPROVED_FINGERPRINT" ]; then echo "::error::Mirror SSH host fingerprint mismatch; refusing push" exit 1 fi printf 'GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=yes -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=%s\n' "$CANDIDATE" >> "$GITHUB_ENV" - name: Mirror to Bitbucket if: ${{ env.BITBUCKET_KEY != '' }} env: MIRROR_ORG: ${{ vars.BITBUCKET_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} MIRROR_HOST: bitbucket.org run: | git remote add bitbucket "git@bitbucket.org:${MIRROR_ORG}/${REPO_NAME}.git" || true git push --force bitbucket main - name: Skipped (BITBUCKET_SSH_KEY not configured) if: ${{ env.BITBUCKET_KEY == '' }} run: | echo "::notice::BITBUCKET_MIRROR_ENABLED=true but secrets.BITBUCKET_SSH_KEY is empty. Skipping Bitbucket mirror. Configure the BITBUCKET_SSH_KEY org/repo secret to enable." mirror-codeberg: timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.CODEBERG_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.CODEBERG_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.CODEBERG_MIRROR_PRIVATE_CONFIRMED == 'true') }} # See mirror-gitlab: the `secrets` context is not valid in step `if:`; # hoist to job-level `env` and gate steps on `env.CODEBERG_KEY`. env: CODEBERG_KEY: ${{ secrets.CODEBERG_SSH_KEY }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0 if: ${{ env.CODEBERG_KEY != '' }} with: ssh-private-key: ${{ secrets.CODEBERG_SSH_KEY }} - name: Verify codeberg SSH host if: ${{ env.CODEBERG_KEY != '' }} env: MIRROR_HOST: codeberg.org APPROVED_FINGERPRINT: ${{ vars.CODEBERG_SSH_FINGERPRINT || 'SHA256:mIlxA9k46MmM6qdJOdMnAQpzGxF4WIVVL+fj+wZbw0g' }} run: | set -euo pipefail # Approved independently of ssh-keyscan; source: https://docs.codeberg.org/security/ssh-fingerprint/ if [[ ! "$MIRROR_HOST" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*$ ]] || [[ ! "$APPROVED_FINGERPRINT" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then echo "::error::Configure a valid CODEBERG_SSH_FINGERPRINT and mirror hostname" exit 1 fi CANDIDATE="$RUNNER_TEMP/mirror-codeberg-known-hosts" ssh-keyscan -T 10 -t ed25519 "$MIRROR_HOST" > "$CANDIDATE" ACTUAL=$(ssh-keygen -lf "$CANDIDATE" -E sha256 | awk '{print $2}' | sort -u) if [ "$ACTUAL" != "$APPROVED_FINGERPRINT" ]; then echo "::error::Mirror SSH host fingerprint mismatch; refusing push" exit 1 fi printf 'GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=yes -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=%s\n' "$CANDIDATE" >> "$GITHUB_ENV" - name: Mirror to Codeberg if: ${{ env.CODEBERG_KEY != '' }} env: MIRROR_ORG: ${{ vars.CODEBERG_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} MIRROR_HOST: codeberg.org run: | git remote add codeberg "git@codeberg.org:${MIRROR_ORG}/${REPO_NAME}.git" || true git push --force codeberg main - name: Skipped (CODEBERG_SSH_KEY not configured) if: ${{ env.CODEBERG_KEY == '' }} run: | echo "::notice::CODEBERG_MIRROR_ENABLED=true but secrets.CODEBERG_SSH_KEY is empty. Skipping Codeberg mirror. Configure the CODEBERG_SSH_KEY org/repo secret to enable." mirror-sourcehut: timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.SOURCEHUT_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.SOURCEHUT_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.SOURCEHUT_MIRROR_PRIVATE_CONFIRMED == 'true') }} # See mirror-gitlab: the `secrets` context is not valid in step `if:`; # hoist to job-level `env` and gate steps on `env.SOURCEHUT_KEY`. env: SOURCEHUT_KEY: ${{ secrets.SOURCEHUT_SSH_KEY }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0 if: ${{ env.SOURCEHUT_KEY != '' }} with: ssh-private-key: ${{ secrets.SOURCEHUT_SSH_KEY }} - name: Verify sourcehut SSH host if: ${{ env.SOURCEHUT_KEY != '' }} env: MIRROR_HOST: git.sr.ht APPROVED_FINGERPRINT: ${{ vars.SOURCEHUT_SSH_FINGERPRINT }} run: | set -euo pipefail # Approved independently of ssh-keyscan; source: https://man.sr.ht/ if [[ ! "$MIRROR_HOST" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*$ ]] || [[ ! "$APPROVED_FINGERPRINT" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then echo "::error::Configure a valid SOURCEHUT_SSH_FINGERPRINT and mirror hostname" exit 1 fi CANDIDATE="$RUNNER_TEMP/mirror-sourcehut-known-hosts" ssh-keyscan -T 10 -t ed25519 "$MIRROR_HOST" > "$CANDIDATE" ACTUAL=$(ssh-keygen -lf "$CANDIDATE" -E sha256 | awk '{print $2}' | sort -u) if [ "$ACTUAL" != "$APPROVED_FINGERPRINT" ]; then echo "::error::Mirror SSH host fingerprint mismatch; refusing push" exit 1 fi printf 'GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=yes -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=%s\n' "$CANDIDATE" >> "$GITHUB_ENV" - name: Mirror to SourceHut if: ${{ env.SOURCEHUT_KEY != '' }} env: MIRROR_ORG: ${{ vars.SOURCEHUT_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} MIRROR_HOST: git.sr.ht run: | git remote add sourcehut "git@git.sr.ht:~${MIRROR_ORG}/${REPO_NAME}" || true git push --force sourcehut main - name: Skipped (SOURCEHUT_SSH_KEY not configured) if: ${{ env.SOURCEHUT_KEY == '' }} run: | echo "::notice::SOURCEHUT_MIRROR_ENABLED=true but secrets.SOURCEHUT_SSH_KEY is empty. Skipping SourceHut mirror. Configure the SOURCEHUT_SSH_KEY org/repo secret to enable." mirror-disroot: timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.DISROOT_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.DISROOT_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.DISROOT_MIRROR_PRIVATE_CONFIRMED == 'true') }} # See mirror-gitlab: the `secrets` context is not valid in step `if:`; # hoist to job-level `env` and gate steps on `env.DISROOT_KEY`. env: DISROOT_KEY: ${{ secrets.DISROOT_SSH_KEY }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0 if: ${{ env.DISROOT_KEY != '' }} with: ssh-private-key: ${{ secrets.DISROOT_SSH_KEY }} - name: Verify disroot SSH host if: ${{ env.DISROOT_KEY != '' }} env: MIRROR_HOST: git.disroot.org APPROVED_FINGERPRINT: ${{ vars.DISROOT_SSH_FINGERPRINT }} run: | set -euo pipefail # Caller must approve this independently of the ssh-keyscan result. if [[ ! "$MIRROR_HOST" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*$ ]] || [[ ! "$APPROVED_FINGERPRINT" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then echo "::error::Configure a valid DISROOT_SSH_FINGERPRINT and mirror hostname" exit 1 fi CANDIDATE="$RUNNER_TEMP/mirror-disroot-known-hosts" ssh-keyscan -T 10 -t ed25519 "$MIRROR_HOST" > "$CANDIDATE" ACTUAL=$(ssh-keygen -lf "$CANDIDATE" -E sha256 | awk '{print $2}' | sort -u) if [ "$ACTUAL" != "$APPROVED_FINGERPRINT" ]; then echo "::error::Mirror SSH host fingerprint mismatch; refusing push" exit 1 fi printf 'GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=yes -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=%s\n' "$CANDIDATE" >> "$GITHUB_ENV" - name: Mirror to Disroot if: ${{ env.DISROOT_KEY != '' }} env: MIRROR_ORG: ${{ vars.DISROOT_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} MIRROR_HOST: git.disroot.org run: | git remote add disroot "git@git.disroot.org:${MIRROR_ORG}/${REPO_NAME}.git" || true git push --force disroot main - name: Skipped (DISROOT_SSH_KEY not configured) if: ${{ env.DISROOT_KEY == '' }} run: | echo "::notice::DISROOT_MIRROR_ENABLED=true but secrets.DISROOT_SSH_KEY is empty. Skipping Disroot mirror. Configure the DISROOT_SSH_KEY org/repo secret to enable." mirror-gitea: timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.GITEA_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.GITEA_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.GITEA_MIRROR_PRIVATE_CONFIRMED == 'true') }} # See mirror-gitlab: the `secrets` context is not valid in step `if:`; # hoist to job-level `env` and gate steps on `env.GITEA_KEY`. The host is # hoisted too: a missing vars.GITEA_HOST must SKIP with a notice, never # scan an empty hostname and redden the default branch (#1264). env: GITEA_KEY: ${{ secrets.GITEA_SSH_KEY }} GITEA_MIRROR_HOST: ${{ vars.GITEA_HOST }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0 if: ${{ env.GITEA_KEY != '' && env.GITEA_MIRROR_HOST != '' }} with: ssh-private-key: ${{ secrets.GITEA_SSH_KEY }} - name: Verify gitea SSH host if: ${{ env.GITEA_KEY != '' && env.GITEA_MIRROR_HOST != '' }} env: MIRROR_HOST: ${{ vars.GITEA_HOST }} APPROVED_FINGERPRINT: ${{ vars.GITEA_SSH_FINGERPRINT }} run: | set -euo pipefail # Approved independently of ssh-keyscan; source: caller-controlled instance if [[ ! "$MIRROR_HOST" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*$ ]] || [[ ! "$APPROVED_FINGERPRINT" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then echo "::error::Configure a valid GITEA_SSH_FINGERPRINT and mirror hostname" exit 1 fi CANDIDATE="$RUNNER_TEMP/mirror-gitea-known-hosts" ssh-keyscan -T 10 -t ed25519 "$MIRROR_HOST" > "$CANDIDATE" ACTUAL=$(ssh-keygen -lf "$CANDIDATE" -E sha256 | awk '{print $2}' | sort -u) if [ "$ACTUAL" != "$APPROVED_FINGERPRINT" ]; then echo "::error::Mirror SSH host fingerprint mismatch; refusing push" exit 1 fi printf 'GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=yes -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=%s\n' "$CANDIDATE" >> "$GITHUB_ENV" - name: Mirror to Gitea if: ${{ env.GITEA_KEY != '' && env.GITEA_MIRROR_HOST != '' }} env: MIRROR_ORG: ${{ vars.GITEA_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} MIRROR_HOST: ${{ vars.GITEA_HOST }} run: | git remote add gitea "git@${MIRROR_HOST}:${MIRROR_ORG}/${REPO_NAME}.git" || true git push --force gitea main - name: Skipped (GITEA_SSH_KEY not configured) if: ${{ env.GITEA_KEY == '' }} run: | echo "::notice::GITEA_MIRROR_ENABLED=true but secrets.GITEA_SSH_KEY is empty. Skipping Gitea mirror. Configure the GITEA_SSH_KEY org/repo secret to enable." - name: Skipped (GITEA_HOST not configured) if: ${{ env.GITEA_KEY != '' && env.GITEA_MIRROR_HOST == '' }} run: | echo "::notice::GITEA_MIRROR_ENABLED=true and GITEA_SSH_KEY is set, but vars.GITEA_HOST is empty. Skipping Gitea mirror rather than scanning an empty hostname (#1264). Configure the GITEA_HOST org/repo variable to enable." mirror-radicle: timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} needs: visibility-guard # Visibility guard (owner ruling 2026-11-13): a private source is pushed only # to a forge confirmed private by vars.RADICLE_MIRROR_PRIVATE_CONFIRMED. if: ${{ !cancelled() && vars.RADICLE_MIRROR_ENABLED == 'true' && (needs.visibility-guard.outputs.public == 'true' || vars.RADICLE_MIRROR_PRIVATE_CONFIRMED == 'true') }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false # secrets cannot be read directly in a step if-expression. Publish only # a boolean, never the key: the Rust setup and cargo install steps must # not inherit RADICLE_KEY while they download and run build scripts. - name: Check Radicle configuration id: radicle env: RADICLE_KEY: ${{ secrets.RADICLE_KEY }} run: | if [ -n "$RADICLE_KEY" ]; then echo 'configured=true' >> "$GITHUB_OUTPUT" else echo 'configured=false' >> "$GITHUB_OUTPUT" fi - name: Setup Rust if: steps.radicle.outputs.configured == 'true' uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 with: toolchain: stable - name: Install Radicle if: steps.radicle.outputs.configured == 'true' run: | cargo install radicle-cli --locked echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" - name: Mirror to Radicle if: steps.radicle.outputs.configured == 'true' env: RADICLE_KEY: ${{ secrets.RADICLE_KEY }} run: | umask 077 mkdir -p ~/.radicle/keys printf "%s\n" "$RADICLE_KEY" > ~/.radicle/keys/radicle unset RADICLE_KEY chmod 600 ~/.radicle/keys/radicle rad sync --announce || echo "Radicle sync attempted" - name: Skipped (RADICLE_KEY not configured) if: steps.radicle.outputs.configured != 'true' run: | echo "::notice::RADICLE_MIRROR_ENABLED=true but secrets.RADICLE_KEY is empty. Skipping Radicle mirror. Configure the RADICLE_KEY org/repo secret to enable." mirror-r2-bundle: # D303/D304: Cloudflare R2 git-bundle backup with mandatory client-side # age encryption before any bytes leave the runner. name: Mirror encrypted bundle to Cloudflare R2 timeout-minutes: 20 runs-on: ${{ inputs.runs-on }} if: vars.R2_BUNDLE_MIRROR_ENABLED == 'true' env: R2_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} R2_SECRET_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} R2_RECIPIENT: ${{ secrets.R2_AGE_RECIPIENT || vars.R2_AGE_RECIPIENT }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - name: Verify R2 endpoint and age recipient if: ${{ env.R2_KEY_ID != '' && env.R2_SECRET_KEY != '' && env.R2_RECIPIENT != '' }} env: R2_ENDPOINT: ${{ vars.R2_ENDPOINT_URL }} R2_BUCKET: ${{ vars.R2_BUCKET }} AGE_RECIPIENT: ${{ env.R2_RECIPIENT }} run: | set -euo pipefail if [[ ! "$R2_ENDPOINT" =~ ^https://[a-zA-Z0-9-]+(\.eu|\.fedramp|\.us)?\.r2\.cloudflarestorage\.com$ ]] || [[ ! "$R2_BUCKET" =~ ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$ ]] || [[ ! "$AGE_RECIPIENT" =~ ^(age1[a-z0-9]{58}|ssh-ed25519[[:space:]]+AAAA[A-Za-z0-9+/=]+)$ ]]; then echo "::error::Configure valid R2_ENDPOINT_URL (*.r2.cloudflarestorage.com), R2_BUCKET (lowercase alphanumeric and hyphens), and R2_AGE_RECIPIENT (age1... or ssh-ed25519)" exit 1 fi - name: Create, age-encrypt, and upload git bundle to Cloudflare R2 if: ${{ env.R2_KEY_ID != '' && env.R2_SECRET_KEY != '' && env.R2_RECIPIENT != '' }} env: AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: auto R2_ENDPOINT: ${{ vars.R2_ENDPOINT_URL }} R2_BUCKET: ${{ vars.R2_BUCKET }} AGE_RECIPIENT: ${{ env.R2_RECIPIENT }} MIRROR_ORG: ${{ vars.R2_ORG || vars.MIRROR_ORG || github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} COMMIT_SHA: ${{ github.sha }} run: | set -euo pipefail if [[ ! "$COMMIT_SHA" =~ ^[0-9a-fA-F]{40}$ ]]; then echo "::error::Invalid COMMIT_SHA" exit 1 fi if ! command -v age >/dev/null 2>&1; then sudo apt-get update -qq && sudo apt-get install -y -qq age fi RAW_BUNDLE="$RUNNER_TEMP/${REPO_NAME}.bundle" ENC_BUNDLE="$RUNNER_TEMP/${REPO_NAME}.bundle.age" trap 'rm -f "$RAW_BUNDLE" "$ENC_BUNDLE"' EXIT git bundle create "$RAW_BUNDLE" --all git bundle verify "$RAW_BUNDLE" age -r "$AGE_RECIPIENT" -o "$ENC_BUNDLE" "$RAW_BUNDLE" rm -f "$RAW_BUNDLE" test -s "$ENC_BUNDLE" BUNDLE_TS="$(date -u +%Y%m%dT%H%M%SZ)-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" SNAPSHOT_KEY="s3://${R2_BUCKET}/${MIRROR_ORG}/${REPO_NAME}/snapshots/${BUNDLE_TS}-${COMMIT_SHA}.bundle.age" LATEST_KEY="s3://${R2_BUCKET}/${MIRROR_ORG}/${REPO_NAME}/latest.bundle.age" aws s3 cp "$ENC_BUNDLE" "$SNAPSHOT_KEY" --endpoint-url "$R2_ENDPOINT" aws s3 cp "$ENC_BUNDLE" "$LATEST_KEY" --endpoint-url "$R2_ENDPOINT" - name: Skipped (R2 credentials or age recipient not configured) if: ${{ env.R2_KEY_ID == '' || env.R2_SECRET_KEY == '' || env.R2_RECIPIENT == '' }} run: | echo "::notice::R2_BUNDLE_MIRROR_ENABLED=true but R2 credentials or R2_AGE_RECIPIENT are empty. Skipping R2 bundle upload."