From 9aff1243353d474fd011586486dc01b0c540189a Mon Sep 17 00:00:00 2001 From: Aslam Ansari Date: Fri, 28 Aug 2026 13:50:52 +0530 Subject: [PATCH 1/4] updated workflow --- .github/workflows/prepare_release.yml | 83 +++++++++++++++++++++------ 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml index b5754a7aa..aa79b7d3d 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release.yml @@ -20,6 +20,7 @@ on: type: string permissions: contents: write + pull-requests: write jobs: prepare-release: runs-on: macos-14 @@ -39,10 +40,11 @@ jobs: - name: Verify Previous Release is Merged (Major Only) if: ${{ github.event.inputs.release_type == 'major' }} run: | + VERSION="${{ github.event.inputs.version }}" echo "Finding the latest release branch on remote..." - # List all remote release branches, sort them by version, and grab the highest one - LATEST_BRANCH=$(git branch -r --list "origin/grpc_release_*.x" | sort -V | tail -n 1 | sed 's/origin\///' | tr -d '[:space:]') + # List all remote release branches, sort them by version, and grab the highest one (excluding current version if it already exists) + LATEST_BRANCH=$(git branch -r --list "origin/grpc_release_*.x" | sed 's/origin\///' | tr -d '[:space:]' | grep -v "^grpc_release_${VERSION}\.x$" | sort -V | tail -n 1) if [ -z "$LATEST_BRANCH" ]; then echo "⚠️ No previous release branches found on remote. Skipping merge check." @@ -65,20 +67,42 @@ jobs: id: branch_prep run: | VERSION="${{ github.event.inputs.version }}" - BRANCH_NAME="grpc_release_${VERSION}.x" + SYNC_TAG="${{ github.event.inputs.sync_tag }}" + TARGET_BRANCH="grpc_release_${VERSION}.x" + SYNC_BRANCH="grpc_release_${SYNC_TAG}" if [ "${{ github.event.inputs.release_type }}" == "major" ]; then - echo "Preparing Major Release for $BRANCH_NAME..." - git checkout main - git checkout -b $BRANCH_NAME + echo "Preparing Major Release for $TARGET_BRANCH..." + git checkout -B main origin/main + git checkout -B "$TARGET_BRANCH" main + + # Push empty release branch if not already present on remote + if git show-ref --verify --quiet "refs/remotes/origin/$TARGET_BRANCH"; then + echo "⚠️ Target release branch $TARGET_BRANCH already exists on remote." + else + echo "Pushing empty branch $TARGET_BRANCH to origin..." + git push origin "$TARGET_BRANCH" + fi + + # Create sync branch from the empty branch + echo "Creating sync branch $SYNC_BRANCH from $TARGET_BRANCH..." + git checkout --no-track -B "$SYNC_BRANCH" "$TARGET_BRANCH" else - echo "Preparing Minor Release for $BRANCH_NAME..." - # For minor releases, checkout the existing branch from remote - git checkout -b $BRANCH_NAME origin/$BRANCH_NAME + echo "Preparing Minor Release for $TARGET_BRANCH..." + if ! git show-ref --verify --quiet "refs/remotes/origin/$TARGET_BRANCH"; then + echo "❌ ERROR: Target branch $TARGET_BRANCH does not exist on remote!" + echo "Please verify the base version or create the release branch first." + exit 1 + fi + + # Create sync branch from the existing release branch + echo "Creating sync branch $SYNC_BRANCH from origin/$TARGET_BRANCH..." + git checkout --no-track -B "$SYNC_BRANCH" "origin/$TARGET_BRANCH" fi - # Save branch name to environment for later steps - echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV + # Save branch names to environment for later steps + echo "target_branch=$TARGET_BRANCH" >> $GITHUB_ENV + echo "sync_branch=$SYNC_BRANCH" >> $GITHUB_ENV - name: Prepare Environment run: | @@ -94,13 +118,34 @@ jobs: - name: Commit Changes run: | git add . - git commit -m "Sync c-core ${{ github.event.inputs.sync_tag }}" + if git diff --staged --quiet; then + echo "No changes to commit." + else + git commit -m "Sync c-core ${{ github.event.inputs.sync_tag }}" + fi - - name: Push Branch and Tag + - name: Push Branch run: | - # 1. Push ONLY the new branch (main remains untouched) - git push origin ${{ env.branch_name }} - - # 2. Add the tag and push it - git tag ${{ github.event.inputs.sync_tag }} - git push origin ${{ github.event.inputs.sync_tag }} \ No newline at end of file + echo "Pushing branch ${{ env.sync_branch }} to origin..." + git push -u origin ${{ env.sync_branch }} --force + + - name: Create Pull Request + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + EXISTING_PR=$(gh pr list --repo "${{ github.repository }}" --head "${{ env.sync_branch }}" --base "${{ env.target_branch }}" --state open --json url --jq '.[0].url // empty') + if [ -n "$EXISTING_PR" ]; then + echo "Pull request already exists: $EXISTING_PR" + echo "### Pull Request" >> $GITHUB_STEP_SUMMARY + echo "A pull request already exists: $EXISTING_PR" >> $GITHUB_STEP_SUMMARY + else + PR_URL=$(gh pr create \ + --repo "${{ github.repository }}" \ + --base "${{ env.target_branch }}" \ + --head "${{ env.sync_branch }}" \ + --title "Sync c-core ${{ github.event.inputs.sync_tag }}" \ + --body "Automated PR to sync gRPC c-core sources for \`${{ github.event.inputs.sync_tag }}\` into \`${{ env.target_branch }}\`.") + echo "Created pull request: $PR_URL" + echo "### Pull Request Created" >> $GITHUB_STEP_SUMMARY + echo "Successfully created pull request: $PR_URL" >> $GITHUB_STEP_SUMMARY + fi \ No newline at end of file From 610060cac32e083f4debfb232f93a561c18621cc Mon Sep 17 00:00:00 2001 From: Aslam Ansari Date: Thu, 3 Sep 2026 13:17:37 +0530 Subject: [PATCH 2/4] added workflow to release on PR Merged --- .github/workflows/draft_release.yml | 91 +++++++++++++++++++++++++++ .github/workflows/prepare_release.yml | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/draft_release.yml diff --git a/.github/workflows/draft_release.yml b/.github/workflows/draft_release.yml new file mode 100644 index 000000000..7e032d4fe --- /dev/null +++ b/.github/workflows/draft_release.yml @@ -0,0 +1,91 @@ +name: Draft Release + +on: + pull_request: + types: [closed] + branches: + - "grpc_release_**" + +permissions: + contents: write + pull-requests: read + +jobs: + draft-release: + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref != 'main' && startsWith(github.event.pull_request.base.ref, 'grpc_release_') + runs-on: macos-14 + + steps: + - name: Determine Tag and Target Branch + id: vars + run: | + TAG="${{ github.event.pull_request.head.ref }}" + TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + + if [ "$TARGET_BRANCH" = "main" ]; then + echo "❌ Error: Release workflow cannot run against 'main' branch." + exit 1 + fi + + echo "tag=$TAG" >> $GITHUB_ENV + echo "target_branch=$TARGET_BRANCH" >> $GITHUB_ENV + echo "Target Branch: $TARGET_BRANCH" + echo "Release Tag: $TAG" + + - name: Checkout Code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.base.ref }} + fetch-depth: 0 + + - name: Set up Git configuration + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Create and Push Tag + run: | + TAG="${{ env.tag }}" + + # Check if tag already exists on remote + if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "$TAG"; then + echo "⚠️ Tag '$TAG' already exists on remote." + else + echo "Creating tag '$TAG'..." + git tag "$TAG" + echo "Pushing tag '$TAG' to origin..." + git push origin "$TAG" + echo "✅ Tag '$TAG' created and pushed successfully." + fi + + - name: Create Draft Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TAG="${{ env.tag }}" + TARGET_BRANCH="${{ env.target_branch }}" + + EXTRA_FLAGS="" + if [[ "$TAG" =~ -(pre|alpha|beta|rc) ]]; then + echo "Tag '$TAG' detected as pre-release." + EXTRA_FLAGS="--prerelease" + fi + + # Check if release already exists + if gh release view "$TAG" --repo "${{ github.repository }}" >/dev/null 2>&1; then + echo "⚠️ Release for '$TAG' already exists." + echo "### Draft Release" >> $GITHUB_STEP_SUMMARY + echo "Release for \`$TAG\` already exists." >> $GITHUB_STEP_SUMMARY + else + echo "Creating draft release for '$TAG' targeting '$TARGET_BRANCH'..." + RELEASE_URL=$(gh release create "$TAG" \ + --repo "${{ github.repository }}" \ + --target "$TARGET_BRANCH" \ + --title "$TAG" \ + --draft \ + $EXTRA_FLAGS \ + --generate-notes) + echo "✅ Created draft release: $RELEASE_URL" + echo "### Draft Release Created" >> $GITHUB_STEP_SUMMARY + echo "Successfully created draft release for [\`$TAG\`]($RELEASE_URL) targeting \`$TARGET_BRANCH\`." >> $GITHUB_STEP_SUMMARY + fi diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml index aa79b7d3d..56bf4d5aa 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release.yml @@ -69,7 +69,7 @@ jobs: VERSION="${{ github.event.inputs.version }}" SYNC_TAG="${{ github.event.inputs.sync_tag }}" TARGET_BRANCH="grpc_release_${VERSION}.x" - SYNC_BRANCH="grpc_release_${SYNC_TAG}" + SYNC_BRANCH="${SYNC_TAG}" if [ "${{ github.event.inputs.release_type }}" == "major" ]; then echo "Preparing Major Release for $TARGET_BRANCH..." From a4b581cf97f28f801a1f98987e6690b641169d23 Mon Sep 17 00:00:00 2001 From: Aslam Ansari Date: Thu, 3 Sep 2026 13:57:57 +0530 Subject: [PATCH 3/4] Rename prepare_release to prepare_release_PR --- .../workflows/{prepare_release.yml => prepare_release_PR.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{prepare_release.yml => prepare_release_PR.yml} (99%) diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release_PR.yml similarity index 99% rename from .github/workflows/prepare_release.yml rename to .github/workflows/prepare_release_PR.yml index 56bf4d5aa..fbe91b77c 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release_PR.yml @@ -1,4 +1,4 @@ -name: Prepare Release +name: Prepare Release PR on: workflow_dispatch: From 3389914c5d874cf1ecd03713398e6b2645b97fb5 Mon Sep 17 00:00:00 2001 From: Aslam Ansari Date: Wed, 9 Sep 2026 13:14:29 +0530 Subject: [PATCH 4/4] Delete draft_release.yml --- .github/workflows/draft_release.yml | 91 ----------------------------- 1 file changed, 91 deletions(-) delete mode 100644 .github/workflows/draft_release.yml diff --git a/.github/workflows/draft_release.yml b/.github/workflows/draft_release.yml deleted file mode 100644 index 7e032d4fe..000000000 --- a/.github/workflows/draft_release.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Draft Release - -on: - pull_request: - types: [closed] - branches: - - "grpc_release_**" - -permissions: - contents: write - pull-requests: read - -jobs: - draft-release: - if: github.event.pull_request.merged == true && github.event.pull_request.base.ref != 'main' && startsWith(github.event.pull_request.base.ref, 'grpc_release_') - runs-on: macos-14 - - steps: - - name: Determine Tag and Target Branch - id: vars - run: | - TAG="${{ github.event.pull_request.head.ref }}" - TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" - - if [ "$TARGET_BRANCH" = "main" ]; then - echo "❌ Error: Release workflow cannot run against 'main' branch." - exit 1 - fi - - echo "tag=$TAG" >> $GITHUB_ENV - echo "target_branch=$TARGET_BRANCH" >> $GITHUB_ENV - echo "Target Branch: $TARGET_BRANCH" - echo "Release Tag: $TAG" - - - name: Checkout Code - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.base.ref }} - fetch-depth: 0 - - - name: Set up Git configuration - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - - name: Create and Push Tag - run: | - TAG="${{ env.tag }}" - - # Check if tag already exists on remote - if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "$TAG"; then - echo "⚠️ Tag '$TAG' already exists on remote." - else - echo "Creating tag '$TAG'..." - git tag "$TAG" - echo "Pushing tag '$TAG' to origin..." - git push origin "$TAG" - echo "✅ Tag '$TAG' created and pushed successfully." - fi - - - name: Create Draft Release - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - TAG="${{ env.tag }}" - TARGET_BRANCH="${{ env.target_branch }}" - - EXTRA_FLAGS="" - if [[ "$TAG" =~ -(pre|alpha|beta|rc) ]]; then - echo "Tag '$TAG' detected as pre-release." - EXTRA_FLAGS="--prerelease" - fi - - # Check if release already exists - if gh release view "$TAG" --repo "${{ github.repository }}" >/dev/null 2>&1; then - echo "⚠️ Release for '$TAG' already exists." - echo "### Draft Release" >> $GITHUB_STEP_SUMMARY - echo "Release for \`$TAG\` already exists." >> $GITHUB_STEP_SUMMARY - else - echo "Creating draft release for '$TAG' targeting '$TARGET_BRANCH'..." - RELEASE_URL=$(gh release create "$TAG" \ - --repo "${{ github.repository }}" \ - --target "$TARGET_BRANCH" \ - --title "$TAG" \ - --draft \ - $EXTRA_FLAGS \ - --generate-notes) - echo "✅ Created draft release: $RELEASE_URL" - echo "### Draft Release Created" >> $GITHUB_STEP_SUMMARY - echo "Successfully created draft release for [\`$TAG\`]($RELEASE_URL) targeting \`$TARGET_BRANCH\`." >> $GITHUB_STEP_SUMMARY - fi