Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: Add INPUT_FORCEORPHAN (#43)
* feat: Add INPUT_FORCEORPHAN option (close #42)
* docs: Add new section about Force orphan
  • Loading branch information
Shohei Ueda authored and GitHub committed Dec 22, 2019
1 parent e376bcf commit 1e0de0f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -294,6 +294,22 @@ When you use `ACTIONS_DEPLOY_KEY`, set your private key to the repository which

Be careful, `GITHUB_TOKEN` has no permission to access to external repositories.

### ⭐️ Force orphan

From `v2.6.0`, we can set the `forceOrphan: true` option.
This allows you to make your publish branch with only the latest commit.

```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.6.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
with:
forceOrphan: true
```

### ⭐️ Script mode

From `v2.5.0`, we can run this action as a shell script.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -16,3 +16,7 @@ inputs:
description: 'If existing files in the publish branch should be not removed before deploying'
required: false
default: 'false'
forceOrphan:
description: 'Keep only the latest commit on a GitHub Pages branch'
required: false
default: 'false'
15 changes: 13 additions & 2 deletions entrypoint.sh
Expand Up @@ -77,7 +77,13 @@ fi
remote_branch="${PUBLISH_BRANCH}"

local_dir="${HOME}/ghpages_${RANDOM}"
if git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then

if [[ "${INPUT_FORCEORPHAN}" == "true" ]]; then
print_info "force ophan: ${INPUT_FORCEORPHAN}"
cd "${PUBLISH_DIR}"
git init
git checkout --orphan "${remote_branch}"
elif git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
cd "${local_dir}"

if [[ ${INPUT_KEEPFILES} == "true" ]]; then
Expand Down Expand Up @@ -110,5 +116,10 @@ else
git commit --allow-empty -m "${COMMIT_MESSAGE}"
fi

git push origin "${remote_branch}"
if [[ ${INPUT_FORCEORPHAN} == "true" ]]; then
git push origin --force "${remote_branch}"
else
git push origin "${remote_branch}"
fi

print_info "${GITHUB_SHA} was successfully deployed"

0 comments on commit 1e0de0f

Please sign in to comment.