Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions .github/workflows/release.yml
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we tested this in the fork yet? I also noticed the note: "Needs to be tested by triggering GitHub Actions manually before merging.”

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ jobs:

steps:
- name: "Create release output"
run: echo '🎬 Release process for version ${{ env.RELEASE_VERSION }} started by @${{ github.triggering_actor }}' >> $GITHUB_STEP_SUMMARY

run: echo "🎬 Release process for version ${RELEASE_VERSION} started by @${GITHUB_TRIGGERING_ACTOR}" >> $GITHUB_STEP_SUMMARY
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
fetch-depth: 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

I think fetch-depth: 0 fetches all history for all branches and tags. But is it just for the mongodb-labs/drivers-github-tools/secure-checkout or is it for the java driver repo itself?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rozza yes fetch-depth 0 fetches all branches and tags.

Per the GitHub Actions documentation (https://docs.github.com/en/actions/tutorials/create-an-example-workflow), drivers-github-tools is only pulled internally to run the action itself. The checkout operates on github.ref.


- name: "Store version numbers in env variables"
# The awk command to increase the version number was copied from
Expand All @@ -42,29 +43,36 @@ jobs:
# RELEASE_BRANCH: The name of the stable branch for this release series
# Example: 5.2.0 => 5.2.x
# Example: 5.2.0-beta1 => <current branch>
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV
echo RELEASE_VERSION_WITHOUT_SUFFIX=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV
if [[ "${{ inputs.version }}" =~ (alpha|beta|rc)[0-9]+$ ]]; then
echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV
echo RELEASE_BRANCH=${{ github.ref_name }} >> $GITHUB_ENV
echo CURRENT_TAG=$(git \
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this git command is somewhat complex. what it does - a) get all tags b) teaches git that those suffixes make a version lower than just the minor/major version c) get the first one in the list (which is the most current tag)

-c versionsort.suffix=-alpha \
-c versionsort.suffix=-beta \
-c versionsort.suffix=-rc \
tag --list 'r*' --sort=-v:refname | head -n 1) >> $GITHUB_ENV
echo RELEASE_VERSION=${INPUT_VERSION} >> $GITHUB_ENV
echo RELEASE_VERSION_WITHOUT_SUFFIX=$(echo ${INPUT_VERSION} | awk -F- '{print $1}') >> $GITHUB_ENV
if [[ "${INPUT_VERSION}" =~ (alpha|beta|rc)[0-9]+$ ]]; then
echo NEXT_VERSION=$(echo ${INPUT_VERSION} | awk -F- '{print $1}') >> $GITHUB_ENV
echo RELEASE_BRANCH=${GITHUB_REF_NAME} >> $GITHUB_ENV
else
echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV
echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV
echo NEXT_VERSION=$(echo ${INPUT_VERSION} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV
echo RELEASE_BRANCH=$(echo ${INPUT_VERSION} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV
fi

- name: "Ensure current snapshot version matches release version"
run: |
grep -q "version=${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT" gradle.properties
grep -q "version=${RELEASE_VERSION_WITHOUT_SUFFIX}-SNAPSHOT" gradle.properties
if [[ $? != 0 ]]; then
echo '❌ Release failed: version in gradle.properties is not a snapshot for release version ${{ inputs.version }}' >> $GITHUB_STEP_SUMMARY
echo "❌ Release failed: version in gradle.properties is not a snapshot for release version ${RELEASE_VERSION}" >> $GITHUB_STEP_SUMMARY
exit 1
fi

- name: "Ensure release tag does not already exist"
run: |
if [[ $(git tag -l r${{ env.RELEASE_VERSION }}) == r${{ env.RELEASE_VERSION }} ]]; then
echo '❌ Release failed: tag for version ${{ inputs.version }} already exists' >> $GITHUB_STEP_SUMMARY
if [[ $(git tag -l r${RELEASE_VERSION}) == r${RELEASE_VERSION} ]]; then
echo "❌ Release failed: tag for version ${RELEASE_VERSION} already exists" >> $GITHUB_STEP_SUMMARY
exit 1
fi

Expand All @@ -74,7 +82,7 @@ jobs:
- name: "Fail if patch release is created from wrong release branch"
if: ${{ !endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name }}
run: |
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
echo "❌ Release failed due to branch mismatch: expected ${RELEASE_VERSION} to be released from ${RELEASE_BRANCH}, got ${GITHUB_REF_NAME}" >> $GITHUB_STEP_SUMMARY
exit 1

# For non-patch releases (A.B.C where C == 0), we expect the release to
Expand All @@ -83,16 +91,18 @@ jobs:
- name: "Fail if non-patch release is created from wrong release branch"
if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'main' }}
run: |
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or main, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
echo "❌ Release failed due to branch mismatch: expected ${RELEASE_VERSION} to be released from ${RELEASE_BRANCH} or main, got ${GITHUB_REF_NAME}" >> $GITHUB_STEP_SUMMARY
exit 1

# Set commit author information to the user that triggered the release workflow
- name: "Set git author information"
env:
ACTOR: ${{ github.actor }}
run: |
GITHUB_USER_NAME=$(gh api users/${{ github.actor }} --jq '.name')
GITHUB_USER_ID=$(gh api users/${{ github.actor }} --jq '.id')
GITHUB_USER_NAME=$(gh api users/${ACTOR} --jq '.name')
GITHUB_USER_ID=$(gh api users/${ACTOR} --jq '.id')
git config user.name "${GITHUB_USER_NAME}"
git config user.email "${GITHUB_USER_ID}+${{ github.actor }}@users.noreply.github.com"
git config user.email "${GITHUB_USER_ID}+${ACTOR}@users.noreply.github.com"

# If a non-patch release is created from a branch other than its
# maintenance branch, create that branch from the current one and push it
Expand All @@ -101,39 +111,40 @@ jobs:
- name: "Create new release branch for non-patch release"
if: ${{ endsWith(env.RELEASE_VERSION, '.0') && env.RELEASE_BRANCH != github.ref_name }}
run: |
echo '🆕 Creating new release branch ${{ env.RELEASE_BRANCH }} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
git checkout -b ${{ env.RELEASE_BRANCH }}
NEXT_MINOR_VERSION=$(echo "${{ env.RELEASE_VERSION }}" | awk -F. -v OFS=. '{$2 += 1 ; $NF = 0 ; print}')
echo "➡️ Bumping version for ${{ github.ref_name }} branch to ${NEXT_MINOR_VERSION}" >> $GITHUB_STEP_SUMMARY
git checkout ${{ github.ref_name }}
.github/workflows/bump-version.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT" "${NEXT_MINOR_VERSION}-SNAPSHOT"
git push origin ${{ github.ref_name }}
git checkout ${{ env.RELEASE_BRANCH }}
echo "🆕 Creating new release branch ${RELEASE_BRANCH} from ${GITHUB_REF_NAME}" >> $GITHUB_STEP_SUMMARY
git checkout -b ${RELEASE_BRANCH}
NEXT_MINOR_VERSION=$(echo "${RELEASE_VERSION}" | awk -F. -v OFS=. '{$2 += 1 ; $NF = 0 ; print}')
echo "➡️ Bumping version for ${GITHUB_REF_NAME} branch to ${NEXT_MINOR_VERSION}" >> $GITHUB_STEP_SUMMARY
git checkout ${GITHUB_REF_NAME}
.github/workflows/bump-version.sh "${RELEASE_VERSION_WITHOUT_SUFFIX}-SNAPSHOT" "${NEXT_MINOR_VERSION}-SNAPSHOT"
git push origin ${GITHUB_REF_NAME}
git checkout ${RELEASE_BRANCH}

# This step bumps version numbers in gradle.properties and creates git artifacts for the release
- name: "Bump version numbers and create release tag"
run: .github/workflows/bump-and-tag.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}" "${{ env.RELEASE_VERSION }}" "${{ env.NEXT_VERSION }}"
run: .github/workflows/bump-and-tag.sh "${RELEASE_VERSION_WITHOUT_SUFFIX}" "${RELEASE_VERSION}" "${NEXT_VERSION}"

- name: "Push release branch and tag"
run: |
git push origin ${{ env.RELEASE_BRANCH }}
git push origin r${{ env.RELEASE_VERSION }}
git push origin ${RELEASE_BRANCH}
git push origin r${RELEASE_VERSION}

- name: "Create draft release with generated changelog"
run: |
if [[ "${{ inputs.version }}" =~ (alpha|beta|rc) ]]; then
if [[ "${RELEASE_VERSION}" =~ (alpha|beta|rc) ]]; then
PRERELEASE="--prerelease --latest=false"
fi
echo "RELEASE_URL=$(\
gh release create r${RELEASE_VERSION} \
${PRERELEASE} \
--target ${{ env.RELEASE_BRANCH }} \
--title "Java Driver ${{ env.RELEASE_VERSION }} ($(date '+%B %d, %Y'))" \
--target ${RELEASE_BRANCH} \
--title "Java Driver ${RELEASE_VERSION} ($(date '+%B %d, %Y'))" \
--generate-notes \
--notes-start-tag "${CURRENT_TAG}" \
--draft\
)" >> "$GITHUB_ENV"

- name: "Set summary"
run: |
echo '🚀 Created tag and drafted release for version [${{ env.RELEASE_VERSION }}](${{ env.RELEASE_URL }})' >> $GITHUB_STEP_SUMMARY
echo "🚀 Created tag and drafted release for version [${RELEASE_VERSION}](${RELEASE_URL})" >> $GITHUB_STEP_SUMMARY
echo '✍️ You may now update the release notes and publish the release when ready' >> $GITHUB_STEP_SUMMARY