2021-11-16 13:47:29 -03:00
|
|
|
name: 'Git Commit Push Action'
|
2021-10-21 14:53:37 -03:00
|
|
|
|
2021-11-16 13:47:29 -03:00
|
|
|
description: 'GitHub Action to commit & push changes made in workflows (all os supported).'
|
2021-10-21 14:53:37 -03:00
|
|
|
|
|
|
|
inputs:
|
|
|
|
email:
|
2021-10-21 15:31:33 -03:00
|
|
|
description: Committer's email address
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
|
|
|
default: ${{ github.actor }}@users.noreply.github.com
|
|
|
|
name:
|
2021-10-21 15:31:33 -03:00
|
|
|
description: Committer's username
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
|
|
|
default: ${{ github.actor }}
|
|
|
|
commit_message:
|
2021-10-21 15:31:33 -03:00
|
|
|
description: Commit message
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
2021-10-21 15:33:04 -03:00
|
|
|
default: Commit performed using Push and Commit action
|
2021-10-21 14:53:37 -03:00
|
|
|
target_branch:
|
2021-10-21 15:31:33 -03:00
|
|
|
description: Branch to push the changes back to
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
|
|
|
default: ${{ github.ref }}
|
|
|
|
files:
|
2021-10-21 15:31:33 -03:00
|
|
|
description: Files to add separated by space
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
|
|
|
default: .
|
|
|
|
remote_repository:
|
2021-10-21 15:55:48 -03:00
|
|
|
description: Repository url to push the code to
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
|
|
|
default: origin
|
|
|
|
access_token:
|
2021-10-21 15:31:33 -03:00
|
|
|
description: Token used to push the code
|
2021-10-21 14:53:37 -03:00
|
|
|
required: true
|
|
|
|
default: ${{ github.token }}
|
|
|
|
force:
|
|
|
|
description: Whether to perform force push
|
|
|
|
required: true
|
|
|
|
default: '0'
|
|
|
|
empty:
|
2021-10-21 15:28:30 -03:00
|
|
|
description: Whether to allow empty commit
|
2021-10-21 14:53:37 -03:00
|
|
|
required: false
|
|
|
|
default: '0'
|
|
|
|
tags:
|
2021-10-21 15:28:30 -03:00
|
|
|
description: Whether to use --tags
|
2021-10-21 14:53:37 -03:00
|
|
|
required: false
|
|
|
|
default: '0'
|
|
|
|
|
|
|
|
outputs:
|
|
|
|
diff-output:
|
|
|
|
description: "Assert output"
|
|
|
|
value: ${{ steps.assert.outputs.result }}
|
|
|
|
|
|
|
|
runs:
|
|
|
|
using: "composite"
|
|
|
|
steps:
|
|
|
|
- name: Git push and commit
|
|
|
|
run: |
|
2021-11-18 11:52:48 -03:00
|
|
|
CURRENT_BRANCH=${GITHUB_REF}
|
|
|
|
case $CURRENT_BRANCH in "refs/heads/"*)
|
|
|
|
CURRENT_BRANCH=$(echo "$CURRENT_BRANCH" | sed "s@refs/heads/@@")
|
|
|
|
esac
|
2021-10-21 14:53:37 -03:00
|
|
|
TARGET_BRANCH=${{ inputs.target_branch }}
|
|
|
|
case $TARGET_BRANCH in "refs/heads/"*)
|
|
|
|
TARGET_BRANCH=$(echo "$TARGET_BRANCH" | sed "s@refs/heads/@@")
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "${{ inputs.force }}" != "0" ]; then
|
|
|
|
FORCE='--force'
|
|
|
|
fi
|
|
|
|
if [ "${{ inputs.empty }}" != "0" ]; then
|
|
|
|
EMPTY='--allow-empty'
|
|
|
|
fi
|
|
|
|
if [ "${{ inputs.tags }}" != "0" ]; then
|
|
|
|
TAGS='--tags'
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "machine github.com" > "$HOME/.netrc"
|
|
|
|
echo " login $GITHUB_ACTOR" >> "$HOME/.netrc"
|
|
|
|
echo " password ${{ inputs.access_token }}" >> "$HOME/.netrc"
|
|
|
|
|
|
|
|
echo "machine api.github.com" >> "$HOME/.netrc"
|
|
|
|
echo " login $GITHUB_ACTOR" >> "$HOME/.netrc"
|
|
|
|
echo " password ${{ inputs.access_token }}" >> "$HOME/.netrc"
|
|
|
|
|
|
|
|
git config --local user.email "${{ inputs.email }}"
|
|
|
|
git config --local user.name "${{ inputs.name }}"
|
|
|
|
git add ${{ inputs.files }} -v
|
|
|
|
git commit -m "${{ inputs.commit_message }}" $EMPTY
|
|
|
|
|
2021-10-21 15:03:39 -03:00
|
|
|
git branch push-and-commit-action-${{ github.run_id }}-${{ github.job }}
|
2021-10-21 14:53:37 -03:00
|
|
|
git fetch "${{ inputs.remote_repository }}" "$CURRENT_BRANCH"
|
|
|
|
git checkout "$CURRENT_BRANCH"
|
2021-10-21 15:03:39 -03:00
|
|
|
git merge push-and-commit-action-${{ github.run_id }}-${{ github.job }}
|
|
|
|
git branch -d push-and-commit-action-${{ github.run_id }}-${{ github.job }}
|
2021-10-21 14:53:37 -03:00
|
|
|
|
|
|
|
git push "${{ inputs.remote_repository }}" "$CURRENT_BRANCH:$TARGET_BRANCH" --follow-tags $FORCE $TAGS
|
|
|
|
shell: bash
|
|
|
|
|
|
|
|
branding:
|
|
|
|
icon: 'git-commit'
|
|
|
|
color: 'black'
|