From 3da93ca9b455d3e73845f9e5c95c8bf180cda50d Mon Sep 17 00:00:00 2001 From: Devanarayanan Date: Fri, 4 Dec 2026 15:28:26 +0000 Subject: [PATCH] ci: add automated GitLab mirror on main push --- .github/workflows/mirror-gitlab.yml | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/mirror-gitlab.yml diff --git a/.github/workflows/mirror-gitlab.yml b/.github/workflows/mirror-gitlab.yml new file mode 100644 index 0000000..a200351 --- /dev/null +++ b/.github/workflows/mirror-gitlab.yml @@ -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}"