Skip to content

Publish

Publish #45

Workflow file for this run

name: Publish
on:
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
build-and-publish-image:
runs-on: ubuntu-24.04
# Permissions required for publishing Docker image.
# See https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
# And permissions required for creating releases.
# See https://github.com/softprops/action-gh-release
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get releases
id: get_releases
run: |
ALL_RELEASES=$(gh api "repos/${GITHUB_REPOSITORY}/releases" --paginate --jq '.[].tag_name')
{
echo 'all_releases<<EOF'
echo "$ALL_RELEASES"
echo EOF
} >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Derive build versions from:
# - Maven version (e.g., 1.29-SNAPSHOT)
# - Existing preview releases (e.g., v1.29.0-preview)
#
# The build version is derived as `1.29.0-preview`.
# If a release already exists with a tag starting with `v1.29.0-preview`,
# the derived version is incremented with a numeric suffix:
# 1.29.0-preview.1, 1.29.0-preview.2, etc.
#
# This versioning follows Semantic Versioning 2.0.0.
# See https://semver.org/
- name: Set version
id: set_version
run: |
VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"
BASE_VERSION=${VERSION%-SNAPSHOT}
BUILD_VERSION="${BASE_VERSION}.0-preview"
PREVIEWS_COUNT=$(grep -c -F "v${BUILD_VERSION}" <<< "${{ steps.get_releases.outputs.all_releases }}" || true)
if (( PREVIEWS_COUNT != 0 )); then
BUILD_VERSION="${BUILD_VERSION}.${PREVIEWS_COUNT}"
fi
mvn --batch-mode versions:set -DnewVersion="$BUILD_VERSION" -DgenerateBackupPoms=false
echo "build_version=$BUILD_VERSION" >> $GITHUB_OUTPUT
- name: Build with Maven
run: |
LOGGING_CONFIG_PATH="org-tweetyproject-web/src/main/resources"
# Logging to stdout by default is more appropriate for a container deployment
mv "$LOGGING_CONFIG_PATH"/logback_stdout.xml "$LOGGING_CONFIG_PATH"/logback.xml
mvn --batch-mode --update-snapshots install -Dgpg.skip=true
mvn --batch-mode --update-snapshots spring-boot:build-image -pl org-tweetyproject-web -DskipTests -Dgpg.skip=true
- name: Publish Fat Jar
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.set_version.outputs.build_version }}
files: org-tweetyproject-web/target/web-*.jar
prerelease: true
- name: Build, tag and push Docker image
run: |
IMAGE_NAME="${{ env.REGISTRY }}/${GITHUB_REPOSITORY@L}/tweetyproject-web-server"
IMAGE_REF_WITH_VERSION="$IMAGE_NAME:${{ steps.set_version.outputs.build_version }}"
docker tag web:${{ steps.set_version.outputs.build_version }} "$IMAGE_REF_WITH_VERSION"
docker push "$IMAGE_REF_WITH_VERSION"
IMAGE_REF_LATEST="$IMAGE_NAME:latest"
docker tag web:${{ steps.set_version.outputs.build_version }} "$IMAGE_REF_LATEST"
docker push "$IMAGE_REF_LATEST"