├── README.md ├── Dockerfile ├── entrypoint.sh ├── LICENSE └── action.yml /README.md: -------------------------------------------------------------------------------- 1 | # git-monorepo-splice-docker-action 2 | GitHub action to splice git histories of libraries before and after being migrated to a monorepo 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8-alpine 2 | 3 | RUN apk update && apk upgrade && \ 4 | apk add --no-cache bash git git-fast-import openssh 5 | 6 | RUN pip3 install git-filter-repo 7 | 8 | # T314987: /github/workspace is not owned by the same user 9 | RUN git config --system --add safe.directory /github/workspace 10 | 11 | COPY entrypoint.sh /entrypoint.sh 12 | 13 | ENTRYPOINT ["/entrypoint.sh"] -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # needed for git rebase to run 5 | git config --global user.email "wmdebot@example.com" 6 | git config --global user.name "WMDE bot" 7 | 8 | # Set up ssh known hosts and agent 9 | ssh-keyscan -t rsa github.com >> /etc/ssh/ssh_known_hosts 10 | eval `ssh-agent -s` 11 | ssh-add - <<< "$SSH_PRIVATE_KEY" 12 | 13 | git remote add upstream "git@github.com:$TARGET_ORG/$TARGET_REPO.git" 14 | git fetch upstream 15 | git replace "$PARENT_COMMIT_ONE" "$PRE_MIGRATION_COMMIT" 16 | git replace "$PARENT_COMMIT_TWO" "$PRE_MIGRATION_COMMIT" 17 | 18 | # split single parameter of this script into multiple params for the command 19 | eval "set -- $1" 20 | git-filter-repo "$@" --refs "$PRE_MIGRATION_COMMIT"..HEAD --force 21 | git rebase upstream/$TARGET_BRANCH 22 | 23 | git push upstream HEAD:"$TARGET_BRANCH" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, Wikimedia Deutschland e. V. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # action.yml 2 | name: 'git-monorepo-splice' 3 | description: 'splice git histories of libraries before and after being migrated to a monorepo' 4 | inputs: 5 | privateKey: 6 | description: 'Private SSH Key for pushing to the target repo' 7 | required: true 8 | targetOrg: 9 | description: 'The github organization (or user) of the target repository' 10 | required: true 11 | targetRepo: 12 | description: 'The target repository' 13 | required: true 14 | targetBranch: 15 | description: 'The target branch' 16 | required: true 17 | monorepoParentCommit1: 18 | description: 'A parent of the merge commit that introduced the library to the monorepo' 19 | required: true 20 | monorepoParentCommit2: 21 | description: 'A parent of the merge commit that introduced the library to the monorepo' 22 | required: true 23 | lastPreMigrationCommit: 24 | description: 'The last commit of the library before merging into the monorepo' 25 | required: true 26 | filterArguments: 27 | description: 'additional arguments to pass to git-filter-repo' 28 | runs: 29 | using: 'docker' 30 | image: 'Dockerfile' 31 | env: 32 | SSH_PRIVATE_KEY: ${{ inputs.privateKey }} 33 | TARGET_ORG: ${{ inputs.targetOrg }} 34 | TARGET_REPO: ${{ inputs.targetRepo }} 35 | TARGET_BRANCH: ${{ inputs.targetBranch }} 36 | PARENT_COMMIT_ONE: ${{ inputs.monorepoParentCommit1 }} 37 | PARENT_COMMIT_TWO: ${{ inputs.monorepoParentCommit2 }} 38 | PRE_MIGRATION_COMMIT: ${{ inputs.lastPreMigrationCommit }} 39 | args: 40 | - ${{ inputs.filterArguments }} --------------------------------------------------------------------------------