-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update action with an action.yml and change env variables to input va…
…riables
- Loading branch information
Showing
11 changed files
with
1,908 additions
and
703 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
FROM alpine:3.10 | ||
|
||
LABEL repository="https://github.com/andstor/copycat-action" | ||
LABEL homepage="https://github.com/andstor/copycat-action" | ||
LABEL "maintainer"="André Storhaug <[email protected]>" | ||
|
||
LABEL "com.github.actions.name"="Copycat Action" | ||
LABEL "com.github.actions.description"="Copy files to other repositories" | ||
LABEL "com.github.actions.icon"="copy" | ||
LABEL "com.github.actions.color"="red" | ||
|
||
RUN apk add --no-cache git | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,87 @@ | ||
# Copycat | ||
<a href="https://github.com/andstor/copycat-action"><img | ||
src="media/logo.svg" alt="Copycat Logo" | ||
width="120" height="auto" align="right"></a> | ||
<p align=center> | ||
<img width="240" src="media/logo.svg" alt="Copycat Logo"> | ||
</p> | ||
<h1 align="center">COPYCAT</h1> | ||
|
||
[GitHub action](https://developer.github.com/actions/) for copying files from one repository to another. | ||
> GitHub Action for copying files to other repositories. | ||
This is a [GitHub action](https://developer.github.com/actions/) to copy files from your repository to another external repository. It is also possible to copy files from/to repository Wikis. | ||
|
||
This action runs in a Docker container and therefore only supports Linux. | ||
|
||
## Usage | ||
|
||
The following example [workflow step](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow) will copy all files from the repository running the action, to a folder named `backup` in the destination repo `copycat-action`. If the files already exist at the destination repo, they will be overwritten. | ||
|
||
```yml | ||
- name: Copy | ||
uses: andstor/copycat-action@v2 | ||
with: | ||
personal_token: ${{ secrets.PERSONAL_TOKEN }} | ||
src_path: /. | ||
dst_path: /backup/ | ||
dst_owner: andstor | ||
dst_repo_name: copycat-action | ||
``` | ||
## Options ⚙️ | ||
The following input variable options can/must be configured: | ||
|Input variable|Necessity|Description|Default| | ||
|--------------------|--------|-----------|-------| | ||
|`src_path`|Required|The source path to the file(s) or folder(s) to copy from. For example, `/.` or `path/to/home.md`.|| | ||
|`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`| | ||
|`dst_owner`|Required|The name of the owner of the repository to push to. For example, `andstor`.|| | ||
|`dst_repo_name`|Required|The name of the repository to push to. For example, `copycat-action`.|| | ||
|`src_branch`|Optional|The branch name of the source repository.|`master`| | ||
|`dst_branch`|Optional|The branch name of the destination repository.|`master`| | ||
|`src_filter`|Optional|A pattern for filtering files to be copied. For example `*.sh`|| | ||
|`src_wiki`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| | ||
|`dst_wiki`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| | ||
|`username`|Optional|The GitHub username to associate commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)| | ||
|`email`|Optional|The email used for associating commits made by this GitHub action.|[`GITHUB_ACTOR`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)`@users.noreply.github.com`| | ||
|
||
## Secrets | ||
|
||
* `personal_token`: (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). | ||
|
||
|
||
## Examples | ||
|
||
### Copy wiki files to external repo | ||
|
||
This workflow configuration will copy all files from the repository's wiki to a folder named `wiki` in the destination repo `andstor.github.io`. | ||
|
||
This can for example be used to merge several wikies of an organisation, and display them on a custom GitHub Pages site. The Jekyll theme [Paper](https://github.com/andstor/jekyll-theme-paper) has support for this. | ||
|
||
```yml | ||
name: Copy | ||
on: gollum | ||
jobs: | ||
copycat: | ||
name: Copycat | ||
copy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Copycat | ||
uses: andstor/copycat-action@v1.1.0 | ||
env: | ||
DST_BRANCH: master | ||
DST_OWNER: andstor | ||
DST_REPO_NAME: copycat-action | ||
DST_PATH: /wiki/ | ||
GH_PAT: ${{ secrets.GH_PAT }} | ||
SRC_BRANCH: master | ||
SRC_PATH: /. | ||
SRC_WIKI: "true" | ||
USERNAME: nutsbot | ||
EMAIL: [email protected] | ||
uses: andstor/copycat-action@v2 | ||
with: | ||
personal_token: ${{ secrets.PERSONAL_TOKEN }} | ||
src_path: /. | ||
dst_path: /wiki/ | ||
dst_owner: andstor | ||
dst_repo_name: andstor.github.io | ||
dst_branch: master | ||
src_branch: master | ||
src_wiki: true | ||
dst_wiki: false | ||
username: nutsbot | ||
email: [email protected] | ||
``` | ||
|
||
## Environment variables | ||
The following environment variable options can/must be configured: | ||
|
||
|Environment variable|Required|Description|Default| | ||
|--------------------|--------|-----------|-------| | ||
|`SRC_PATH`|Required|The source path to the file(s) or folder(s) to copy from. For example, `/.` or `path/to/home.md`.|| | ||
|`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`| | ||
|`DST_OWNER`|Required|The name of the owner of the repository to push to. For example, `andstor`.|| | ||
|`DST_REPO_NAME`|Required|The name of the repository to push to. For example, `copycat-action`.|| | ||
|`SRC_BRANCH`|Optional|The branch name of the source repository. Optional.|`master`| | ||
|`DST_BRANCH`|Optional|The branch name of the destination repository. Optional.|`master`| | ||
|`SRC_FILTER`|Optional|A pattern for filtering files to be copied. For example `*.sh`|| | ||
|`SRC_WIKI`|Optional|Set to `true` if the source repository you want to copy from is the GitHub Wiki.| `false`| | ||
|`DST_WIKI`|Optional|Set to `true` if the destination repository you want to copy from is the GitHub Wiki.|`false`| | ||
|`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)| | ||
|`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`| | ||
|
||
## Secrets | ||
* `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). | ||
|
||
## Author | ||
|
||
The Copycat GitHub action is written by [André Storhaug](https://github.com/andstor) <[email protected]> | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: 'Copycat' | ||
description: 'GitHub Action for copying files to other repositories' | ||
author: 'André Storhaug' | ||
branding: | ||
icon: 'copy' | ||
color: 'red' | ||
inputs: | ||
personal_token: | ||
description: 'Personal access token' | ||
required: true | ||
src_path: | ||
description: 'The source path to the file(s) or folder(s) to copy from' | ||
required: true | ||
dst_path: | ||
description: 'The destination path to copy the file(s) or folder(s) to' | ||
required: false | ||
dst_owner: | ||
description: 'The name of the owner of the repository to push to' | ||
required: true | ||
dst_repo_name: | ||
description: 'The name of the repository to push to' | ||
required: true | ||
src_branch: | ||
description: 'The branch name of the source repository' | ||
required: false | ||
default: 'master' | ||
dst_branch: | ||
description: 'The branch name of the destination repository' | ||
required: false | ||
default: 'master' | ||
src_filter: | ||
description: 'A pattern for filtering files to be copied' | ||
required: false | ||
src_wiki: | ||
description: 'Set to true if the source repository you want to copy from is the GitHub Wiki' | ||
default: false | ||
required: false | ||
dst_wiki: | ||
description: 'Set to true if the destination repository you want to copy from is the GitHub Wiki' | ||
required: false | ||
default: false | ||
username: | ||
description: 'The GitHub username to associate commits made by this GitHub action' | ||
required: false | ||
email: | ||
description: 'The email used for associating commits made by this GitHub action' | ||
required: false | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.personal_token }} | ||
- ${{ inputs.src_path }} | ||
- ${{ inputs.dst_path }} | ||
- ${{ inputs.dst_owner }} | ||
- ${{ inputs.dst_repo_name }} | ||
- ${{ inputs.src_branch }} | ||
- ${{ inputs.dst_branch }} | ||
- ${{ inputs.src_filter }} | ||
- ${{ inputs.src_wiki }} | ||
- ${{ inputs.dst_wiki }} | ||
- ${{ inputs.username }} | ||
- ${{ inputs.email }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
#!/bin/sh | ||
# | ||
# @author André Storhaug <[email protected]> | ||
# @date 2019-07-01 | ||
# @copyright MIT | ||
# @version 1.2.0 | ||
# @date 2020-02-22 | ||
# @license MIT | ||
# @version 2.0.0 | ||
|
||
set -o pipefail | ||
|
||
PERSONAL_TOKEN="$INPUT_PERSONAL_TOKEN" | ||
SRC_PATH="$INPUT_SRC_PATH" | ||
DST_PATH="$INPUT_DST_PATH" | ||
DST_OWNER="$INPUT_DST_OWNER" | ||
DST_REPO_NAME="$INPUT_DST_REPO_NAME" | ||
SRC_BRANCH="$INPUT_SRC_BRANCH" | ||
DST_BRANCH="$INPUT_DST_BRANCH" | ||
SRC_WIKI="$INPUT_SRC_WIKI" | ||
DST_WIKI="$INPUT_DST_WIKI" | ||
USERNAME="$INPUT_USERNAME" | ||
EMAIL="$INPUT_EMAIL" | ||
|
||
if [[ -z "$SRC_PATH" ]]; then | ||
echo "SRC_PATH environment variable is missing. Cannot proceed." | ||
exit 1 | ||
|
@@ -59,7 +71,7 @@ else | |
echo "Copying files matching \"${SRC_FILTER}\" from \"${SRC_REPO_NAME}/${SRC_PATH}\" and pushing it to ${GITHUB_REPOSITORY}" | ||
fi | ||
|
||
git clone --branch ${SRC_BRANCH} --single-branch --depth 1 https://${GH_PAT}@github.com/${SRC_REPO}.git | ||
git clone --branch ${SRC_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${SRC_REPO}.git | ||
if [ "$?" -ne 0 ]; then | ||
echo >&2 "Cloning '$SRC_REPO' failed" | ||
exit 1 | ||
|
@@ -70,7 +82,7 @@ if [[ -n "$SRC_FILTER" ]]; then | |
find ${SRC_REPO_NAME}/ -type f -not -name "${SRC_FILTER}" -exec rm {} \; | ||
fi | ||
|
||
git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${GH_PAT}@github.com/${DST_REPO}.git | ||
git clone --branch ${DST_BRANCH} --single-branch --depth 1 https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git | ||
if [ "$?" -ne 0 ]; then | ||
echo >&2 "Cloning '$DST_REPO' failed" | ||
exit 1 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.