Skip to content
Merged
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
168 changes: 168 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Release Library
run-name: Release ${{ github.ref_name != github.event.repository.default_branch && 'snapshot ' || '' }}${{ github.ref_name }} by @${{ github.actor }}

on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type - only for main branch'
required: true
type: choice
options:
- patch
- minor
- major
default: patch

permissions:
contents: write
packages: write

jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 1

- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Determine version
id: version
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
CURRENT_BRANCH: ${{ github.ref_name }}
run: |
# Get the latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"

# Remove 'v' prefix if present
LATEST_VERSION=${LATEST_TAG#v}
echo "Latest version: $LATEST_VERSION"

# Parse version components
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION"

# Determine if we're on the default branch
if [ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ]; then
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
BUMP_TYPE="${{ inputs.version_bump }}"
else
BUMP_TYPE="patch"
fi

case $BUMP_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac

NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
IS_RELEASE=true
else
# Snapshot build - increment patch and add -SNAPSHOT
PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-SNAPSHOT"
IS_RELEASE=false
fi

echo "New version: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
echo "bump_type=${BUMP_TYPE:-none}" >> $GITHUB_OUTPUT

- name: "Build and test (version: ${{ steps.version.outputs.version }})"
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
mvn clean verify -B -Drevision=$VERSION

- name: Publish to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
VERSION: ${{ steps.version.outputs.version }}
run: |
mvn deploy -DskipTests -B -Drevision=$VERSION

- name: Create and push tag (release only)
env:
VERSION: ${{ steps.version.outputs.version }}
if: steps.version.outputs.is_release == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"
git tag -a "v$VERSION" -m "Release version $VERSION"
git push origin "v$VERSION"

- name: Create GitHub Release (release only)
if: steps.version.outputs.is_release == 'true'
uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0
with:
tag: v${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
body: |
## Release ${{ steps.version.outputs.version }}

### Changes
This release was automatically generated.

### Maven Dependency
```xml
<dependency>
<groupId>net.airvantage</groupId>
<artifactId>proxy-socket-core</artifactId>
<version>${{ steps.version.outputs.version }}</version>
</dependency>
```

### GitHub Packages
To use this library from GitHub Packages, add the following repository to your `pom.xml`:
```xml
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/${{ github.repository }}</url>
</repository>
</repositories>
```
draft: false
prerelease: false
generateReleaseNotes: true

- name: Summary
env:
VERSION: ${{ steps.version.outputs.version }}
if: always()
run: |
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: $VERSION" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
echo "- **Repository**: https://github.com/${{ github.repository }}/packages" >> $GITHUB_STEP_SUMMARY
17 changes: 15 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@

<groupId>net.airvantage</groupId>
<artifactId>proxy-socket-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>${revision}</version>
<packaging>pom</packaging>

<description>ProxyProtocol Java implementation.</description>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/${github.repository}</url>
</repository>
</distributionManagement>

<properties>

<!-- Version managed by CI/CD workflow -->
<revision>0.0.0-SNAPSHOT</revision>

<!-- GitHub repository (format: owner/repo) -->
<github.repository>airvantage/proxy-socket-java</github.repository>

<!-- Dependency versions -->
<junit.version>5.10.3</junit.version>
<guava.version>33.5.0-jre</guava.version>
Expand Down Expand Up @@ -79,7 +93,6 @@
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion proxy-socket-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.airvantage</groupId>
<artifactId>proxy-socket-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>${revision}</version>
</parent>
<artifactId>proxy-socket-core</artifactId>
<name>Proxy Protocol - Core</name>
Expand Down
2 changes: 1 addition & 1 deletion proxy-socket-guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.airvantage</groupId>
<artifactId>proxy-socket-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>${revision}</version>
</parent>
<artifactId>proxy-socket-guava</artifactId>
<name>Proxy Protocol - Guava Cache</name>
Expand Down
2 changes: 1 addition & 1 deletion proxy-socket-udp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.airvantage</groupId>
<artifactId>proxy-socket-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>${revision}</version>
</parent>
<artifactId>proxy-socket-udp</artifactId>
<name>Proxy Protocol - UDP</name>
Expand Down
Loading