Skip to content

Commit

Permalink
fix(CE): CE sync commit not working for multiple commits (Multiwoven#201
Browse files Browse the repository at this point in the history
)
  • Loading branch information
karthik-sivadas authored Jun 24, 2024
1 parent e8c57fa commit afc0792
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions .github/workflows/sync-ce-commits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ jobs:
PREV_DATE=$(date -d "yesterday" +'%Y-%m-%d')
echo "::set-output name=date::$PREV_DATE"
- name: Fetch CE commits
id: fetch-ce-commits
run: |
PREV_DATE=${{ steps.prev-date.outputs.date }}
CE_COMMITS=$(git log enterprise/main --since="$PREV_DATE 00:00" --until="$PREV_DATE 23:59" --grep="(CE)" --pretty=format:"%H" --no-merges)
echo "::set-output name=ce_commits::$CE_COMMITS"
- name: Create new branch for cherry-picked commits
run: |
BRANCH_NAME="cherry-pick-ce-commits-${{ steps.prev-date.outputs.date }}"
git checkout -b $BRANCH_NAME
echo "::set-output name=branch_name::$BRANCH_NAME"
- name: Authenticate GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
Expand All @@ -58,21 +45,21 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
IFS=' ' read -r -a commits <<< "${{ steps.fetch-ce-commits.outputs.ce_commits }}"
for commit in "${commits[@]}"; do
AUTHOR_NAME=$(git log -1 --pretty=format:'%an' $commit)
AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae' $commit)
COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' $commit)
BRANCH_NAME="cherry-pick-ce-commit-${commit}-$(date +%s)"
PREV_DATE=${{ steps.prev-date.outputs.date }}
git log enterprise/main --since="$PREV_DATE 00:00" --until="$PREV_DATE 23:59" --grep="(CE)" --format="%H" --no-merges | while read sha; do
AUTHOR_NAME=$(git log -1 --pretty=format:'%an' $sha)
AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae' $sha)
COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' $sha)
BRANCH_NAME="cherry-pick-ce-commit-${sha}"
git checkout -b $BRANCH_NAME
git cherry-pick $commit || {
echo "Conflict in commit $commit, resolving manually."
git cherry-pick $sha || {
echo "Conflict in commit $sha, resolving manually."
git add .
git commit -am "Resolve conflict in cherry-pick of $commit and change the commit message"
git commit -am "Resolve conflict in cherry-pick of $sha and change the commit message"
}
git push --force --set-upstream origin $BRANCH_NAME
PR_TITLE="${COMMIT_MESSAGE}"
PR_BODY="This PR cherry-picks the CE commit ${commit} from the Enterprise repository. Commit author: ${AUTHOR_NAME} (${AUTHOR_EMAIL})"
PR_BODY="This PR cherry-picks the CE commit ${sha} from the Enterprise repository. Commit author: ${AUTHOR_NAME} (${AUTHOR_EMAIL})"
AUTHOR_GH_USERNAME=$(gh api graphql -f query='query { search(query: "${AUTHOR_EMAIL}", type: USER, first: 1) { nodes { ... on User { login } } } }' -q '.data.search.nodes[0].login')
if [ -n "$AUTHOR_GH_USERNAME" ]; then
PR_BODY="${PR_BODY}\n\ncc @${AUTHOR_GH_USERNAME}"
Expand Down

0 comments on commit afc0792

Please sign in to comment.