name: 'Push and Commit action' description: 'GitHub Action to commit & push changes made in workflows to upstream repository :octocat:' 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: Automatically updated 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 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: | CURRENT_BRANCH=${GITHUB_REF##*/} 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 }} git push "${{ inputs.remote_repository }}" "$CURRENT_BRANCH:$TARGET_BRANCH" --follow-tags $FORCE $TAGS shell: bash branding: icon: 'git-commit' color: 'black'