Release v1.0.00 to GitHub Packages #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fully automated release to GitHub Packages | |
# This workflow performs the following operations: | |
# | |
# - Create a release branch | |
# - Prepare the release with Maven | |
# - Perform the release to GitHub Packages | |
# - Upload Maven Site to GitHub Pages | |
# - Publish the packages as a GitHub Release | |
# - Create a Pull Request to prepare next development version | |
# | |
# Requires the GITHUB_TOKEN secret to be defined (workspace or organization) | |
name: Release to GitHub Packages | |
run-name: Release v${{ inputs.releaseVersion }} to GitHub Packages | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseVersion: | |
type: string | |
description: "Release version" | |
required: true | |
default: "" | |
developmentVersion: | |
type: string | |
description: "New SNAPSHOT version" | |
required: true | |
default: "" | |
permissions: | |
contents: write | |
pull-requests: write | |
pages: write | |
id-token: write | |
packages: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these releases and deployments to complete. | |
concurrency: | |
group: release | |
cancel-in-progress: false | |
# Default to bash | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
prepare: | |
name: Prepare Release v${{ inputs.releaseVersion }} | |
runs-on: ubuntu-latest | |
outputs: | |
branchName: ${{ env.branchName }} | |
tagName: ${{ env.tagName }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: temurin | |
java-package: jdk | |
cache: maven | |
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml | |
settings-path: ${{ github.workspace }} # location for the settings.xml file | |
- name: Configure Git User | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "GitHub Actions" | |
- name: Set release branch and tag name | |
run: | | |
echo "branchName=release/v$INPUT_RELEASEVERSION" >> $GITHUB_ENV | |
echo "tagName=v$INPUT_RELEASEVERSION" >> $GITHUB_ENV | |
env: | |
INPUT_RELEASEVERSION: ${{ inputs.releaseVersion }} | |
- name: Create ${{ env.branchName }} branch | |
run: | | |
git checkout ${{ env.branchName }} 2>/dev/null || git checkout -b ${{ env.branchName }} | |
git push --force origin ${{ env.branchName }} | |
- name: Clean up existing ${{ env.tagName }} tags | |
run: | | |
git tag -d ${{ env.tagName }} || true | |
git push origin :refs/tags/${{ env.tagName }} || true | |
- name: Update project version to ${{ inputs.releaseVersion }} | |
run: | | |
mvn versions:set -DnewVersion=${{ inputs.releaseVersion }} | |
mvn versions:commit | |
- name: Commit ${{ inputs.releaseVersion }} | |
run: | | |
git add pom.xml metricshub-jre-linux/pom.xml metricshub-jre-windows/pom.xml | |
git commit -m "Updated POM version to ${{ inputs.releaseVersion }}" | |
- name: Create tag ${{ env.tagName }} | |
run: | | |
git tag -a ${{ env.tagName }} -m "Release ${{ env.tagName }}" | |
- name: Push tag ${{ env.tagName }} | |
run: | | |
git push origin ${{ env.tagName }} | |
- name: Prepare next version ${{ inputs.developmentVersion }} | |
run: | | |
mvn versions:set -DnewVersion=${{ inputs.developmentVersion }} | |
mvn versions:commit | |
git add pom.xml metricshub-jre-linux/pom.xml metricshub-jre-windows/pom.xml | |
git commit -m "Updated POM version to ${{ inputs.developmentVersion }}" | |
- name: Push next version ${{ inputs.developmentVersion }}" | |
run: | | |
git push origin ${{ env.branchName }} | |
release: | |
name: Release v${{ inputs.releaseVersion }} on ${{ matrix.config.os }} | |
needs: prepare | |
runs-on: ${{ matrix.config.os }} | |
strategy: | |
matrix: | |
config: | |
- { os: ubuntu-latest, packageSuffix: linux } | |
- { os: windows-latest, packageSuffix: windows } | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: temurin | |
java-package: jdk | |
cache: maven | |
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml | |
settings-path: ${{ github.workspace }} # location for the settings.xml file | |
- name: Checkout ${{ needs.prepare.outputs.tagName }} branch | |
run: | | |
git fetch | |
git checkout ${{ needs.prepare.outputs.tagName }} 2>/dev/null | |
- name: Perform release to GitHub Packages | |
id: perform | |
run: | | |
mvn -B -U \ | |
clean deploy \ | |
-s $GITHUB_WORKSPACE/settings.xml | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Package ${{ inputs.releaseVersion }} removal on failure | |
uses: actions/delete-package-versions@v4 | |
with: | |
package-version-ids: ${{ inputs.releaseVersion }} | |
package-name: org.sentrysoftware.metricshub-jre-${{ matrix.config.packageSuffix }} | |
package-type: maven | |
if: always() && (steps.perform.outcome == 'failure') | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: jre-${{ matrix.config.os }} | |
path: | | |
./target/*.buildinfo | |
./target/metricshub-jre-*/target/*.zip | |
./target/metricshub-jre-*/target/*.buildinfo | |
# Finalize job | |
finalize: | |
name: Finalize release | |
runs-on: ubuntu-latest | |
needs: [ prepare, release ] | |
steps: | |
- name: Setup tmate SSH session | |
uses: mxschmitt/action-tmate@v3 | |
with: | |
detached: true | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
merge-multiple: true | |
- name: Create a GitHub Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ needs.prepare.outputs.tagName }} | |
fail_on_unmatched_files: false | |
generate_release_notes: true | |
files: | | |
./target/*.buildinfo | |
./metricshub-jre-*/target/*.zip | |
./metricshub-jre-*/target/*.buildinfo | |
- name: Create Pull Request from ${{ needs.prepare.outputs.branchName }} to ${{ github.event.repository.default_branch }} | |
uses: devops-infra/[email protected] | |
with: | |
github_token: ${{ github.token }} | |
source_branch: ${{ needs.prepare.outputs.branchName }} | |
target_branch: ${{ github.event.repository.default_branch }} | |
title: Release v${{ inputs.releaseVersion }} and prepare v${{ inputs.developmentVersion }} | |
body: | | |
## Automated release | |
* Release **v${{ inputs.releaseVersion }}** | |
* Prepare **v${{ inputs.developmentVersion }}** | |
label: automatic | |
get_diff: true | |
allow_no_diff: true |