update creating branch section

Signed-off-by: GuillaumeFalourd <guillaume.falourd@zup.com.br>
This commit is contained in:
GuillaumeFalourd 2022-01-06 23:45:30 -03:00
parent 92277f3abb
commit e7a4b74c2a

View file

@ -91,7 +91,7 @@ runs:
git branch push-and-commit-action-${{ github.run_id }}-${{ github.job }} git branch push-and-commit-action-${{ github.run_id }}-${{ github.job }}
git fetch "${{ inputs.remote_repository }}" "$CURRENT_BRANCH" git fetch "${{ inputs.remote_repository }}" "$CURRENT_BRANCH"
git checkout "$CURRENT_BRANCH" git checkout "$CURRENT_BRANCH"
git merge -X ours push-and-commit-action-${{ github.run_id }}-${{ github.job }} git merge push-and-commit-action-${{ github.run_id }}-${{ github.job }}
git branch -d 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 git push "${{ inputs.remote_repository }}" "$CURRENT_BRANCH:$TARGET_BRANCH" --follow-tags $FORCE $TAGS
@ -134,10 +134,21 @@ runs:
cd "$CLONE_DIRECTORY" cd "$CLONE_DIRECTORY"
# Create new branch
REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY REMOTE_URL=https://$DESTINATION_OWNER:${{ inputs.access_token }}@github.com/$DESTINATION_OWNER/$DESTINATION_REPOSITORY
git remote set-url origin $REMOTE_URL git remote set-url origin $REMOTE_URL
git fetch origin git fetch origin
if [ -z "${{ inputs.target_dir }}" ]; then
git add ${{ inputs.source_files }}
else
git add ${{ inputs.target_dir }}/${{ inputs.source_files }}
fi
# Won't commit if no changes were made
git diff-index --quiet HEAD || git commit --message "${{ inputs.commit_message }}"
git status
git branch copy-push-files-action-${{ github.run_id }}-${{ github.job }}
# Create new branch (if necessary)
BE=$(git ls-remote --heads origin ${{ inputs.target_branch }} | wc -l) BE=$(git ls-remote --heads origin ${{ inputs.target_branch }} | wc -l)
if [[ $BE == *"0"* ]]; then if [[ $BE == *"0"* ]]; then
echo "##### Target branch doesn't exist. Creating new branch #####" echo "##### Target branch doesn't exist. Creating new branch #####"
@ -145,15 +156,11 @@ runs:
else else
git checkout ${{ inputs.target_branch }} git checkout ${{ inputs.target_branch }}
fi fi
git add . git merge -X theirs copy-push-files-action-${{ github.run_id }}-${{ github.job }}
git status git branch -d copy-push-files-action-${{ github.run_id }}-${{ github.job }}
# Won't commit if no changes were made
git diff-index --quiet HEAD || git commit --message "${{ inputs.commit_message }}"
echo echo
echo "##### Pushing git commit #####" echo "##### Pushing git commit #####"
# --set-upstream: sets the branch when pushing to a branch that does not exist
git push -f -u origin "${{ inputs.target_branch }}" git push -f -u origin "${{ inputs.target_branch }}"
else else