|
| 1 | +name: Create Release Branch Workflow |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + version: |
| 6 | + description: "Release version" |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + branch_name: |
| 10 | + description: "Release branch name" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + commit_sha: |
| 14 | + description: "Optional commit SHA to start release branch from. By default, it will use the latest commit on the main branch." |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + |
| 18 | +jobs: |
| 19 | + create-release-branch: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Check if release branch already exists |
| 28 | + id: check-branch |
| 29 | + run: | |
| 30 | + if git show-ref --verify --quiet refs/heads/${{ github.event.inputs.branch_name }}; then |
| 31 | + echo "Release branch ${{ github.event.inputs.branch_name }} already exists." |
| 32 | + git checkout ${{ github.event.inputs.branch_name }} |
| 33 | + else |
| 34 | + echo "create_new_branch=true" >> $GITHUB_ENV |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Create release branch |
| 38 | + id: create-branch |
| 39 | + if: env.create_new_branch == 'true' |
| 40 | + run: | |
| 41 | + echo "Release branch ${{ github.event.inputs.branch_name }} does not exist. Creating it." |
| 42 | + if [ "${{ github.event.inputs.commit_sha }}" != "" ]; then |
| 43 | + export "COMMIT_SHA=${{ github.event.inputs.commit_sha }}" |
| 44 | + else |
| 45 | + export "COMMIT_SHA=$(git rev-parse HEAD)" |
| 46 | + fi |
| 47 | + git checkout -b ${{ github.event.inputs.branch_name }} $COMMIT_SHA |
| 48 | + git push origin ${{ github.event.inputs.branch_name }} |
| 49 | +
|
| 50 | + - name: Replace version in release.json |
| 51 | + id: replace-version |
| 52 | + run: | |
| 53 | + jq --arg version "${{ github.event.inputs.version }}" '.mongodbOperator=$version' release.json > tmp_release.json |
| 54 | + mv tmp_release.json release.json |
| 55 | + git add release.json |
| 56 | + git commit -m "Update release.json with version ${{ github.event.inputs.version }}" |
| 57 | + git push origin ${{ github.event.inputs.branch_name }} |
0 commit comments