Skip to content
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
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

set -e

if [[ -z "$GITHUB_TOKEN" ]]; then
if [ -z "$GITHUB_TOKEN" ]; then
echo "Set the GITHUB_TOKEN environment variable."
exit 1
fi

if [[ ! -z "$SSH_PRIVATE_KEY" ]]; then
if [ ! -z "$SSH_PRIVATE_KEY" ]; then
echo "Saving SSH_PRIVATE_KEY"

mkdir --parents /root/.ssh
mkdir -p /root/.ssh
echo "$SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa

# Github action changes $HOME to /github at runtime
# therefore we always copy the SSH key to $HOME (aka. ~)
mkdir --parents ~/.ssh
mkdir -p ~/.ssh
cp /root/.ssh/* ~/.ssh/ 2> /dev/null || true
fi

Expand Down
14 changes: 7 additions & 7 deletions github-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ set -e
UPSTREAM_REPO=$1
BRANCH_MAPPING=$2

if [[ -z "$UPSTREAM_REPO" ]]; then
if [ -z "$UPSTREAM_REPO" ]; then
echo "Missing \$UPSTREAM_REPO"
exit 1
fi

if [[ -z "$BRANCH_MAPPING" ]]; then
if [ -z "$BRANCH_MAPPING" ]; then
echo "Missing \$SOURCE_BRANCH:\$DESTINATION_BRANCH"
exit 1
fi

if ! echo $UPSTREAM_REPO | grep -Eq ':|@|\.git\/?$'
if ! echo "$UPSTREAM_REPO" | grep -Eq ':|@|\.git\/?$'
then
echo "UPSTREAM_REPO does not seem to be a valid git URI, assuming it's a GitHub repo"
echo "Originally: $UPSTREAM_REPO"
Expand All @@ -41,14 +41,14 @@ git remote --verbose
echo "Pushing changings from tmp_upstream to origin"
git push origin "refs/remotes/tmp_upstream/${BRANCH_MAPPING%%:*}:refs/heads/${BRANCH_MAPPING#*:}" --force

if [[ "$SYNC_TAGS" = true ]]; then
if [ "$SYNC_TAGS" = true ]; then
echo "Force syncing all tags"
git tag -d $(git tag -l) > /dev/null
git tag -d "$(git tag -l)" > /dev/null
git fetch tmp_upstream --tags --quiet
git push origin --tags --force
elif [[ -n "$SYNC_TAGS" ]]; then
elif [ -n "$SYNC_TAGS" ]; then
echo "Force syncing tags matching pattern: $SYNC_TAGS"
git tag -d $(git tag -l) > /dev/null
git tag -d "$(git tag -l)" > /dev/null
git fetch tmp_upstream --tags --quiet
git tag | grep "$SYNC_TAGS" | xargs --no-run-if-empty git push origin --force
fi
Expand Down