├── Dockerfile ├── entrypoint.sh ├── action.yml ├── README.md └── LICENSE /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: Git require the .git folder to be 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 | # Set up ssh known hosts and agent 5 | ssh-keyscan -t rsa github.com >> /etc/ssh/ssh_known_hosts 6 | eval `ssh-agent -s` 7 | ssh-add - <<< "$SSH_PRIVATE_KEY" 8 | 9 | # split single parameter of this script into multiple params for the command 10 | eval "set -- $1" 11 | git-filter-repo "$@" 12 | 13 | git push "git@github.com:$TARGET_ORG/$TARGET_REPO.git" HEAD:"$TARGET_BRANCH" 14 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # action.yml 2 | name: 'git-filter-repo-push' 3 | description: 'Runs git-filter-repo and pushes the result to a target using ssh' 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 | filterArguments: 18 | description: 'The raw arguments to pass to git-filter-repo' 19 | runs: 20 | using: 'docker' 21 | image: 'Dockerfile' 22 | env: 23 | SSH_PRIVATE_KEY: ${{ inputs.privateKey }} 24 | TARGET_ORG: ${{ inputs.targetOrg }} 25 | TARGET_REPO: ${{ inputs.targetRepo }} 26 | TARGET_BRANCH: ${{ inputs.targetBranch }} 27 | args: 28 | - ${{ inputs.filterArguments }} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git-filter-repo-docker-action 2 | A GitHub Docker Action to run git-filter-repo and push the result to a GitHub repository using ssh 3 | 4 | This repo contains a github action to trigger a custom git-repo-filter command. 5 | 6 | It is designed to be run on pushes to the main or master branch of a repository 7 | and to then push the resulting filtered repo to another remote using an ssh key. 8 | 9 | # Example Workflow 10 | ``` 11 | name: CI 12 | on: 13 | push: 14 | branches: [ master ] 15 | 16 | jobs: 17 | filter: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | fetch-depth: 0 23 | - name: git-filter-repo 24 | uses: wmde/git-filter-repo-docker-action@v1 25 | with: 26 | privateKey: ${{ secrets.SSH_PRIVATE_KEY }} 27 | targetOrg: wikimedia 28 | targetRepo: wikibase-changes 29 | targetBranch: main 30 | filterArguments: >- 31 | --path=lib/includes/changes/ 32 | --path=lib/includes/Changes/ 33 | --path=lib/tests/phpunit/changes/ 34 | --path=lib/tests/phpunit/Changes/ 35 | --path lib/packages/wikibase/changes/ 36 | --path .mailmap 37 | --path-rename=lib/includes/changes:src 38 | --path-rename=lib/includes/Changes:src 39 | --path-rename=lib/tests/phpunit/changes:tests 40 | --path-rename=lib/tests/phpunit/Changes:tests 41 | --path-rename lib/packages/wikibase/changes/: 42 | --message-callback 'return re.sub(b"^changes: ", b"", message)' 43 | ``` 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, 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 | --------------------------------------------------------------------------------