Skip to content

Publish

Publish #30

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: Set version
id: set_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
BASE_VERSION=${VERSION%-SNAPSHOT}
BUILD_DATE=$(date +%Y%m%d)
BUILD_VERSION="${BASE_VERSION}-${BUILD_DATE}-${GITHUB_SHA::7}"
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: ${{ steps.set_version.outputs.build_version }}
files: org-tweetyproject-web/target/web-*.jar
- 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"