feat: new option keepFiles (#33)

This commit is contained in:
Roman Hotsiy 2019-09-24 19:41:21 +02:00 committed by Shohei Ueda
parent 13d694636e
commit 8eedda6921
3 changed files with 27 additions and 1 deletions

View File

@ -199,6 +199,23 @@ For example:
emptyCommits: false
```
#### ⭐️ Keeping existing files
By default, existing files in the publish branch are removed before adding the ones from publish dir. If you want the action to add new files but leave existing ones untouched, set the optional parameter `keepFiles` to `true`.
For example:
```yaml
- name: deploy
uses: peaceiris/actions-gh-pages@v2.3.2
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
with:
keepFiles: true
```
## Tips and FAQ

View File

@ -12,3 +12,7 @@ inputs:
description: 'If empty commits should be made to the publication branch'
required: false
default: 'true'
keepFiles:
description: 'If existing files in the publish branch should be not removed before deploying'
required: false
default: 'false'

View File

@ -61,7 +61,12 @@ remote_branch="${PUBLISH_BRANCH}"
local_dir="${HOME}/$(tr -cd 'a-f0-9' < /dev/urandom | head -c 32)"
if git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
cd "${local_dir}"
git rm -r --ignore-unmatch '*'
print_info "Keeping existing files: ${INPUT_KEEPFILES}"
if [[ ${INPUT_KEEPFILES} != "true" ]]; then
git rm -r --ignore-unmatch '*'
fi
find "${GITHUB_WORKSPACE}/${PUBLISH_DIR}" -maxdepth 1 | \
tail -n +2 | \
xargs -I % cp -rf % "${local_dir}/"