├── media ├── logo.ai ├── logo.png └── logo.svg ├── Dockerfile ├── LICENSE ├── README.md └── entrypoint.sh /media/logo.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/documentation-copycat-action/master/media/logo.ai -------------------------------------------------------------------------------- /media/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/documentation-copycat-action/master/media/logo.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.10 2 | 3 | LABEL repository="https://github.com/andstor/copycat-action" 4 | LABEL homepage="https://github.com/andstor/copycat-action" 5 | LABEL "maintainer"="André Storhaug " 6 | 7 | LABEL "com.github.actions.name"="Copycat Action" 8 | LABEL "com.github.actions.description"="Copy files to other repositories" 9 | LABEL "com.github.actions.icon"="copy" 10 | LABEL "com.github.actions.color"="red" 11 | 12 | RUN apk add --no-cache git 13 | 14 | COPY entrypoint.sh /entrypoint.sh 15 | ENTRYPOINT ["/entrypoint.sh"] 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 André Storhaug 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Copycat 2 | Copycat Logo 5 | 6 | [GitHub action](https://developer.github.com/actions/) for copying files from one repository to another. 7 | 8 | ## Usage 9 | ``` 10 | name: Copy 11 | on: gollum 12 | jobs: 13 | copycat: 14 | name: Copycat 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@master 18 | - name: Copycat 19 | uses: andstor/copycat-action@v1.1.0 20 | env: 21 | DST_BRANCH: master 22 | DST_OWNER: andstor 23 | DST_REPO_NAME: copycat-action 24 | DST_PATH: /wiki/ 25 | GH_PAT: ${{ secrets.GH_PAT }} 26 | SRC_BRANCH: master 27 | SRC_PATH: /. 28 | SRC_WIKI: "true" 29 | USERNAME: nutsbot 30 | EMAIL: andr3.storhaug+bot@gmail.com 31 | 32 | ``` 33 | 34 | ## Environment variables 35 | The following environment variable options can/must be configured: 36 | 37 | |Environment variable|Required|Description|Default| 38 | |--------------------|--------|-----------|-------| 39 | |`SRC_PATH`|Required|The source path to the file(s) or folder(s) to copy from. For example, `/.` or `path/to/home.md`.|| 40 | |`DST_PATH`|Optional|The destination path to copy the file(s) or folder(s) to. For example, `/wiki/` or `path/to/index.md`. |`SRC_PATH`| 41 | |`DST_OWNER`|Required|The name of the owner of the repository to push to. For example, `andstor`.|| 42 | |`DST_REPO_NAME`|Required|The name of the repository to push to. For example, `copycat-action`.|| 43 | |`SRC_BRANCH`|Optional|The branch name of the source repository. Optional.|`master`| 44 | |`DST_BRANCH`|Optional|The branch name of the destination repository. Optional.|`master`| 45 | |`SRC_FILTER`|Optional|A pattern for filtering files to be copied. For example `*.sh`|| 46 | |`SRC_WIKI`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| 47 | |`DST_WIKI`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| 48 | |`USERNAME`|Optional|The GitHub username to associate commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/articles/virtual-environments-for-github-actions#environment-variables)| 49 | |`EMAIL`|Optional|The email used for associating commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/articles/virtual-environments-for-github-actions#environment-variables)`@users.noreply.github.com`| 50 | 51 | ## Secrets 52 | * `GH_PAT`: (required) GitHub Private Access Token used for the clone/push operations. To create it follow the [GitHub Documentation](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). 53 | 54 | ## Author 55 | The Copycat GitHub action is written by [André Storhaug](https://github.com/andstor) 56 | 57 | ## License 58 | This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details. 59 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # @author André Storhaug 4 | # @date 2019-07-01 5 | # @copyright MIT 6 | # @version 1.2.0 7 | 8 | set -o pipefail 9 | 10 | if [[ -z "$SRC_PATH" ]]; then 11 | echo "SRC_PATH environment variable is missing. Cannot proceed." 12 | exit 1 13 | fi 14 | 15 | if [[ -z "$DST_OWNER" ]]; then 16 | echo "DST_OWNER environment variable is missing. Cannot proceed." 17 | exit 1 18 | fi 19 | 20 | if [[ -z "$DST_REPO_NAME" ]]; then 21 | echo "DST_REPO_NAME environment variable is missing. Cannot proceed." 22 | exit 1 23 | fi 24 | 25 | if [ "$SRC_WIKI" = "true" ]; then 26 | SRC_WIKI=".wiki" 27 | else 28 | SRC_WIKI="" 29 | fi 30 | 31 | if [ "$DST_WIKI" = "true" ]; then 32 | DST_WIKI=".wiki" 33 | else 34 | DST_WIKI="" 35 | fi 36 | 37 | BASE_PATH=$(pwd) 38 | DST_PATH="${DST_PATH:-${SRC_PATH}}" 39 | 40 | USERNAME="${USERNAME:-${GITHUB_ACTOR}}" 41 | EMAIL="${EMAIL:-${GITHUB_ACTOR}@users.noreply.github.com}" 42 | 43 | SRC_BRANCH="${SRC_BRANCH:-master}" 44 | DST_BRANCH="${DST_BRANCH:-master}" 45 | 46 | SRC_REPO="${GITHUB_REPOSITORY}${SRC_WIKI}" 47 | SRC_REPO_NAME="${GITHUB_REPOSITORY#*/}${SRC_WIKI}" 48 | DST_REPO="${DST_OWNER}/${DST_REPO_NAME}${DST_WIKI}" 49 | DST_REPO_NAME="${DST_REPO_NAME}${DST_WIKI}" 50 | 51 | DIR="${DST_PATH%/*}" 52 | 53 | git config --global user.name "${USERNAME}" 54 | git config --global user.email "${EMAIL}" 55 | 56 | if [[ -z "$SRC_FILTER" ]]; then 57 | echo "Copying \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" 58 | else 59 | echo "Copying files matching \"${SRC_FILTER}\" from \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" 60 | fi 61 | 62 | git clone --branch ${SRC_BRANCH} --single-branch --depth 1 https://${GH_PAT}@github.com/${SRC_REPO}.git 63 | if [ "$?" -ne 0 ]; then 64 | echo >&2 "Cloning '$SRC_REPO' failed" 65 | exit 1 66 | fi 67 | rm -rf ${SRC_REPO_NAME}/.git 68 | 69 | if [[ -n "$SRC_FILTER" ]]; then 70 | find ${SRC_REPO_NAME}/ -type f -not -name "${SRC_FILTER}" -exec rm {} \; 71 | fi 72 | 73 | git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${GH_PAT}@github.com/${DST_REPO}.git 74 | if [ "$?" -ne 0 ]; then 75 | echo >&2 "Cloning '$DST_REPO' failed" 76 | exit 1 77 | fi 78 | 79 | mkdir -p ${DST_REPO_NAME}/${DIR} || exit "$?" 80 | cp -rf ${SRC_REPO_NAME}/${SRC_PATH} ${DST_REPO_NAME}/${DST_PATH} || exit "$?" 81 | cd ${DST_REPO_NAME} || exit "$?" 82 | 83 | if [ -d "${BASE_PATH}/${SRC_REPO_NAME}/${SRC_PATH}" ]; then 84 | COMMIT_MESSAGE="Update file(s) in \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" 85 | else 86 | COMMIT_MESSAGE="Update file \"${SRC_PATH}\" from \"${GITHUB_REPOSITORY}\"" 87 | fi 88 | 89 | if [ -z "$(git status --porcelain)" ]; then 90 | # Working directory is clean 91 | echo "No changes detected " 92 | else 93 | # Uncommitted changes 94 | git add -A 95 | git commit --message "${COMMIT_MESSAGE}" 96 | git push origin ${DST_BRANCH} 97 | fi 98 | 99 | echo "Copying complete 👌" 100 | -------------------------------------------------------------------------------- /media/logo.svg: -------------------------------------------------------------------------------- 1 | Artboard 1 --------------------------------------------------------------------------------