blob: b8e37f6b85ab48f7f31e52e204294f11420c9667 [file] [log] [blame]
# Builds and deploys the site if the build was successful
name: Build & Deploy Site
# Conditions necessary to trigger a build
on:
push:
# Ignore pushes on all branches by default
# branches that should trigger a build must be explicitly excluded from the ignore using '!BRANCH_NAME'
branches-ignore:
- '**'
- '!master'
# Only build if a file in one of these paths has been changed
#
# This list must not contains directories which are modified and commited as part of this action
# Such a setup would lead to an infinite loop where the push as part of the action triggers a new run of the action
paths:
- 'src/main/asciidoc/**'
- 'src/main/template/**'
jobs:
build:
name: Build & Deploy Site
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Build Site
run: mvn clean install
# Determines the short sha of the commit that triggered the build
- name: Determine Short SHA
if: success()
id: short-sha
run: |
short_sha=$(git rev-parse --short=10 $GITHUB_SHA)
echo "::set-output name=short_sha::$short_sha"
shell: 'bash'
# Determine the author data of the HEAD commit which will be used for the deploy commit
- name: Determine HEAD Author Data
if: success()
id: author-data
run: |
author_name=$(git log -1 --format='%aN' HEAD)
echo "::set-output name=author_name::$author_name"
author_email=$(git log -1 --format='%aE' HEAD)
echo "::set-output name=author_email::$author_email"
shell: 'bash'
# Commits any changes to the 'docs/' directory using the credentials of the current HEAD commit; does nothing if there is nothing to commit
- name: Commit Result
if: success()
run: |
echo "Adding changes"
git add 'docs/'
if $(git diff -s --cached --exit-code)
then
# nothing staged
echo "Nothing to commit"
exit 0
fi
echo "Setting up author data"
git config user.name "${{ steps.author-data.outputs.author_name }}"
git config user.email "${{ steps.author-data.outputs.author_email }}"
echo "Commiting changes"
git commit -m "Auto-deploy site for commit ${{ steps.short-sha.outputs.short_sha }}"
echo "Pushing changes"
git push
shell: 'bash'