Skip to content

Build and Release

Build and Release #5

Workflow file for this run

name: Build and Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. 1.0.0)'
required: true
type: string
env:
JAVA_VERSION: '17'
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
jobs:
verify-version:
runs-on: ubuntu-22.04
permissions:
contents: write
outputs:
version: ${{ github.event.inputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Validate version format
run: |
if [[ ! ${{ github.event.inputs.version }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Must be in format x.y.z"
exit 1
fi
- name: Extract current version
id: current_version
run: |
echo "version=$(grep -E "^[[:space:]]*version[[:space:]]*=[[:space:]]*[^[:space:]]" version.properties | head -n 1 | cut -d'=' -f2 | tr -d '[:space:]' | sed 's/-snapshot$//')" >> $GITHUB_OUTPUT
- name: Compare versions
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
NEW_VERSION="${{ github.event.inputs.version }}"
if ! dpkg --compare-versions "$NEW_VERSION" ge "$CURRENT_VERSION"; then
echo "[error] New version ($NEW_VERSION) must be greater than or equal to current version ($CURRENT_VERSION)"
exit 1
fi
- name: Set version
id: set_version
run: echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
- name: Update version.properties version
run: |
VERSION="${{ github.event.inputs.version }}"
if ! sed -i "s/^version=.*/version=$VERSION/" version.properties; then
echo "[error] Failed to update version.properties"
exit 1
fi
if git diff --quiet version.properties; then
echo "[info] No changes to version.properties"
else
git add version.properties
git commit -m "chore: update version to $VERSION"
git push || {
echo "[error] Failed to push version update"
exit 1
}
fi
- name: Create and push tag
run: |
TAG_NAME="v${{ steps.set_version.outputs.version }}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "[warning] Tag $TAG_NAME already exists, skipping tag creation"
else
echo "Creating new tag $TAG_NAME"
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
git push origin "$TAG_NAME" || {
echo "[error] Failed to push tag $TAG_NAME"
exit 1
}
fi
- name: Verify version match
run: |
PKG_VERSION=$(grep -E "^[[:space:]]*version[[:space:]]*=[[:space:]]*[^[:space:]]" version.properties | head -n 1 | cut -d'=' -f2 | tr -d '[:space:]')
if [ "${{ github.event.inputs.version }}" != "$PKG_VERSION" ]; then
echo "Version mismatch: Input version (${{ github.event.inputs.version }}) does not match version.properties version ($PKG_VERSION)"
exit 1
fi
build-jar:
needs: verify-version
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build Processor JAR
run: |
./gradlew clean bootJar -Pversion=${{ needs.verify-version.outputs.version }} --stacktrace || {
echo "[error] Build failed. See below for detailed logs:"
find . -name "*.log" -type f -exec sh -c 'echo "=== $1 ==="; cat "$1"' _ {} \;
exit 1
}
- name: Prepare distribution
run: |
cp "build/libs/thymelab-processor-${{ needs.verify-version.outputs.version }}.jar" ./
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: jar
path: thymelab-processor-${{ needs.verify-version.outputs.version }}.jar
retention-days: 5
package-examples:
needs: verify-version
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
- name: Create examples archive
run: |
if [ ! -d "examples" ] || [ -z "$(ls -A examples)" ]; then
echo "[error] Examples directory not found or empty"
exit 1
fi
zip -r "thymelab-examples-${{ needs.verify-version.outputs.version }}.zip" examples/
- name: Upload examples artifact
uses: actions/upload-artifact@v4
with:
name: examples
path: thymelab-examples-*.zip
retention-days: 5
create-release:
needs: [verify-version, build-jar, package-examples]
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout master
- name: Get Changes
id: get_changes
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
CHANGES=$(git log --pretty=format:"- %s")
else
CHANGES=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD)
fi
echo "changes<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Download JAR artifact
uses: actions/download-artifact@v4
with:
name: jar
path: release-files
- name: Download examples artifact
uses: actions/download-artifact@v4
with:
name: examples
path: release-files
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: ThymeLab v${{ needs.verify-version.outputs.version }}
body: |
## ThymeLab v${{ needs.verify-version.outputs.version }}
### 📥 Downloads
- **📦 thymelab-processor-${{ needs.verify-version.outputs.version }}.jar**: Standalone processor JAR
- **📚 thymelab-examples-${{ needs.verify-version.outputs.version }}.zip**: Template examples and resources
### 🚀 Quick Start
```bash
java -jar thymelab-processor-${{ needs.verify-version.outputs.version }}.jar \
-Dserver.port=8080 \
-Dlogging.level.com.github.thkwag.thymelab=INFO \
-Dwatch.directory.templates=/path/to/templates \
-Dwatch.directory.thymeleaf-data=/path/to/thymelab/data \
-Dwatch.directory.static=/path/to/static
```
### 📌 Note
The examples package contains template examples that can be used with ThymeLab Processor.
### 📝 What's Changed
${{ steps.get_changes.outputs.changes }}
files: |
release-files/thymelab-processor-${{ needs.verify-version.outputs.version }}.jar
release-files/thymelab-examples-${{ needs.verify-version.outputs.version }}.zip
draft: false
prerelease: false
generate_release_notes: true
tag_name: v${{ needs.verify-version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update to next snapshot version
run: |
CURRENT_VERSION="${{ needs.verify-version.outputs.version }}"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$NF = $NF + 1;} 1' OFS=.)-snapshot
if ! sed -i "s/^version=.*/version=$NEW_VERSION/" version.properties; then
echo "[error] Failed to update version.properties"
exit 1
fi
git add version.properties
git commit -m "chore: update version to $NEW_VERSION"
git push || {
echo "[error] Failed to push changes"
exit 1
}