|
| 1 | +# |
| 2 | +# Copyright OpenSearch Contributors |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# The OpenSearch Contributors require contributions made to |
| 6 | +# this file be licensed under the Apache-2.0 license or a |
| 7 | +# compatible open source license. |
| 8 | +# |
| 9 | + |
| 10 | +# This workflow automates the preparation of patch release branches. |
| 11 | +# It validates the release branch, updates gradle.properties to the next version |
| 12 | +# generates the THIRD-PARTY file, and creates a pull request with all changes. |
| 13 | + |
| 14 | +name: Prepare Release Branch |
| 15 | + |
| 16 | +on: |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + pull-requests: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + prepare-release: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout Data Prepper |
| 29 | + uses: actions/checkout@v2 |
| 30 | + |
| 31 | + - name: Validate release branch |
| 32 | + id: validate_branch |
| 33 | + run: | |
| 34 | + BRANCH_NAME=${GITHUB_REF#refs/heads/} |
| 35 | + echo "Running on branch: $BRANCH_NAME" |
| 36 | + |
| 37 | + # Validate branch name matches {major}.{minor} pattern |
| 38 | + if ! [[ $BRANCH_NAME =~ ^[0-9]+\.[0-9]+$ ]]; then |
| 39 | + echo "::error::Invalid release branch name: $BRANCH_NAME" |
| 40 | + echo "This workflow must run on a release branch with format {major}.{minor} (e.g., '2.6')" |
| 41 | + echo "Current branch: $BRANCH_NAME" |
| 42 | + echo "" |
| 43 | + echo "To run this workflow:" |
| 44 | + echo " 1. Switch to a release branch (e.g., 2.6)" |
| 45 | + echo " 2. Navigate to Actions > Prepare Patch Release" |
| 46 | + echo " 3. Click 'Run workflow' and select the release branch" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + |
| 50 | + echo "✅ Valid release branch: $BRANCH_NAME" |
| 51 | + echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Set up JDK |
| 54 | + uses: actions/setup-java@v4 |
| 55 | + with: |
| 56 | + java-version: 21 |
| 57 | + distribution: temurin |
| 58 | + |
| 59 | + - name: Update version to next release |
| 60 | + id: version |
| 61 | + run: | |
| 62 | + ./gradlew updateToNextVersion |
| 63 | + |
| 64 | + RELEASE_VERSION=$(./gradlew -q printCurrentVersion) |
| 65 | + echo "version=$RELEASE_VERSION" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Generate THIRD-PARTY file |
| 68 | + run: | |
| 69 | + echo "Generating THIRD-PARTY file..." |
| 70 | + |
| 71 | + # Run the Gradle task to generate the THIRD-PARTY file |
| 72 | + # Capture both stdout and stderr for better error reporting |
| 73 | + if ! OUTPUT=$(./gradlew --no-daemon generateThirdPartyReport 2>&1); then |
| 74 | + echo "::error::Failed to generate THIRD-PARTY file" |
| 75 | + echo "Gradle output:" |
| 76 | + echo "$OUTPUT" |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + |
| 80 | + # Verify the THIRD-PARTY file was created/updated |
| 81 | + if [ ! -f THIRD-PARTY ]; then |
| 82 | + echo "::error::THIRD-PARTY file not found after generation" |
| 83 | + echo "The generateThirdPartyReport task completed but did not create the expected file" |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + |
| 87 | + echo "Successfully generated THIRD-PARTY file" |
| 88 | +
|
| 89 | + - name: GitHub App token |
| 90 | + id: github_app_token |
| 91 | + uses: tibdex/github-app-token@v2 |
| 92 | + with: |
| 93 | + app_id: ${{ secrets.APP_ID }} |
| 94 | + private_key: ${{ secrets.APP_PRIVATE_KEY }} |
| 95 | + |
| 96 | + - name: Create Pull Request |
| 97 | + id: create_pr |
| 98 | + uses: peter-evans/create-pull-request@v6 |
| 99 | + with: |
| 100 | + token: ${{ steps.github_app_token.outputs.token }} |
| 101 | + add-paths: | |
| 102 | + gradle.properties |
| 103 | + THIRD-PARTY |
| 104 | + commit-message: 'Prepare release ${{ steps.version.outputs.version }}' |
| 105 | + signoff: true |
| 106 | + branch: prepare-release-${{ steps.version.outputs.version }} |
| 107 | + delete-branch: true |
| 108 | + base: ${{ steps.validate_branch.outputs.branch }} |
| 109 | + title: 'Prepare release ${{ steps.version.outputs.version }}' |
| 110 | + body: | |
| 111 | + ## Automated Release Preparation |
| 112 | + |
| 113 | + This PR prepares the release branch for version **${{ steps.version.outputs.version }}**. |
| 114 | + |
| 115 | + ### Automated Changes |
| 116 | + - Updated `gradle.properties` version to `${{ steps.version.outputs.version }}` |
| 117 | + - Generated `THIRD-PARTY` file |
| 118 | + |
| 119 | + ### Manual Steps Remaining |
| 120 | + |
| 121 | + Before merging this PR: |
| 122 | + - [ ] Review the version number is correct |
| 123 | + - [ ] Review the THIRD-PARTY file changes |
| 124 | + |
| 125 | + After merging this PR: |
| 126 | + - [ ] Prepare release notes (see [release notes script](release/script/release-notes/README.md)) |
| 127 | + - [ ] Run the [Release Artifacts workflow](https://github.com/opensearch-project/data-prepper/actions/workflows/release.yml) |
| 128 | + - [ ] Approve the release issue (requires 2 maintainer approvals) |
| 129 | + - [ ] Update the draft release with release notes |
| 130 | + - [ ] Publish the release |
| 131 | + - [ ] Close the milestone |
| 132 | + |
| 133 | + --- |
| 134 | + |
| 135 | + Branch: ${{ steps.validate_branch.outputs.branch }} |
| 136 | + |
| 137 | + Generated by the [Prepare Patch Release workflow](https://github.com/opensearch-project/data-prepper/actions/workflows/release-prepare-patch.yml) |
| 138 | +
|
| 139 | + - name: Output PR URL |
| 140 | + if: steps.create_pr.outputs.pull-request-url |
| 141 | + run: | |
| 142 | + echo "✅ Pull Request created successfully!" |
| 143 | + echo "URL: ${{ steps.create_pr.outputs.pull-request-url }}" |
| 144 | + echo "::notice::Pull Request created: ${{ steps.create_pr.outputs.pull-request-url }}" |
| 145 | +
|
| 146 | + - name: Check PR creation |
| 147 | + if: steps.create_pr.outcome == 'failure' |
| 148 | + run: | |
| 149 | + echo "::error::Failed to create pull request" |
| 150 | + echo "This could be due to:" |
| 151 | + echo " - Missing or invalid GitHub App credentials" |
| 152 | + echo " - Insufficient permissions" |
| 153 | + echo " - Network issues" |
| 154 | + echo "Please check the logs above for more details" |
| 155 | + exit 1 |
| 156 | +
|
| 157 | + - name: Workflow summary |
| 158 | + if: always() |
| 159 | + run: | |
| 160 | + echo "## Workflow Execution Summary" >> $GITHUB_STEP_SUMMARY |
| 161 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 162 | + |
| 163 | + if [ "${{ steps.validate_branch.outcome }}" == "success" ]; then |
| 164 | + echo "✅ Branch validation: **${{ steps.validate_branch.outputs.branch }}**" >> $GITHUB_STEP_SUMMARY |
| 165 | + else |
| 166 | + echo "❌ Branch validation failed" >> $GITHUB_STEP_SUMMARY |
| 167 | + fi |
| 168 | + |
| 169 | + if [ "${{ steps.version.outcome }}" == "success" ]; then |
| 170 | + echo "✅ Version determination: **${{ steps.version.outputs.version }}**" >> $GITHUB_STEP_SUMMARY |
| 171 | + else |
| 172 | + echo "❌ Version determination failed" >> $GITHUB_STEP_SUMMARY |
| 173 | + fi |
| 174 | + |
| 175 | + if [ "${{ steps.create_pr.outcome }}" == "success" ]; then |
| 176 | + echo "✅ Pull request created: ${{ steps.create_pr.outputs.pull-request-url }}" >> $GITHUB_STEP_SUMMARY |
| 177 | + else |
| 178 | + echo "❌ Pull request creation failed" >> $GITHUB_STEP_SUMMARY |
| 179 | + fi |
0 commit comments