From 241ef9fea0d06c52a502714f02f76487136a094a Mon Sep 17 00:00:00 2001 From: James McCollum Date: Sat, 14 Sep 2019 13:49:20 -0500 Subject: [PATCH] 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 --- .github/workflows/docker-image-ci.yml | 16 +--------------- README.md | 20 ++++++++++++++++++++ action.yml | 5 +++++ entrypoint.sh | 12 +++++++++++- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.github/workflows/docker-image-ci.yml b/.github/workflows/docker-image-ci.yml index a188a56f9..b855300d2 100644 --- a/.github/workflows/docker-image-ci.yml +++ b/.github/workflows/docker-image-ci.yml @@ -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: diff --git a/README.md b/README.md index 8773026e9..3d903a151 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 8c9bbed3f..a99278a6b 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/entrypoint.sh b/entrypoint.sh index 640acb3f3..837697265 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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"