Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ============================================================================
# SNAPSHOT BUILD & CHANGELOG ACCUMULATION
# ============================================================================
#
# PURPOSE:
# --------
# Builds SNAPSHOT artifacts and accumulates changelog entries when PRs are
# merged to main. Does NOT create version tags - use cut-release.yml for that.
#
# HOW IT WORKS:
# -------------
# 1. Triggered when a PR is merged to main
# 2. Builds SNAPSHOT artifacts (version calculated from git-semver-plugin)
# 3. Updates CHANGELOG.md with new commits under "Unreleased" section
# 4. Commits changelog updates back to main
#
# VERSIONING:
# -----------
# Uses git-semver-plugin to calculate version from conventional commits:
# - fix: → patch bump
# - feat: → minor bump
# - feat!: or BREAKING CHANGE → major bump
#
# Version remains X.Y.Z-SNAPSHOT until cut-release.yml is triggered.
#
# RELATED WORKFLOWS:
# ------------------
# - build-and-publish.yml: Builds and publishes Docker images
# - cut-release.yml: Creates version tags and releases (manual)
# - release-publish.yml: Official ASF releases (manual, after vote)

name: Snapshot Build

on:
push:
branches:
- main

permissions:
contents: write

env:
JAVA_VERSION: '25'
JAVA_DISTRIBUTION: 'temurin'

jobs:
snapshot:
name: Build Snapshot & Update Changelog
runs-on: ubuntu-latest
# Skip if this is a release commit or changelog update
if: "!startsWith(github.event.head_commit.message, 'chore(release):') && !startsWith(github.event.head_commit.message, 'chore(changelog):')"

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: 'gradle'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Calculate version
id: version
run: |
VERSION=$(./gradlew printVersion --quiet)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current SNAPSHOT version: $VERSION"

- name: Build SNAPSHOT
run: ./gradlew build

- name: Generate changelog entries
id: changelog
run: |
# Get changelog from git-semver-plugin
CHANGELOG_CONTENT=$(./gradlew printChangeLog --quiet)

# Create or update CHANGELOG.md with Unreleased section
if [ -f CHANGELOG.md ]; then
# Check if Unreleased section exists
if grep -q "## \[Unreleased\]" CHANGELOG.md; then
# Replace existing Unreleased section
# Create temp file with new unreleased content
cat > CHANGELOG_NEW.md << 'HEADER'
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

HEADER
echo "$CHANGELOG_CONTENT" >> CHANGELOG_NEW.md
echo "" >> CHANGELOG_NEW.md
# Append everything after the old Unreleased section (previous releases)
sed -n '/^## \[[0-9]/,$p' CHANGELOG.md >> CHANGELOG_NEW.md 2>/dev/null || true
mv CHANGELOG_NEW.md CHANGELOG.md
else
# No Unreleased section, add it at the top
cat > CHANGELOG_NEW.md << 'HEADER'
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

HEADER
echo "$CHANGELOG_CONTENT" >> CHANGELOG_NEW.md
echo "" >> CHANGELOG_NEW.md
# Append existing content (skip any header)
tail -n +2 CHANGELOG.md >> CHANGELOG_NEW.md 2>/dev/null || true
mv CHANGELOG_NEW.md CHANGELOG.md
fi
else
# Create new CHANGELOG.md
cat > CHANGELOG.md << 'HEADER'
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

HEADER
echo "$CHANGELOG_CONTENT" >> CHANGELOG.md
fi

- name: Check for changelog changes
id: changes
run: |
if git diff --quiet CHANGELOG.md 2>/dev/null; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi

- name: Commit changelog updates
if: steps.changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore(changelog): update unreleased changes"
git push origin main

- name: Summary
run: |
echo "### Snapshot Build Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Changelog:** Updated with latest commits" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To create a release, run the **Cut Release** workflow." >> $GITHUB_STEP_SUMMARY
18 changes: 12 additions & 6 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ jobs:
runs-on: ubuntu-latest

steps:
# Checkout the repository code
# Checkout the repository code with full history
# Full history is required for git-semver-plugin to calculate version
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

# Set up Java environment using centralized configuration
# See .github/actions/setup-java/action.yml to update Java version
Expand Down Expand Up @@ -207,9 +210,12 @@ jobs:
packages: write

steps:
# Checkout the repository code
# Checkout the repository code with full history
# Full history is required for git-semver-plugin to calculate version
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

# Set up Java environment using centralized configuration
# See .github/actions/setup-java/action.yml to update Java version
Expand All @@ -218,14 +224,14 @@ jobs:

# Extract version and determine image tags
# Outputs:
# - version: Project version from build.gradle.kts
# - version: Project version from git-semver-plugin
# - tags: Comma-separated list of Docker tags to apply
# - is_release: Whether this is a release build (from version tag)
- name: Extract metadata
id: meta
run: |
# Get version from build.gradle.kts
VERSION=$(grep '^version = ' build.gradle.kts | sed 's/version = "\(.*\)"/\1/')
# Get version from git-semver-plugin (derived from git tags + commits)
VERSION=$(./gradlew printVersion --quiet)
echo "version=$VERSION" >> $GITHUB_OUTPUT

# Determine image tags based on trigger type
Expand All @@ -235,7 +241,7 @@ jobs:
echo "tags=$TAG_VERSION,latest" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
else
# For main branch, append short commit SHA for traceability
# For main branch, use SNAPSHOT version with short commit SHA
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "tags=$VERSION-$SHORT_SHA,latest" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
Expand Down
Loading