Skip to content

Commit 1e0de0f

Browse files
authored
feat: Add INPUT_FORCEORPHAN (#43)
* feat: Add INPUT_FORCEORPHAN option (close #42) * docs: Add new section about Force orphan
1 parent e376bcf commit 1e0de0f

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,22 @@ When you use `ACTIONS_DEPLOY_KEY`, set your private key to the repository which
294294

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

297+
### ⭐️ Force orphan
298+
299+
From `v2.6.0`, we can set the `forceOrphan: true` option.
300+
This allows you to make your publish branch with only the latest commit.
301+
302+
```yaml
303+
- name: Deploy
304+
uses: peaceiris/[email protected]
305+
env:
306+
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
307+
PUBLISH_BRANCH: gh-pages
308+
PUBLISH_DIR: ./public
309+
with:
310+
forceOrphan: true
311+
```
312+
297313
### ⭐️ Script mode
298314

299315
From `v2.5.0`, we can run this action as a shell script.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ inputs:
1616
description: 'If existing files in the publish branch should be not removed before deploying'
1717
required: false
1818
default: 'false'
19+
forceOrphan:
20+
description: 'Keep only the latest commit on a GitHub Pages branch'
21+
required: false
22+
default: 'false'

entrypoint.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ fi
7777
remote_branch="${PUBLISH_BRANCH}"
7878

7979
local_dir="${HOME}/ghpages_${RANDOM}"
80-
if git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
80+
81+
if [[ "${INPUT_FORCEORPHAN}" == "true" ]]; then
82+
print_info "force ophan: ${INPUT_FORCEORPHAN}"
83+
cd "${PUBLISH_DIR}"
84+
git init
85+
git checkout --orphan "${remote_branch}"
86+
elif git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
8187
cd "${local_dir}"
8288

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

113-
git push origin "${remote_branch}"
119+
if [[ ${INPUT_FORCEORPHAN} == "true" ]]; then
120+
git push origin --force "${remote_branch}"
121+
else
122+
git push origin "${remote_branch}"
123+
fi
124+
114125
print_info "${GITHUB_SHA} was successfully deployed"

0 commit comments

Comments
 (0)