fix: add --set-upstream
This commit is contained in:
@@ -26,27 +26,31 @@ jobs:
|
|||||||
MIRROR_URL: ${{ secrets.MIRROR_REPO_URL }}
|
MIRROR_URL: ${{ secrets.MIRROR_REPO_URL }}
|
||||||
MIRROR_TOKEN: ${{ secrets.MIRROR_REPO_TOKEN }}
|
MIRROR_TOKEN: ${{ secrets.MIRROR_REPO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
|
# Clean variables (remove potential whitespace/newlines)
|
||||||
|
CLEAN_MIRROR_URL=$(echo "$MIRROR_URL" | tr -d '[:space:]')
|
||||||
|
CLEAN_USER=$(echo "$GIT_USER_NAME" | tr -d '[:space:]')
|
||||||
|
CLEAN_TOKEN=$(echo "$MIRROR_TOKEN" | tr -d '[:space:]')
|
||||||
|
|
||||||
# URL encode special characters in credentials
|
# URL encode special characters in credentials
|
||||||
ENCODED_USER=$(printf %s "$GIT_USER_NAME" | jq -sRr @uri)
|
ENCODED_USER=$(printf %s "$CLEAN_USER" | jq -sRr @uri)
|
||||||
ENCODED_TOKEN=$(printf %s "$MIRROR_TOKEN" | jq -sRr @uri)
|
ENCODED_TOKEN=$(printf %s "$CLEAN_TOKEN" | jq -sRr @uri)
|
||||||
|
|
||||||
# Build authenticated URL
|
# Build authenticated URL
|
||||||
if [[ "$MIRROR_URL" == https://* ]]; then
|
if [[ "$CLEAN_MIRROR_URL" == https://* ]]; then
|
||||||
# URL with https protocol
|
# URL with https protocol
|
||||||
CLEAN_URL="${MIRROR_URL#https://}"
|
CLEAN_URL="${CLEAN_MIRROR_URL#https://}"
|
||||||
AUTH_URL="https://${ENCODED_USER}:${ENCODED_TOKEN}@${CLEAN_URL}"
|
AUTH_URL="https://${ENCODED_USER}:${ENCODED_TOKEN}@${CLEAN_URL}"
|
||||||
elif [[ "$MIRROR_URL" == http://* ]]; then
|
elif [[ "$CLEAN_MIRROR_URL" == http://* ]]; then
|
||||||
# URL with http protocol
|
# URL with http protocol
|
||||||
CLEAN_URL="${MIRROR_URL#http://}"
|
CLEAN_URL="${CLEAN_MIRROR_URL#http://}"
|
||||||
AUTH_URL="http://${ENCODED_USER}:${ENCODED_TOKEN}@${CLEAN_URL}"
|
AUTH_URL="http://${ENCODED_USER}:${ENCODED_TOKEN}@${CLEAN_URL}"
|
||||||
else
|
else
|
||||||
# URL without protocol
|
# URL without protocol
|
||||||
AUTH_URL="https://${ENCODED_USER}:${ENCODED_TOKEN}@${MIRROR_URL}"
|
AUTH_URL="https://${ENCODED_USER}:${ENCODED_TOKEN}@${CLEAN_MIRROR_URL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $AUTH_URL
|
|
||||||
# Add mirror remote with authentication
|
# Add mirror remote with authentication
|
||||||
git remote add mirror "$AUTH_URL"
|
git remote add mirror "$AUTH_URL"
|
||||||
|
|
||||||
# Push to mirror
|
# Push to mirror
|
||||||
git push mirror main --force
|
git push --set-upstream mirror main --force
|
||||||
|
|||||||
Reference in New Issue
Block a user