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
This commit is contained in:
James McCollum 2019-09-14 13:49:20 -05:00 committed by Shohei Ueda
parent dea149a296
commit 241ef9fea0
4 changed files with 37 additions and 16 deletions

View File

@ -1,10 +1,6 @@
name: docker image ci
on:
push:
branches:
- master
- 'release-v*'
on: push
jobs:
test:
@ -20,16 +16,6 @@ jobs:
docker build . --file Dockerfile --tag ${DOCKER_IMAGE} ||
(echo -e "\e[31m[${GITHUB_WORKFLOW}] failed to build\e[m" && exit 1)
# - name: push latest image
# if: endsWith(github.ref, 'master')
# env:
# DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/action:latest
# PKG_GITHUB_TOKEN: ${{ secrets.PKG_GITHUB_TOKEN }}
# run: |
# echo ${PKG_GITHUB_TOKEN} | docker login docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin &&
# docker push ${DOCKER_IMAGE} &&
# docker logout
shellcheck:
runs-on: ubuntu-18.04
steps:

View File

@ -27,6 +27,7 @@ Table of Contents
- [:star: Pull action image from Docker Hub](#star-pull-action-image-from-docker-hub)
- [:star: `PERSONAL_TOKEN`](#star-personal_token)
- [:star: `GITHUB_TOKEN`](#star-github_token)
- [:star: Suppressing empty commits](#star-suppressing-empty-commits)
- [Examples](#examples)
- [Static Site Generators with Node.js](#static-site-generators-with-nodejs)
- [Gatsby](#gatsby)
@ -156,6 +157,25 @@ By pulling docker images, you can reduce the overall execution time of your work
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
#### :star: Suppressing empty commits
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]
[Issue #21]: https://github.com/peaceiris/actions-gh-pages/issues/21
For example:
```yaml
- name: deploy
uses: peaceiris/actions-gh-pages@v2.2.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
with:
emptyCommits: false
```
## Examples

View File

@ -7,3 +7,8 @@ runs:
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
emptyCommits:
description: 'If empty commits should be made to the publication branch'
required: false
default: 'true'

View File

@ -71,6 +71,16 @@ git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git remote rm origin || true
git remote add origin "${remote_repo}"
git add --all
git commit --allow-empty -m "Automated deployment: $(date -u) ${GITHUB_SHA}"
print_info "Allowing empty commits: ${INPUT_EMPTYCOMMITS}"
COMMIT_MESSAGE="Automated deployment: $(date -u) ${GITHUB_SHA}"
if [[ ${INPUT_EMPTYCOMMITS} == "true" ]]; then
git commit --allow-empty -m "${COMMIT_MESSAGE}"
else
git commit -m "${COMMIT_MESSAGE}" || \
print_info "No changes detected, skipping deployment" && \
exit 0
fi
git push origin "${remote_branch}"
print_info "${GITHUB_SHA} was successfully deployed"