-
Notifications
You must be signed in to change notification settings - Fork 6
/
chart-sync.sh
executable file
·52 lines (40 loc) · 2.12 KB
/
chart-sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
RELEASE_FILE_CONTENTS=$(curl -L -s "https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${RELEASE_BRANCH}/manifests/release.txt")
RELEASE_TYPE=$(echo $RELEASE_FILE_CONTENTS | awk '{print $1}')
RELEASE_TAG=$(echo $RELEASE_FILE_CONTENTS | awk '{print $3}')
if [[ "$RELEASE_TYPE" == "stable" ]];
then
echo "Starting PR creation..."
# Clone the source repository
git clone $INPUT_SOURCE_REPO
cd ..
# Clone the target repository
git clone $INPUT_TARGET_REPO
cd $INPUT_WORKING_DIR
# Add a remote for the target repository
git remote add target https://${INPUT_GIT_TARGET_USERNAME}:${INPUT_GIT_TARGET_TOKEN}@${INPUT_TARGET_REPO#https://}
# Check out to the main branch and print remotes for verification
git checkout main
git remote -v
# Set Git user email and name
git config --global user.email ${INPUT_GIT_TARGET_USEREMAIL}
git config --global user.name ${INPUT_GIT_TARGET_USERNAME}
# Create a unique branch name using prefix and Git hash
NEW_BRANCH_NAME="sync-$(date +"%Y-%m-%d-%H%M%S")-$(git rev-parse --short HEAD)"
# Create and checkout a new branch
git checkout -b $NEW_BRANCH_NAME
# Copy contents from source directory to target directory
rsync -av --exclude='.git' ../${INPUT_SOURCE_DIR} $INPUT_TARGET_DIR
# Commit the changes and push them to the new branch
git add .
git commit -m "Syncing Repo from branch ${NEW_BRANCH_NAME}"
git push target $NEW_BRANCH_NAME
# Create a pull request from the new branch to the main branch
PR_TITLE="Sync changes from ${INPUT_SOURCE_REPO} for release ${RELEASE_TAG}"
PR_BODY="This pull request syncs changes from ${INPUT_SOURCE_REPO} for release ${RELEASE_TAG}."
TARGET_REPO_NAME=${INPUT_TARGET_REPO#https://github.com/}
echo $INPUT_GIT_TARGET_TOKEN | gh auth login --with-token
gh pr create --title "Sync changes from $NEW_BRANCH_NAME" --body "This pull request syncs changes from $NEW_BRANCH_NAME" --base main --head $NEW_BRANCH_NAME --repo $INPUT_TARGET_REPO
echo "Pull request created successfully."
else
echo "No sync operation due to beta"
fi