Can github-action-push-to-another-repository be used to publish Sphinx documentation into GitHub pages?

Yes, see the example.

How can I copy only some files / only some directories / exclude some files / etc.?

If you need to filter files or directories (exclude files, include only some, etc.) use a step before the Action to filter these into a temporary directory that will be pushed. This can be done with “rsync” or any tool that you feel comfortable with (this could be “rclone” or “find + exec + rm”, “find + exec + mv”, etc. depending on your needs).

See a working example to exclude a generated file (main.epub).

    runs-on: ubuntu-latest
    container: ubuntu
      - uses: actions/checkout@v2
      - name: Copy output_temp/ to output/ using rsync (to exclude main.epub in this example)
        run:  apk add rsync && rsync -arv --exclude="/main.epub" output_temp/ output/
      - name: Pushes to another repository
        id: push_directory
        uses: cpina/github-action-push-to-another-repository@main
          SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
          source-directory: output/
          destination-github-username: 'cpina'
          destination-repository-name: 'push-to-another-repository-output'
          user-email: carles3@pina.cat
          target-branch: main

In the step above, rsync is installed (depending on your environment it will already be installed) and everything is copied from output_temp to output excluding main.epub. Be careful with the usage of “/” and the exclude parameter in rsync directories. Refer to the rsync documentation for other options such as filtering using an extension to include only some files / directories, etc. rsync filters are very flexible.

How can I copy the whole repository?

Use source_directory: . do not use destination-directory or destination-directory: ., to copy all the source GitHub repository to the destination.


This will also copy .github/workflows/! The destination repository will try to execute the Action. It will probably fail because the SSH keys / Personal Access Token will not be available for the destination repository.

An easy way to avoid the execution in the destination repository if you are using source_directory: . is to disable the GitHub Actions in the destination repository. To disable GitHub Actions in the destination repository:

  1. Go to the destination repository (e.g. https://github.com/cpina/push-to-another-repository-output/settings)

  2. Click on “Settings”

  3. On the left side bar click on “Actions” and then “General”

  4. Click on “Disable actions”

  5. Click on “Save”

Could it work on Mac OS, Windows or No Docker environments?

The main branch or the main releases (named v1.5.1, etc.) don’t support Mac OS X or Windows, only Linux. This is the reason that something along the lines of the following is needed in .github/workflows/file.yml:

runs-on: ubuntu-latest
container: ubuntu

GitHub runs the Action in a Docker container and makes the files (from the previous steps, like the usual build.sh) available in the container.

There is a different branch of the GitHub Action working on composite mode instead of Docker mode. Specify the @composite-1.5.1 branch, for example:

     - name: Pushes to another repository
       uses: cpina/github-action-push-to-another-repository@composite-1.5.1
         SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
         source-directory: output/
         destination-github-username: 'cpina'
         destination-repository-name: 'push-to-another-repository-playground'
         user-email: carles@pina.cat
         target-branch: pushed-from-action

There are some things that you need to be aware of:

  • the Action uses #!/bin/sh. It should work on workers that can execute #!/bin/sh (Mac should be okay; Windows might need some extra setup)

  • the Action uses the binary ssh-keyscan (usually packaged with openssh-client) and git. They need to be installed if you do not already have them. You might need to modify the action.yml of the forked GitHub Action.

  • because the Action is running in the environment of the real machine, and the environment might be different in different installations and versions, it is possible that problems will occur. Read the output and fork the project if changes are needed. There is no error checking for binaries or versions of git, shell versions, etc. If you need help, get in touch via a new GitHub Issue. If it works for you, feel free to get in touch as well using a GitHub Issue so that I am aware (I will close it saying thank you)