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

Added git safe config to the temp dir #63

Open
wants to merge 4 commits 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
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ inputs:
description: 'Git server host, default github.com'
required: false
default: github.com
push_retries:
description: 'How many times the git push should be retried'
required: false
default: 0
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -49,6 +53,7 @@ runs:
- ${{ inputs.git-server }}
- ${{ inputs.rename }}
- ${{ inputs.use-rsync }}
- ${{ inputs.push-retries }}
branding:
icon: 'git-commit'
color: 'green'
18 changes: 16 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ then
INPUT_DESTINATION_BRANCH=main
fi
OUTPUT_BRANCH="$INPUT_DESTINATION_BRANCH"

PUSH_RETRIES=${INPUT_PUSH_RETRIES:-0}
CLONE_DIR=$(mktemp -d)

echo "Cloning destination git repository"
git config --global user.email "$INPUT_USER_EMAIL"
git config --global user.name "$INPUT_USER_NAME"
git clone --single-branch --branch $INPUT_DESTINATION_BRANCH "https://x-access-token:$API_TOKEN_GITHUB@$INPUT_GIT_SERVER/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"

git config --global --add safe.directory $CLONE_DIR

git clone --depth=1 --single-branch --branch $INPUT_DESTINATION_BRANCH "https://x-access-token:$API_TOKEN_GITHUB@$INPUT_GIT_SERVER/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"

if [ ! -z "$INPUT_RENAME" ]
then
Expand Down Expand Up @@ -65,6 +68,17 @@ if git status | grep -q "Changes to be committed"
then
git commit --message "$INPUT_COMMIT_MESSAGE"
echo "Pushing git commit"
counter=1
while ! git push -u origin HEAD:"$OUTPUT_BRANCH"
do
if [[ $counter -gt $PUSH_RETRIES ]]; then
>&2 echo "failed after $retries retries"
exit 1
fi
echo "Retrying attempt $counter"
counter=$[$counter + 1]
done

git push -u origin HEAD:"$OUTPUT_BRANCH"
else
echo "No changes detected"
Expand Down