From 770c884650a23bf1baeecb2bedf85136c438a1a2 Mon Sep 17 00:00:00 2001 From: pbhandar-amd <138039281+pbhandar-amd@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:21:44 -0400 Subject: [PATCH] Create merge_ff_only.yml --- .github/workflows/merge_ff_only.yml | 139 ++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 .github/workflows/merge_ff_only.yml diff --git a/.github/workflows/merge_ff_only.yml b/.github/workflows/merge_ff_only.yml new file mode 100644 index 00000000..2e3ca320 --- /dev/null +++ b/.github/workflows/merge_ff_only.yml @@ -0,0 +1,139 @@ +name: Merge (ff only) +on: + workflow_call: + inputs: + source-repo: + required: true + type: string + description: Source repo path in the format [REPO_OWNER]/[REPO_NAME] + target-repo: + required: true + type: string + description: Target repo path in the format [REPO_OWNER]/[REPO_NAME] + source-branch: + required: true + type: string + description: Source branch from [SOURCE_REPO] that you want merged into [TARGET_BRANCH] from [TARGET_REPO] + target-branch: + required: true + type: string + description: Target branch to merge [SOURCE_BRANCH] from [SOURCE_REPO] into. + secrets: + github-token: + required: true +jobs: + Promote: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ inputs.source-repo }} + ref: ${{ inputs.source-branch }} + persist-credentials: false + fetch-depth: 0 + - name: Merge source-branch into target-branch + env: + # gh needs this env var set with the exact name GH_TOKEN + GH_TOKEN: ${{ secrets.github-token }} + SOURCE_BRANCH: ${{ inputs.source-branch }} + TARGET_BRANCH: ${{ inputs.target-branch }} + TARGET_REPO: ${{ inputs.target-repo }} + shell: bash + run: | + git config --global user.email "promote@github.com" + git config --global user.name "auto-promote" + git config --global --add --bool push.autoSetupRemote true + git remote add target-repo "https://$GH_TOKEN@github.com/$TARGET_REPO.git" + git fetch -q target-repo + git branch --track "$TARGET_BRANCH-target-repo" remotes/target-repo/$TARGET_BRANCH + echo "After tracking target branch external" + git switch -q "$TARGET_BRANCH-target-repo" + # echo "switched to $TARGET_BRANCH-external" + # echo "before merging" + # merge_msg=$(git merge $SOURCE_BRANCH --no-commit || echo " ") + # merge_msg=$(git merge $SOURCE_BRANCH --no-commit || echo " ") + # merge_msg=$(git merge $SOURCE_BRANCH --ff-only || echo " ") + #merge_msg=$(git merge $SOURCE_BRANCH || echo " ") + git merge $SOURCE_BRANCH --ff-only + git push -q target-repo HEAD:$TARGET_BRANCH + + # # echo "after merging" + # # echo "before status" + # git status --porcelain + # #is_merge_conflict=$(git status --porcelain | egrep ^U) + # is_merge_conflict=$(git status --porcelain | egrep ^U || echo "") + # # echo "after status" + + # if [ -z "$is_merge_conflict" ] ; then + # merge_status=0 + # else + # merge_status=1 + # fi + + # echo "Value of merge_msg is:" + # echo "${merge_msg}" + # echo "" + # echo "Value of merge_status: $merge_status" + + # if [ "$merge_status" -eq 0 ]; then + # # pushes local develop-external branch to external repo's 'develop' branch + # # git add -A + # # diff_files=$(git diff --name-only --cached) + # # if [ -z "$diff_files" ]; then + # # echo "No files to be promoted to external $TARGET_BRANCH so nothing to merge" + # # exit 0 + # # fi + # # echo "Merge $SOURCE_BRANCH into $TARGET_BRANCH-external" + # # git commit -m "Promote internal $SOURCE_BRANCH into external $TARGET_BRANCH" + # git push -q external HEAD:develop + # echo "Merged changes from internal $SOURCE_BRANCH to external $TARGET_BRANCH successfully" + # else + # echo "Encountered a merge conflict when doing a git merge from $SOURCE_BRANCH to $TARGET_BRANCH. We'll create a PR instead" + # dev_branch_count=$(git ls-remote --heads external --list "refs/heads/${DEV_BRANCH}*" | wc -l | xargs) + # echo "Value of dev_branch_count: $dev_branch_count" + # git merge --abort + # if [ "$dev_branch_count" -gt 0 ]; then + # dev_branch_count=$((dev_branch_count + 1)) + # echo "Remote branch with the name $TARGET_BRANCH already exists, so we create a branch with the name '${TARGET_BRANCH}-${dev_branch_count}' instead." + # DEV_BRANCH="${TARGET_BRANCH}-${dev_branch_count}" + # git switch -q "$SOURCE_BRANCH" + # git checkout -q -b "$DEV_BRANCH" + # fi + + # git push -q external "$DEV_BRANCH" + # #if [ "$dev_branch_count" -gt 0 ]; then + # echo "Create a PR from $DEV_BRANCH into $TARGET_BRANCH and let user resolve merge conflicts manually" + # gh pr create --repo $ROCM_INSTALL_PUBLIC_REPO -B $TARGET_BRANCH -H $DEV_BRANCH --title "[Promote]: Promote internal $SOURCE_BRANCH into $TARGET_BRANCH" --body "Created by Github action" --draft + # #fi + # fi + + + # # commit_msg=$(git commit -m "Sync internal $SOURCE_BRANCH to external $TARGET_BRANCH" || echo "error") internal commit test + # # echo "Value of commit_msg: $commit_msg" force merge conflict + # # commit_status=${PIPESTATUS[0]} + # # echo "Value of commit_status is $commit_status" + + # # if egrep -q "no changes added to commit|nothing to commit, working tree clean|nothing added to commit but untracked files present" <<< "$commit_msg"; then + # # echo "External branch $TARGET_BRANCH is up to date. Nothing to commit" + # # exit 0 + # # elif [ "$commit_status" -eq 0 ]; then + # # git push external "$TARGET_BRANCH-external" + # #elif [ "$commit_status" -eq 128 ]; then + # # Encountered some unknown error when merging internal develop into external + # # Create a PR instead + # # else + # # dev_branch_count=$(git ls-remote --heads external --list "refs/heads/${DEV_BRANCH}*" | wc -l | xargs) + # # echo "Value of dev_branch_count: $dev_branch_count" + + # # if [ "$dev_branch_count" -gt 0 ]; then + # # dev_branch_count=$((dev_branch_count + 1)) + # # echo "Remote branch with the name $TARGET_BRANCH already exists, so we create a branch with the name '${TARGET_BRANCH}-${dev_branch_count}' instead." + # # DEV_BRANCH="${TARGET_BRANCH}-${dev_branch_count}" + # # git checkout -b "$DEV_BRANCH" + # # fi + + # # git push external "$DEV_BRANCH" + # # #if [ "$dev_branch_count" -gt 0 ]; then + # # gh pr create --repo $ROCM_INSTALL_PUBLIC_REPO -B $TARGET_BRANCH -H $DEV_BRANCH --title "[Promote]: Promote internal $SOURCE_BRANCH into $TARGET_BRANCH" --body "Created by Github action" --draft + # # #fi + # # fi