update GitHub release action for catalog

This commit is contained in:
2025-07-29 17:34:42 +02:00
parent 3777682a2d
commit 19cd2c373b
3 changed files with 85 additions and 18 deletions

43
.github/workflows/publish-catalog.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
name: Publish Catalog
on:
workflow_call:
inputs:
JAVA_VERSION:
description: Java version to use
required: false
type: string
default: '17'
PROJECT_NAME:
description: Project name
required: true
type: string
PROJECT_VERSION:
description: Release version
required: true
type: string
secrets:
CI_BOT_PAT:
required: true
env:
REPOSITORY_USER: ${{ vars.CI_BOT_USERNAME }}
REPOSITORY_TOKEN: ${{ secrets.CI_BOT_PAT }}
jobs:
publish-catalog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: "v${{ inputs.PROJECT_VERSION }}"
token: ${{ secrets.CI_BOT_PAT }}
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ inputs.JAVA_VERSION }}
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew publish

View File

@@ -23,7 +23,7 @@ on:
type: string type: string
TYPE: TYPE:
default: '' default: ''
description: Type of release (service or artifact) description: Type of release (service, artifact, or catalog)
required: false required: false
type: string type: string
@@ -32,8 +32,8 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
has-changes: ${{ steps.has-changes.outputs.HAS_CHANGES }} has-changes: ${{ steps.has-changes.outputs.HAS_CHANGES }}
release-version: ${{ steps.release-version.outputs.RELEASE_VERSION }} project-name: ${{ steps.extract.outputs.PROJECT_NAME }}
project-name: ${{ steps.project-name.outputs.PROJECT_NAME }} release-version: ${{ steps.extract.outputs.RELEASE_VERSION }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
@@ -56,19 +56,19 @@ jobs:
run: | run: |
echo "No changes to release, failing..." echo "No changes to release, failing..."
exit 1 exit 1
- name: Extract application name from settings.gradle.kts - name: Extract project name and version
id: project-name id: extract
run: | run: |
# Extract project name
NAME=$(awk -F '=' '/^rootProject\.name/ { gsub(/[[:space:]]*/,"",$2); gsub(/"/,"",$2); print $2 }' settings.gradle.kts) NAME=$(awk -F '=' '/^rootProject\.name/ { gsub(/[[:space:]]*/,"",$2); gsub(/"/,"",$2); print $2 }' settings.gradle.kts)
if [ -z "$NAME" ]; then if [ -z "$NAME" ]; then
echo "Error: No application name found in settings.gradle.kts" >&2 echo "Error: No application name found in settings.gradle.kts" >&2
exit 1 exit 1
fi fi
echo "PROJECT_NAME=$NAME" >> $GITHUB_OUTPUT echo "PROJECT_NAME=$NAME" >> $GITHUB_OUTPUT
echo "Extracted application name: $NAME" echo "Extracted project name: $NAME"
- name: Extract version from gradle.properties
id: release-version # Extract version
run: |
VERSION=$(awk -F '=' '/^version[[:space:]]*=/{ gsub(/[[:space:]]*/,"",$2); sub(/-SNAPSHOT$/,"",$2); print $2 }' gradle.properties) VERSION=$(awk -F '=' '/^version[[:space:]]*=/{ gsub(/[[:space:]]*/,"",$2); sub(/-SNAPSHOT$/,"",$2); print $2 }' gradle.properties)
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then
echo "Error: No version found in gradle.properties" >&2 echo "Error: No version found in gradle.properties" >&2
@@ -76,26 +76,39 @@ jobs:
fi fi
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_OUTPUT echo "RELEASE_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted release version: $VERSION" echo "Extracted release version: $VERSION"
- name: Un-snapshot catalog versions
if: ${{ inputs.TYPE == 'catalog' }}
run: |
if [ -f hlaeja.versions.toml ]; then
sed -i -E 's/^(hlaeja[A-Za-z]+[[:space:]]*=[[:space:]]*")([0-9]+\.[0-9]+\.[0-9]+)-SNAPSHOT(")/\1\2\3/' hlaeja.versions.toml
if ! git diff --quiet hlaeja.versions.toml; then
git add hlaeja.versions.toml
echo "Catalog versions updated"
else
echo "No changes in catalog versions"
fi
fi
- name: Un-snapshot version and commit changes - name: Un-snapshot version and commit changes
run: | run: |
sed -i "s/\(version\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties sed -i "s/\(version\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties
sed -i "s/\(catalog\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties sed -i "s/\(catalog\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties
if ! git diff --exit-code --quiet -- "gradle.properties"; then if ! git diff --exit-code --quiet -- "gradle.properties"; then
git add gradle.properties git add gradle.properties
git commit -m "[RELEASE] - Release version: ${{ steps.release-version.outputs.RELEASE_VERSION }}" git commit -m "[RELEASE] - Release version: ${{ steps.extract.outputs.RELEASE_VERSION }}"
git push origin master git push origin master
else else
echo "No changes to commit" echo "No changes to commit"
fi fi
- name: Add release tag - name: Add release tag
run: | run: |
git_tag="v${{ steps.release-version.outputs.RELEASE_VERSION }}" git_tag="v${{ steps.extract.outputs.RELEASE_VERSION }}"
git tag -a "$git_tag" -m "Release version $git_tag" git tag -a "$git_tag" -m "Release version $git_tag"
git push origin "$git_tag" git push origin "$git_tag"
- name: Archive database files and commit changes - name: Archive database files and commit changes
if: ${{ inputs.DATABASE_FILES != '' }} if: ${{ inputs.DATABASE_FILES != '' }}
run: | run: |
version="${{ steps.release-version.outputs.RELEASE_VERSION }}" version="${{ steps.extract.outputs.RELEASE_VERSION }}"
type="${{ inputs.DATABASE_FILES }}" type="${{ inputs.DATABASE_FILES }}"
version_dir="${type}/v${version}" version_dir="${type}/v${version}"
if [ -d "$type" ] && [ -n "$(ls -A $type/*."$type" 2>/dev/null)" ]; then if [ -d "$type" ] && [ -n "$(ls -A $type/*."$type" 2>/dev/null)" ]; then
@@ -109,7 +122,7 @@ jobs:
fi fi
- name: Snapshot version and commit changes - name: Snapshot version and commit changes
run: | run: |
next_version=$(awk -F '.' '{print $1 "." $2+1 ".0"}' <<< "${{ steps.release-version.outputs.RELEASE_VERSION }}") next_version=$(awk -F '.' '{print $1 "." $2+1 ".0"}' <<< "${{ steps.extract.outputs.RELEASE_VERSION }}")
sed -i "s/\(version\s*=\s*\)[0-9.]*/\1${next_version}-SNAPSHOT/" gradle.properties sed -i "s/\(version\s*=\s*\)[0-9.]*/\1${next_version}-SNAPSHOT/" gradle.properties
echo "Bumped version to: ${next_version}-SNAPSHOT" echo "Bumped version to: ${next_version}-SNAPSHOT"
if ! git diff --exit-code --quiet -- "gradle.properties"; then if ! git diff --exit-code --quiet -- "gradle.properties"; then
@@ -141,3 +154,14 @@ jobs:
JAVA_VERSION: ${{ inputs.JAVA_VERSION }} JAVA_VERSION: ${{ inputs.JAVA_VERSION }}
PROJECT_NAME: ${{ needs.release.outputs.project-name }} PROJECT_NAME: ${{ needs.release.outputs.project-name }}
PROJECT_VERSION: ${{ needs.release.outputs.release-version }} PROJECT_VERSION: ${{ needs.release.outputs.release-version }}
finalise-publish-catalog:
needs: release
if: needs.release.outputs.has-changes == 'true' && inputs.TYPE == 'catalog'
uses: ./.github/workflows/publish-catalog.yml
secrets:
CI_BOT_PAT: ${{ secrets.CI_BOT_PAT }}
with:
JAVA_VERSION: ${{ inputs.JAVA_VERSION }}
PROJECT_NAME: ${{ needs.release.outputs.project-name }}
PROJECT_VERSION: ${{ needs.release.outputs.release-version }}

View File

@@ -5,8 +5,8 @@ GitHub actions [reusing workflows](https://docs.github.com/en/actions/using-work
## Actions secrets and variables ## Actions secrets and variables
### Secrets ### Secrets
- CI_BOT_PAT - CI_BOT_PAT = git_hub_token
### Variables ### Variables
- CI_BOT_USERNAME - CI_BOT_USERNAME = noreply@audapi.com
- CI_BOT_EMAIL - CI_BOT_EMAIL = audapi