kernel / .github / workflows / mirror.ymlmain at 949894f
name: mirror
# github.com/iterate/kernel is a read-only mirror of https://git.iterate.com/repos/kernel, with the
# same commits. This workflow runs in the mirror: it reads the source's main with no credential and
# pushes it to the mirror's main. The push never forces: when the two have parted, it fails and a
# person looks. A ruleset of the mirror refuses a forced push to main and its deletion.
#
# It pushes with the deploy key in the secret MIRROR_DEPLOY_KEY, which can write to this repository
# alone. The job's own token will not do: GitHub lets it push no commit that changes a workflow, and
# starts no workflow for what it pushes. The key's push starts npm-publish.yml.
#
# After a merge to the source, to mirror at once: `gh workflow run mirror.yml --repo iterate/kernel`.
# GitHub stops a schedule in a repository with no commit for 60 days; a dispatch starts it again.
on:
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:
concurrency:
group: mirror
cancel-in-progress: false
permissions: {}
jobs:
mirror:
if: github.repository == 'iterate/kernel'
runs-on: ubuntu-latest
steps:
- name: Push the source's main to this repository's main
env:
MIRROR_DEPLOY_KEY: ${{ secrets.MIRROR_DEPLOY_KEY }}
run: |
install -m 700 -d "$RUNNER_TEMP/ssh"
install -m 600 /dev/null "$RUNNER_TEMP/ssh/key"
printf '%s\n' "$MIRROR_DEPLOY_KEY" > "$RUNNER_TEMP/ssh/key"
# GitHub's host key (https://docs.github.com/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints)
echo "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl" > "$RUNNER_TEMP/ssh/known_hosts"
export GIT_SSH_COMMAND="ssh -i $RUNNER_TEMP/ssh/key -o IdentitiesOnly=yes -o UserKnownHostsFile=$RUNNER_TEMP/ssh/known_hosts -o StrictHostKeyChecking=yes"
git init --quiet "$RUNNER_TEMP/kernel"
cd "$RUNNER_TEMP/kernel"
git fetch --quiet https://git.iterate.com/repos/kernel main
source="$(git rev-parse FETCH_HEAD)"
mirror="$(git ls-remote git@github.com:iterate/kernel.git refs/heads/main | cut -f1)"
if [ "$source" = "$mirror" ]; then
echo "main is at $source in both" | tee -a "$GITHUB_STEP_SUMMARY"
exit 0
fi
git push --quiet git@github.com:iterate/kernel.git "$source:refs/heads/main"
echo "main: ${mirror:-nothing} to $source" | tee -a "$GITHUB_STEP_SUMMARY"