Release and deploy #27
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
name: Release and deploy | |
on: | |
workflow_dispatch: | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- name: Cache Maven repository | |
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Set up JDK 21 | |
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: maven | |
- name: Setup Maven server settings | |
uses: s4u/maven-settings-action@7802f6aec16c9098b4798ad1f1d8ac75198194bd # v3.0.0 | |
with: | |
servers: | | |
[{ | |
"id": "nvd", | |
"username": "john.doe", | |
"password": "${{ secrets.NVD_KEY }}" | |
}, | |
{ | |
"id": "docker.io", | |
"username": "${{ secrets.DOCKER_USERNAME }}", | |
"password": "${{ secrets.DOCKER_TOKEN }}" | |
}] | |
- name: Extract version from POM | |
id: extract_version | |
run: | | |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
# Remove -SNAPSHOT from version | |
VERSION=${VERSION%-SNAPSHOT} | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Set up Git user | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
- name: Set release version | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
mvn versions:set -DnewVersion=${{ env.VERSION }} | |
git commit -am "Release version set" | |
git push origin main | |
- name: Build with Maven | |
run: mvn -B clean install package -Pdocker --file pom.xml | |
- name: Create and push tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git tag v${{ env.VERSION }} | |
git push origin v${{ env.VERSION }} | |
- name: Increase version | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
mvn -B release:update-versions | |
git commit -am "Next development version set" | |
git push origin main | |
- name: Upload released assets | |
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2 | |
with: | |
name: v${{ env.VERSION }} | |
tag_name: v${{ env.VERSION }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
draft: false | |
prerelease: true | |
files: | | |
target/repository-*.* |