action-git-commit-push/action.yml

106 lines
3.2 KiB
YAML
Raw Normal View History

2021-11-16 13:47:29 -03:00
name: 'Git Commit Push Action'
2021-11-16 13:47:29 -03:00
description: 'GitHub Action to commit & push changes made in workflows (all os supported).'
inputs:
email:
description: Committer's email address
required: true
default: ${{ github.actor }}@users.noreply.github.com
name:
description: Committer's username
required: true
default: ${{ github.actor }}
commit_message:
description: Commit message
required: true
default: Commit performed using Push and Commit action
target_branch:
description: Branch to push the changes back to
required: true
default: ${{ github.ref }}
files:
description: Files to add separated by space
required: true
default: .
remote_repository:
description: Repository url to push the code to
required: true
default: origin
access_token:
description: Token used to push the code
required: true
default: ${{ github.token }}
force:
description: Whether to perform force push
required: true
default: '0'
empty:
description: Whether to allow empty commit
required: false
default: '0'
tags:
description: Whether to use --tags
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
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
git branch push-and-commit-action-${{ github.run_id }}-${{ github.job }}
git fetch "${{ inputs.remote_repository }}" "$CURRENT_BRANCH"
git checkout "$CURRENT_BRANCH"
git merge push-and-commit-action-${{ github.run_id }}-${{ github.job }}
git branch -d push-and-commit-action-${{ github.run_id }}-${{ github.job }}
2021-12-21 09:49:45 -03:00
if [[ `git status --porcelain` ]]; then
git push "${{ inputs.remote_repository }}" "$CURRENT_BRANCH:$TARGET_BRANCH" --follow-tags $FORCE $TAGS
else
echo "No changes"
fi
shell: bash
branding:
icon: 'git-commit'
color: 'black'