Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/mirror-gitlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Mirror to GitLab

on:
push:
branches:
- "main"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: mirror-gitlab-${{ github.ref }}
cancel-in-progress: false

jobs:
mirror:
name: Mirror to GitLab
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
fetch-depth: 0
persist-credentials: false

- name: Push to GitLab mirror
env:
GITLAB_MIRROR_KEY: ${{ secrets.GITLAB_MIRROR_KEY }}
run: |
set -euo pipefail

if [ -z "${GITLAB_MIRROR_KEY:-}" ]; then
echo "::error::GITLAB_MIRROR_KEY secret is not set."
exit 1
fi

SSH_DIR="$(mktemp -d)"
trap 'rm -rf "$SSH_DIR"' EXIT

chmod 700 "$SSH_DIR"
printf '%s\n' "$GITLAB_MIRROR_KEY" > "$SSH_DIR/id_ed25519"
chmod 600 "$SSH_DIR/id_ed25519"
printf '%s\n' 'gitlab.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf' > "$SSH_DIR/known_hosts"
chmod 644 "$SSH_DIR/known_hosts"

export GIT_SSH_COMMAND="ssh -i $SSH_DIR/id_ed25519 -o UserKnownHostsFile=$SSH_DIR/known_hosts -o StrictHostKeyChecking=yes -o IdentitiesOnly=yes"

git push "git@gitlab.com:${GITHUB_REPOSITORY}.git" "HEAD:refs/heads/${GITHUB_REF_NAME}"
Loading