Skip to content

Release CI

Release CI #43

Workflow file for this run

name: Release CI
on:
workflow_dispatch:
inputs:
version-overwrite:
required: false
default: ''
description: 'Use this to overwrite the version number to release, otherwise uses the current SNAPSHOT version (expected format x.y.z)'
type: string
permissions: { }
jobs:
prepare-release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.variables.outputs.version }}
next-version: ${{ steps.variables.outputs.next-version }}
release-branch: ${{ steps.variables.outputs.release-branch }}
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
with:
persist-credentials: false
- name: Setup Environment
id: variables
env:
VERSION_OVERWRITE: ${{ github.event.inputs.version-overwrite }}
run: |-
VERSION="${VERSION_OVERWRITE}"
if [[ -z ${VERSION} ]]; then
CURRENT_SNAPSHOT=`yq -p=xml '.project.version' pom.xml`
VERSION=${CURRENT_SNAPSHOT%-SNAPSHOT}
fi
NEXT_VERSION="${VERSION%.*}.$((${VERSION##*.} + 1))-SNAPSHOT"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "next-version=${NEXT_VERSION}" >> $GITHUB_OUTPUT
echo "release-branch=${VERSION%.*}.x" >> $GITHUB_OUTPUT
create-release:
runs-on: ubuntu-latest
needs:
- prepare-release
env:
VERSION: ${{ needs.prepare-release.outputs.version }}
BRANCH_NAME: ${{ needs.prepare-release.outputs.release-branch }}
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
with:
token: ${{ secrets.BOT_RELEASE_GITHUB_TOKEN }}
- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # tag=v5.2.0
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Set Version and Commit
run: |-
git config user.name "dependencytrack-bot"
git config user.email "106437498+dependencytrack-bot@users.noreply.github.com"
if [[ -z $(git ls-remote --quiet --heads origin "${BRANCH_NAME}") ]]; then
git checkout -b "${BRANCH_NAME}"
else
git fetch origin "${BRANCH_NAME}"
git checkout "${BRANCH_NAME}"
fi
mvn -B --no-transfer-progress versions:set -DnewVersion=${VERSION}
git add pom.xml
git commit -m "prepare-release: set version to ${VERSION}"
git push origin "${BRANCH_NAME}"
git tag "${VERSION}"
git push origin "${VERSION}"
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.BOT_RELEASE_GITHUB_TOKEN }}
RELEASE_VERSION: ${{ needs.prepare-release.outputs.version }}
RELEASE_BRANCH: ${{ needs.prepare-release.outputs.release-branch }}
run: |-
gh release create "${RELEASE_VERSION}" \
--target "${RELEASE_BRANCH}" \
--title "${RELEASE_VERSION}" \
--generate-notes \
--draft
post-release:
runs-on: ubuntu-latest
permissions:
contents: write # Required to push pom.xml update
needs:
- prepare-release
- create-release
env:
NEXT_VERSION: ${{ needs.prepare-release.outputs.next-version }}
BRANCH_NAME: ${{ needs.prepare-release.outputs.release-branch }}
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
with:
ref: ${{ needs.prepare-release.outputs.release-branch }}
- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # tag=v5.2.0
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Set SNAPSHOT Version after Release
run: |-
git config user.name "dependencytrack-bot"
git config user.email "106437498+dependencytrack-bot@users.noreply.github.com"
mvn -B --no-transfer-progress versions:set -DnewVersion=${NEXT_VERSION}
git add pom.xml
git commit -m "prepare-iteration: set version to ${NEXT_VERSION}"
git push origin "${BRANCH_NAME}"