Skip to content
Open
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Mirror to GitLab and trigger GitLab CI

This is a GitHub Action that mirrors commits and pull requests from Github to GitLab. The workflow involves 3 repositories, namely: mirror, source(SOURCE_REPO) and target(TARGET_REPO). The mirror and source repositories need to be on Github whereas the target repository should be on Gitlab. A Github action in the mirror repository, triggered by a manual action, scans the source repo and clones selective items to the target repository. Examples of github actions in the mirror repository are provided below. CI in Gitlab will be triggered based on the settings of the target repository. This action will wait and return the status and url of the pipeline back to the source repository on GitHub.
This is a GitHub Action that mirrors commits and pull requests from Github to GitLab.
The workflow involves 3 repositories, namely:
1. mirroring repo,
2. source(SOURCE_REPO) and
3. target(TARGET_REPO).

The mirroring and source repositories need to be on Github whereas the target repository should be on Gitlab. A Github action in the mirroring repository, triggered by a manual action, scans the source repo and clones selective items to the target repository. Examples of github actions in the mirror repository are provided below. CI in Gitlab will be triggered based on the settings of the target repository. This action will wait and return the status and url of the pipeline back to the source repository on GitHub.

To provide some level of security, the action restricts what commits can be cloned (and therefore initiate CI) into Gitlab. Activites tied to the (approved-)user providing the SOURCE_PAT, a Github token, are eligible to be cloned. The events considered are push and pull requests. Commits, based in push or in a pull request, are eligible if they are authored by the approved-user or if the commit/PR has an approval comment associated with it. In the case of testing a PR the comment must be more recent than the latest commit. The approved user is expected to review the code before undertaking these actions.

Expand All @@ -11,6 +17,21 @@ The most important workflow is testing pull requests from forks, as this is not

Push workflows target a specific branch. Whereas PRs can target a specific PR by providing the optional argument PR_NUMBER

Possible steps:
Setting up the workflow
1. Create a mirroring repository (see example repository below)
2. Add one or more of the example workflows provided below for your intended workflow
3. Create source and target PAT and add them to the mirroring repo
Using the workflow
4. If commits/PR are from non-approved user, provide approval string in commit/PR comment.
5. Trigger GitHub action in mirroring repository.

## Example repositories
Source repo: https://github.com/adityakavalur/source_repo
Mirroring repo: https://github.com/adityakavalur/mirroring_repo
Target repo: https://gitlab.com/akavalur/target_repo


## Example workflows

There are 3 example workflows that this action can support: push, internal pull request and fork pull request. You can leverage any or all of them. All fields are mandatory unless explicitly specified.
Expand Down Expand Up @@ -107,4 +128,5 @@ jobs:

Be sure to define the secrets `SOURCE_PAT` and `TARGET_PAT` in secrets.


This repo expands on work done by SvanBoxel in https://github.com/SvanBoxel/gitlab-mirror-and-ci-action