Files
app-ethereum/.github/actions/commit-changes/action.yml
2022-03-14 15:02:51 +01:00

81 lines
2.4 KiB
YAML

name: 'Commit and push if the version file has changed'
inputs:
name:
description: 'The name of the commiter'
required: true
default: 'github-actions[bot]'
email:
description: 'The email of the commiter'
required: true
default: 'github-actions[bot]@users.noreply.github.com'
message:
description: 'The commit message'
required: true
default: 'New release version(s)'
files:
description: 'The file(s) to add in the commit'
required: true
default: '*'
directory:
description: 'The directory in which the action will be performed'
required: true
default: '.'
branch:
description: 'Checkout (or create) on a specific branch before commit/push'
required: true
default: 'master'
secret:
description: 'A token allowing to push the commit on the repository'
required: true
default: '.'
repository:
description: 'The repository where to push'
required: true
default: ''
runs:
using: 'composite'
steps:
- name: Commit the changes
id: commit
run: |
git config --global user.name ${{ inputs.name }}
ORIGIN="$(pwd)"
cd ${{ inputs.directory }}
git switch ${{ inputs.branch }} 2>/dev/null || git switch -c ${{ inputs.branch }}
echo "-----------------------------------------------------------"
echo "Initial repo status"
git status
CHANGES="$(git status --porcelain ${{ inputs.files }})"
if [ -z "${CHANGES}" ]; \
then \
echo "-----------------------------------------------------------"; \
echo "No changes, stopping now"; \
echo "COMMIT=NO" > $GITHUB_ENV; \
cd "${ORIGIN}"; \
exit 0; \
fi
echo -e "Changes:\n${CHANGES}"
git add ${{ inputs.files }}
echo "-----------------------------------------------------------"
echo "Repo status before commit"
git status
git commit -am "${{ inputs.message }}"
echo "COMMIT=YES" > $GITHUB_ENV
git log -n 2
cd "${ORIGIN}"
shell: bash
- run: echo "${{ env.COMMIT }}"
shell: bash
- name: Push commit
if: ${{ env.COMMIT == 'YES' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ inputs.secret }}
branch: ${{ inputs.branch }}
directory: ${{ inputs.directory }}
repository: ${{ inputs.repository }}