Skip to content

Commit 241ef9f

Browse files
kingofzealpeaceiris
authored andcommitted
feat: Add emptyCommits option (#22)
* feat: Add emptyCommits option (@kingofzeal) * docs: Update README about emptyCommits option (@kingofzeal) * gha: Update trigger of docker image ci workflow (@peaceiris) Close #21
1 parent dea149a commit 241ef9f

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

.github/workflows/docker-image-ci.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: docker image ci
22

3-
on:
4-
push:
5-
branches:
6-
- master
7-
- 'release-v*'
3+
on: push
84

95
jobs:
106
test:
@@ -20,16 +16,6 @@ jobs:
2016
docker build . --file Dockerfile --tag ${DOCKER_IMAGE} ||
2117
(echo -e "\e[31m[${GITHUB_WORKFLOW}] failed to build\e[m" && exit 1)
2218
23-
# - name: push latest image
24-
# if: endsWith(github.ref, 'master')
25-
# env:
26-
# DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/action:latest
27-
# PKG_GITHUB_TOKEN: ${{ secrets.PKG_GITHUB_TOKEN }}
28-
# run: |
29-
# echo ${PKG_GITHUB_TOKEN} | docker login docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin &&
30-
# docker push ${DOCKER_IMAGE} &&
31-
# docker logout
32-
3319
shellcheck:
3420
runs-on: ubuntu-18.04
3521
steps:

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Table of Contents
2727
- [:star: Pull action image from Docker Hub](#star-pull-action-image-from-docker-hub)
2828
- [:star: `PERSONAL_TOKEN`](#star-personal_token)
2929
- [:star: `GITHUB_TOKEN`](#star-github_token)
30+
- [:star: Suppressing empty commits](#star-suppressing-empty-commits)
3031
- [Examples](#examples)
3132
- [Static Site Generators with Node.js](#static-site-generators-with-nodejs)
3233
- [Gatsby](#gatsby)
@@ -156,6 +157,25 @@ By pulling docker images, you can reduce the overall execution time of your work
156157
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157158
```
158159

160+
#### :star: Suppressing empty commits
161+
162+
By default, a commit will always be generated and pushed to the `PUBLISH_BRANCH`, even if nothing changed. If you want to suppress this behavior, set the optional parameter `emptyCommits` to `false`. cf. [Issue #21]
163+
164+
[Issue #21]: https://github.com/peaceiris/actions-gh-pages/issues/21
165+
166+
For example:
167+
168+
```yaml
169+
- name: deploy
170+
uses: peaceiris/[email protected]
171+
env:
172+
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
173+
PUBLISH_BRANCH: gh-pages
174+
PUBLISH_DIR: ./public
175+
with:
176+
emptyCommits: false
177+
```
178+
159179

160180

161181
## Examples

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ runs:
77
branding:
88
icon: 'upload-cloud'
99
color: 'blue'
10+
inputs:
11+
emptyCommits:
12+
description: 'If empty commits should be made to the publication branch'
13+
required: false
14+
default: 'true'

entrypoint.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
7171
git remote rm origin || true
7272
git remote add origin "${remote_repo}"
7373
git add --all
74-
git commit --allow-empty -m "Automated deployment: $(date -u) ${GITHUB_SHA}"
74+
75+
print_info "Allowing empty commits: ${INPUT_EMPTYCOMMITS}"
76+
COMMIT_MESSAGE="Automated deployment: $(date -u) ${GITHUB_SHA}"
77+
if [[ ${INPUT_EMPTYCOMMITS} == "true" ]]; then
78+
git commit --allow-empty -m "${COMMIT_MESSAGE}"
79+
else
80+
git commit -m "${COMMIT_MESSAGE}" || \
81+
print_info "No changes detected, skipping deployment" && \
82+
exit 0
83+
fi
84+
7585
git push origin "${remote_branch}"
7686
print_info "${GITHUB_SHA} was successfully deployed"

0 commit comments

Comments
 (0)