|
| 1 | +name: "Release New Version" |
| 2 | +run-name: "Release ${{ inputs.version }}" |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: "The version to be released. This is checked for consistency with the branch name and configuration" |
| 9 | + required: true |
| 10 | + type: "string" |
| 11 | + |
| 12 | +env: |
| 13 | + # TODO: Use different token |
| 14 | + GH_TOKEN: ${{ secrets.MERGE_UP_TOKEN }} |
| 15 | + GIT_AUTHOR_NAME: "DBX PHP Release Bot" |
| 16 | + GIT_AUTHOR_EMAIL: "[email protected]" |
| 17 | + |
| 18 | +jobs: |
| 19 | + prepare-release: |
| 20 | + name: "Prepare release" |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: "Create release output" |
| 25 | + run: echo '🎬 Release process for version ${{ inputs.version }} started by @${{ github.triggering_actor }}' >> $GITHUB_STEP_SUMMARY |
| 26 | + |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + submodules: true |
| 30 | + token: ${{ env.GH_TOKEN }} |
| 31 | + |
| 32 | + - name: "Store version numbers in env variables" |
| 33 | + run: | |
| 34 | + echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV |
| 35 | + echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | cut -d '.' -f-2) >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - name: "Ensure release tag does not already exist" |
| 38 | + run: | |
| 39 | + if [[ $(git tag -l ${RELEASE_VERSION}) == ${RELEASE_VERSION} ]]; then |
| 40 | + echo '❌ Release failed: tag for version ${{ inputs.version }} already exists' >> $GITHUB_STEP_SUMMARY |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: "Fail if branch names don't match" |
| 45 | + if: ${{ github.ref_name != env.RELEASE_BRANCH }} |
| 46 | + run: | |
| 47 | + echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY |
| 48 | + exit 1 |
| 49 | +
|
| 50 | + # |
| 51 | + # Preliminary checks done - commence the release process |
| 52 | + # |
| 53 | + |
| 54 | + - name: "Set git author information" |
| 55 | + run: | |
| 56 | + git config user.name "${GIT_AUTHOR_NAME}" |
| 57 | + git config user.email "${GIT_AUTHOR_EMAIL}" |
| 58 | +
|
| 59 | + # Create draft release with release notes |
| 60 | + - name: "Create draft release" |
| 61 | + run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ github.ref_name }} --title "${{ inputs.version }}" --generate-notes --draft)" >> "$GITHUB_ENV" |
| 62 | + |
| 63 | + # This step creates the signed release tag |
| 64 | + - name: "Create release tag" |
| 65 | + uses: mongodb-labs/drivers-github-tools/garasign/git-sign@v1 |
| 66 | + with: |
| 67 | + command: "git tag -m 'Release ${{ inputs.version }}' -s --local-user=${{ vars.GPG_KEY_ID }} ${{ inputs.version }}" |
| 68 | + garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }} |
| 69 | + garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }} |
| 70 | + artifactory_username: ${{ secrets.ARTIFACTORY_USER }} |
| 71 | + artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }} |
| 72 | + |
| 73 | + # TODO: Manually merge using ours strategy. This avoids merge-up pull requests being created |
| 74 | + # Process is: |
| 75 | + # 1. switch to next branch (according to merge-up action) |
| 76 | + # 2. merge release branch using --strategy=ours |
| 77 | + # 3. push next branch |
| 78 | + # 4. switch back to release branch, then push |
| 79 | + |
| 80 | + - name: "Push changes from release branch" |
| 81 | + run: git push |
| 82 | + |
| 83 | + # Pushing the release tag starts build processes that then produce artifacts for the release |
| 84 | + - name: "Push release tag" |
| 85 | + run: git push origin ${{ inputs.version }} |
| 86 | + |
| 87 | + - name: "Set summary" |
| 88 | + run: | |
| 89 | + echo '🚀 Created tag and drafted release for version [${{ inputs.version }}](${{ env.RELEASE_URL }})' >> $GITHUB_STEP_SUMMARY |
| 90 | + echo '✍️ You may now update the release notes and publish the release when ready' >> $GITHUB_STEP_SUMMARY |
0 commit comments