This GitHub Action mirrors a repository to another repository while rewriting git history to ignore certain files or directories. It is based on the original repository-mirroring-action by pixta-dev, but with some added features:
- It supports .mirrorignore file to ignore certain paths when mirroring.
- It adds .gitkeep and .private files to the ignored directories that exist on the last commit.
- It commits these changes as
github.actor.
This action is perfect for maintaining a clean, public-facing mirror of a private repository.
- It's recommended to set it to run on main branch pushes and deletions. You can configure the branch in the settings of the GitHub action.
- It runs within a Docker environment, containing the pushed repository at
/github/workspaces. - It uses
git-filter-repoto rewrite git history, removing all paths (directories and files) specified in the.mirrorignorefile. See the documentation for more details about git-filter-repo mechanisms. - If any removed directories were present on the last commit, they will be replaced with a directory containing
.gitkeepand.privatefiles. - These changes are committed and pushed to the mirror repository.
- All caveats present in
git-filter-repoapply here. Check here for detailed limitations. - Only one branch is mirrored, as set by
main_branchaction parameter.
Customize following example workflow (namely replace <username>/<target_repository_name> with the right information) and save as .github/workflows/main.yml on your source repository.
To find out how to create and add the GITLAB_SSH_PRIVATE_KEY, follow the steps below:
- How to generate an SSH key pair. Recommended encryption would be at least
2048-bit RSA. - Add the public key to your gitlab account
- Add the private key as a secret to your workflow. More information on creating and using secrets.
name: Mirroring
on:
push:
branches:
- master
jobs:
public_mirror:
runs-on: ubuntu-latest
steps:
# <-- must use actions/checkout before mirroring!
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: usher-labs/monorepo-package-mirror-action@main
with:
target_repo_url:
git@github.com:<username>/<target_repository_name>.git
ssh_private_key:
# <-- use 'secrets' to pass credential information.
${{ secrets.SSH_PRIVATE_KEY }}
main_branch: masterTo avoid copying specific files or directories on the mirrored repository, you can add a .mirrorignore file to the root of the source repository.
# .mirrorignore example content
# Be aware: the mirrorignore parse isn't robust
# file path format:
# path/to/file.txt
# directory path format:
# path/to/dir or path/to/dir
# spaces on files or folders isn't supported.
# glob pattern isn't supported.
# negate paths with a leading !, for example:
# !contracts/evm
# won't copy the following files to the mirror repo
packages/broker
packages/validator
# to avoid copying again this action to the mirror
# rename to the appropriate action file
.github/workflows/public-mirror.ymlThis action is based on the original repository-mirroring-action by pixta-dev. We've added features for more flexibility when mirroring repositories, especially when some files or directories need to be kept private.