Skip to content

Prepare Release

Prepare Release #9

name: "Prepare Release"
on:
workflow_dispatch:
inputs:
branch:
description: "The Branch to Release From"
required: false
default: "main"
release-version:
description: "The Version to Release"
required: false
env:
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
JAVA_VERSION: 17
jobs:
bump-version:
name: "Bump Version"
outputs:
current-version: ${{ steps.determine-versions.outputs.CURRENT_SNAPSHOT }}
release-version: ${{ steps.determine-versions.outputs.RELEASE_VERSION }}
new-version: ${{ steps.determine-versions.outputs.NEW_SNAPSHOT }}
release-branch: ${{ steps.prepare-release.outputs.BRANCH_NAME }}
release-commit: ${{ steps.prepare-release.outputs.RELEASE_COMMIT_ID }}
release-tag: ${{ steps.prepare-release.outputs.TAG_NAME }}
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: "Prepare git"
run: |
git config --global user.email "[email protected]"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Determine Versions"
id: determine-versions
run: python .pipeline/scripts/get-release-versions.py
env:
INPUT_VERSION: ${{ github.event.inputs.release-version }}
- run: "echo Release Version: ${{ steps.determine-versions.outputs.RELEASE_VERSION }}"
- run: "echo Current Version: ${{ steps.determine-versions.outputs.CURRENT_SNAPSHOT }}"
- run: "echo New Version: ${{ steps.determine-versions.outputs.NEW_SNAPSHOT }}"
- name: "Set Release Version to ${{ steps.determine-versions.outputs.RELEASE_VERSION }}"
id: prepare-release
run: |
# NOTE: If you change this pattern here, also adjust perform_release.yml:
BRANCH_NAME=RELEASE-${{ steps.determine-versions.outputs.RELEASE_VERSION }}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
git switch --create $BRANCH_NAME
python .pipeline/scripts/set-release-versions.py --version ${{ steps.determine-versions.outputs.RELEASE_VERSION }}
git add .
git commit -m "Update to version ${{ steps.determine-versions.outputs.RELEASE_VERSION }}"
# Create release notes
python .pipeline/scripts/release_notes_automation.py --version ${{ steps.determine-versions.outputs.RELEASE_VERSION }} --folder "docs/release-notes"
git add .
git commit -m "Add new release notes"
# We need to get the commit id, and push the branch so the release tag will point at the right commit afterwards
RELEASE_COMMIT_ID=$(git log -1 --pretty=format:"%H")
echo "RELEASE_COMMIT_ID=$RELEASE_COMMIT_ID" >> $GITHUB_OUTPUT
TAG_NAME=rel/${{ steps.determine-versions.outputs.RELEASE_VERSION }}
git tag $TAG_NAME $RELEASE_COMMIT_ID
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
git push origin $BRANCH_NAME
git push origin $TAG_NAME
create-release:
name: "Create GitHub Release"
needs: [ bump-version ]
outputs:
release-name: ${{ steps.create-release.outputs.RELEASE_NAME }}
release-url: ${{ steps.create-release.outputs.RELEASE_URL }}
permissions:
contents: write # needed to create a new release
actions: read # needed to download the artifacts from the CI workflow
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.release-branch }}
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
cache: 'maven'
- name: "Build SDK"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean install -DskipTests"
mvn $MVN_ARGS
- name: "Create Release"
id: create-release
run: |
# Create a tarball of the whole repository into release-artifacts.tar.gz
tar --exclude=./release-artifacts.tar.gz -czf release-artifacts.tar.gz *
RELEASE_NAME="rel/${{ needs.bump-version.outputs.release-version }}"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_OUTPUT
RELEASE_URL=$(gh release create "$RELEASE_NAME" \
--target ${{ needs.bump-version.outputs.release-commit }} \
--title "Release ${{ needs.bump-version.outputs.release-version }}" \
--draft --generate-notes \
release-artifacts.tar.gz)
echo "RELEASE_URL=$RELEASE_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
create-code-pr:
name: "Create Code PR"
needs: [ bump-version, create-release ]
outputs:
pr-url: ${{ steps.create-code-pr.outputs.PR_URL }}
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.release-branch }}
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }} # this is needed so that the same token is used when pushing our changes later. Otherwise, our on: push workflows (i.e. our continuous integration) won't be triggered.
- name: "Prepare git"
run: |
git config --global user.email "[email protected]"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Set New Version and Reset Release Notes"
run: |
python .pipeline/scripts/set-release-versions.py --version ${{ needs.bump-version.outputs.new-version }}
git add .
git commit -m "Update to version ${{ needs.bump-version.outputs.new-version }}"
# Reset release notes for next version
cp .pipeline/scripts/release_notes_template.md docs/release-notes/release_notes.md
git add docs/release-notes/release_notes.md
git commit -m "Reset release notes"
git push
- name: "Create Code PR"
run: |
COMMIT_URL=${{ github.event.repository.html_url }}/commit/${{ needs.bump-version.outputs.release-commit }}
PR_URL=$(gh pr create --title "Release ${{ needs.bump-version.outputs.release-version }}" --body "## TODOs
- [ ] Review the changes in [the release commit]($COMMIT_URL)
- [ ] Review the [Draft Release](${{ needs.create-release.outputs.release-url }})
- [ ] Review **and approve** this PR
- [ ] Trigger the [Perform Release Workflow](${{ github.event.repository.html_url }}/actions/workflows/perform-release.yml)
- [ ] Once the `Perform Release` workflow is through, head over to the [Central Sonatype](https://central.sonatype.com/publishing/deployments) and log in with the credentials in the Team Password Safe. There should be a published release.")
echo "PR_URL=$PR_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
handle-failure:
runs-on: ubuntu-latest
needs: [ bump-version, create-release, create-code-pr ]
permissions:
contents: write # needed to delete the GitHub release
if: ${{ failure() }}
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: "Prepare git"
run: |
git config --global user.email "[email protected]"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Delete Release"
if: ${{ needs.create-release.outputs.release-url != '' }}
run: gh release delete --repo "${{ github.repository }}" ${{ needs.create-release.outputs.release-name }} --yes
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
continue-on-error: true
- name: "Delete Release Branch"
if: ${{ needs.bump-version.outputs.release-branch != '' }}
run: git push --delete origin ${{ needs.bump-version.outputs.release-branch }}
env:
GITHUB_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
continue-on-error: true
- name: "Delete Release Tag"
if: ${{ needs.bump-version.outputs.release-tag != '' }}
run: git push --delete origin ${{ needs.bump-version.outputs.release-tag }}
env:
GITHUB_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
continue-on-error: true