Skip to content

Release workflow

Release workflow #288

name: Release workflow
on:
workflow_dispatch: # Allows manual triggering
env:
JAVA_VERSION: 21
REGISTRY_IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/shikkanime-core
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'corretto'
- name: Build and test
run: ./gradlew clean test --info
upgrade-version:
runs-on: ubuntu-latest
needs: test
outputs:
v-version: ${{ steps.version.outputs.v-version }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Get next version
uses: reecetech/[email protected]
id: version
with:
scheme: conventional_commits
- name: Update version in build.gradle.kts
run: |
#!/bin/bash
PROJECT_VERSION=$(cat 'build.gradle.kts' | grep -oP 'version = "\K[^\\"]*' | head -n 1)
# Update the file
sed -i "s|$PROJECT_VERSION|${{ steps.version.outputs.version }}|g" build.gradle.kts
# Set up Git
git config user.name Ziedelth
git config user.email ${{ secrets.USER_EMAIL }}
# Commit the changes
git add build.gradle.kts
git commit -m "Update version to ${{ steps.version.outputs.version }}"
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.USER_TOKEN }}
branch: ${{ github.ref }}
force: true
push-tag:
runs-on: ubuntu-latest
needs: upgrade-version
steps:
- uses: actions/checkout@v4
# Pull the latest commits
- name: Pull latest commits
run: git pull
- name: Push Git Tag
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git tag ${{ needs.upgrade-version.outputs.v-version }}
git push origin ${{ needs.upgrade-version.outputs.v-version }}
docker:
runs-on: ubuntu-latest
needs: [upgrade-version,push-tag]
strategy:
fail-fast: false
matrix:
platform: [linux/amd64, linux/arm64]
build_version: [slim, full]
steps:
- uses: actions/checkout@v4
# Pull the latest commits
- name: Pull latest commits
run: git pull
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'corretto'
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=${{ needs.upgrade-version.outputs.v-version }}-${{ matrix.build_version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build
run: gradle clean installDist
- name: Build docker file
id: build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
build-args: BUILD_VERSION=${{ matrix.build_version }}
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:${{ matrix.build_version }}
cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:${{ matrix.build_version }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs: docker
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}