Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,57 @@ jobs:
email: andr3.storhaug+bot@gmail.com
```

## Tips

### Copy folder contents only
By default, `copycat-action` copies the folder *and* its contents at `src_path` to `dst_path` when the end of your path is a folder.
To only copy the contents of a folder, you can just include a dot at the end of the `src_path`. The dot at the end tells it to copy the contents of the current directory, not the directory itself. Since this repo uses `cp`, its predictable. This method also will also include hidden files and folders.

Example:
```yaml
- name: deploy
uses: andstor/copycat-action@v3.2.4
with:
personal_token: ${{ secrets.GIT_TOKEN }}
src_path: some/path/.
dst_path: /.
dst_owner: username
dst_repo_name: repo_name
commit_message: 'New Prod Release'
```


## Troubleshooting

### Cloning Failed
Error:
```
warning: Could not find remote branch <...> to clone.
fatal: Remote branch <...> not found in upstream origin
Cloning '<...>' failed
```
By default, `copycat-action` creates a destination branch if it doesn't exist. See more discussion [here](https://github.com/andstor/copycat-action/issues/25).
If your cloning fails, it is likely due to a typo when you provided the `src_branch` and/or `dst_branch` args to `copycat-action`.

If you don't explicitly provide the `src_branch` and/or `dst_branch` args to `copycat-action`, your default branch names should both be "master". Otherwise you'll get an error very similar to above.

Reference:
```yaml
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'
```

A while back, GitHub started naming the master branch "main" by default. Since `copycat-action` looks for a "master" branch by default, you have to explicity provide branch names if you are using Github's new naming convention "main" for your default branch. Obviously if you are already using custom branch names, you have to explicity specify them.

We are keeping the default for both args as "master" since it is compliant with the *majority* of repos out there, but currently exploring options to automatically detect the default branch name.

## Author

The Copycat GitHub action is written by [André Storhaug](https://github.com/andstor) <andr3.storhaug@gmail.com>
Expand Down
14 changes: 12 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@ DST_PATH="${DST_PATH:-${SRC_PATH}}"
USERNAME="${USERNAME:-${GITHUB_ACTOR}}"
EMAIL="${EMAIL:-${GITHUB_ACTOR}@users.noreply.github.com}"

SRC_BRANCH="${SRC_BRANCH:-master}"
DST_BRANCH="${DST_BRANCH:-master}"
#Default Branch name checks

#SRC
SRC_DEFAULT_BRANCH_NAME=${git ls-remote --symref https://${PERSONAL_TOKEN}@github.com/${SRC_REPO}.git HEAD | awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}'}
echo "SRC default branch name is: \"${DEF_BRANCH_NAME}\""

#DST
DST_DEFAULT_BRANCH_NAME=${git ls-remote --symref https://${PERSONAL_TOKEN}@github.com/${DST_REPO}.git HEAD | awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}'}
echo "DST default branch name is: \"${DEF_BRANCH_NAME}\""

SRC_BRANCH="${origin:-${SRC_DEFAULT_BRANCH_NAME}}"
DST_BRANCH="${origin:-${DST_DEFAULT_BRANCH_NAME}}"

SRC_REPO="${GITHUB_REPOSITORY}${SRC_WIKI}"
SRC_REPO_NAME="${GITHUB_REPOSITORY#*/}${SRC_WIKI}"
Expand Down