diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml new file mode 100644 index 0000000000..b5754a7aa4 --- /dev/null +++ b/.github/workflows/prepare_release.yml @@ -0,0 +1,106 @@ +name: Prepare Release + +on: + workflow_dispatch: + inputs: + release_type: + description: 'Release Type' + required: true + type: choice + options: + - major + - minor + version: + description: 'Base Version (e.g., 1.84 or 2.0)' + required: true + type: string + sync_tag: + description: 'Sync Tag (e.g., v1.84.0-pre1)' + required: true + type: string +permissions: + contents: write +jobs: + prepare-release: + runs-on: macos-14 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required to fetch all history for the merge check + + - name: Set up Git configuration + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git fetch --all + + - name: Verify Previous Release is Merged (Major Only) + if: ${{ github.event.inputs.release_type == 'major' }} + run: | + 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:]') + + if [ -z "$LATEST_BRANCH" ]; then + echo "⚠️ No previous release branches found on remote. Skipping merge check." + exit 0 + fi + + echo "Latest release branch found: $LATEST_BRANCH" + echo "Checking if $LATEST_BRANCH is merged into main..." + + # Check if the latest release branch is an ancestor of main + if ! git merge-base --is-ancestor origin/$LATEST_BRANCH origin/main; then + echo "❌ ERROR: $LATEST_BRANCH has NOT been merged into main!" + echo "Please merge the previous release branch into main before cutting a new major release." + exit 1 + else + echo "✅ $LATEST_BRANCH is successfully merged into main." + fi + + - name: Prepare Branch + id: branch_prep + run: | + VERSION="${{ github.event.inputs.version }}" + BRANCH_NAME="grpc_release_${VERSION}.x" + + if [ "${{ github.event.inputs.release_type }}" == "major" ]; then + echo "Preparing Major Release for $BRANCH_NAME..." + git checkout main + git checkout -b $BRANCH_NAME + 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 + fi + + # Save branch name to environment for later steps + echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV + + - name: Prepare Environment + run: | + chmod +x ./scripts/prepare_env.sh + ./scripts/prepare_env.sh + + - name: Sync gRPC Code + run: | + source .venv/bin/activate + chmod +x ./scripts/sync_grpc_src_shallow.sh + ./scripts/sync_grpc_src_shallow.sh ${{ github.event.inputs.sync_tag }} + + - name: Commit Changes + run: | + git add . + git commit -m "Sync c-core ${{ github.event.inputs.sync_tag }}" + + - name: Push Branch and Tag + 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