Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support force pushing #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ The directory to wipe and replace in the target repository. Defaults to wiping

The string `ORIGIN_COMMIT` is replaced by `$REPOSITORY_URL@commit`.

### `force` (argument) [optional]
If "true", will force push to the target repo. Use with caution


### `API_TOKEN_GITHUB` (environment)
E.g.:
`API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}`
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ inputs:
description: '[Optional] The directory to wipe and replace in the target repository'
default: ''
required: false

force:
description: "[Optional] If 'true', will force push and thus overwrite the target repo's history"
default: 'false'
required: false

runs:
using: docker
image: Dockerfile
Expand All @@ -64,6 +68,7 @@ runs:
- '${{ inputs.target-branch }}'
- '${{ inputs.commit-message }}'
- '${{ inputs.target-directory }}'
- '${{ inputs.force }}'
branding:
icon: git-commit
color: green
13 changes: 11 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DESTINATION_REPOSITORY_USERNAME="$8"
TARGET_BRANCH="$9"
COMMIT_MESSAGE="${10}"
TARGET_DIRECTORY="${11}"
FORCE="${12}"

if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
then
Expand Down Expand Up @@ -102,6 +103,14 @@ echo "[+] git diff-index:"
# git diff-index : to avoid doing the git commit failing if there are no changes to be commit
git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE"

echo "[+] Pushing git commit"
if $FORCE; then
echo "[+] Force pushing git commit"
FORCE_FLAG="-f"
else
echo "[+] Pushing git commit"
FORCE_FLAG=""
fi
# --set-upstream: sets de branch when pushing to a branch that does not exist
git push "https://$USER_NAME:$API_TOKEN_GITHUB@$GITHUB_SERVER/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" --set-upstream "$TARGET_BRANCH"
git push "https://$USER_NAME:$API_TOKEN_GITHUB@$GITHUB_SERVER/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" \
--set-upstream "$TARGET_BRANCH" \
"$FORCE_FLAG"