Skip to content

Commit 3ac905a

Browse files
authored
RAV-2958 - Setup Release workflow with package publication (#11)
Implement release process with package build and publication in the repository package space
1 parent 5b0eef9 commit 3ac905a

5 files changed

Lines changed: 186 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: Release Library
2+
run-name: Release ${{ github.ref_name != github.event.repository.default_branch && 'snapshot ' || '' }}${{ github.ref_name }} by @${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version_bump:
8+
description: 'Version bump type - only for main branch'
9+
required: true
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
default: patch
16+
17+
permissions:
18+
contents: write
19+
packages: write
20+
21+
jobs:
22+
release:
23+
name: Build and Release
24+
runs-on: ubuntu-latest
25+
outputs:
26+
version: ${{ steps.version.outputs.version }}
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v6
31+
with:
32+
fetch-depth: 1
33+
34+
- name: Set up JDK 17
35+
uses: actions/setup-java@v5
36+
with:
37+
java-version: '17'
38+
distribution: 'temurin'
39+
cache: 'maven'
40+
41+
- name: Configure Git
42+
run: |
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
46+
- name: Determine version
47+
id: version
48+
env:
49+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
50+
CURRENT_BRANCH: ${{ github.ref_name }}
51+
run: |
52+
# Get the latest tag
53+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
54+
echo "Latest tag: $LATEST_TAG"
55+
56+
# Remove 'v' prefix if present
57+
LATEST_VERSION=${LATEST_TAG#v}
58+
echo "Latest version: $LATEST_VERSION"
59+
60+
# Parse version components
61+
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION"
62+
63+
# Determine if we're on the default branch
64+
if [ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ]; then
65+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
66+
BUMP_TYPE="${{ inputs.version_bump }}"
67+
else
68+
BUMP_TYPE="patch"
69+
fi
70+
71+
case $BUMP_TYPE in
72+
major)
73+
MAJOR=$((MAJOR + 1))
74+
MINOR=0
75+
PATCH=0
76+
;;
77+
minor)
78+
MINOR=$((MINOR + 1))
79+
PATCH=0
80+
;;
81+
patch)
82+
PATCH=$((PATCH + 1))
83+
;;
84+
esac
85+
86+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
87+
IS_RELEASE=true
88+
else
89+
# Snapshot build - increment patch and add -SNAPSHOT
90+
PATCH=$((PATCH + 1))
91+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-SNAPSHOT"
92+
IS_RELEASE=false
93+
fi
94+
95+
echo "New version: $NEW_VERSION"
96+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
97+
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
98+
echo "bump_type=${BUMP_TYPE:-none}" >> $GITHUB_OUTPUT
99+
100+
- name: "Build and test (version: ${{ steps.version.outputs.version }})"
101+
env:
102+
VERSION: ${{ steps.version.outputs.version }}
103+
run: |
104+
mvn clean verify -B -Drevision=$VERSION
105+
106+
- name: Publish to GitHub Packages
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
GITHUB_ACTOR: ${{ github.actor }}
110+
VERSION: ${{ steps.version.outputs.version }}
111+
run: |
112+
mvn deploy -DskipTests -B -Drevision=$VERSION
113+
114+
- name: Create and push tag (release only)
115+
env:
116+
VERSION: ${{ steps.version.outputs.version }}
117+
if: steps.version.outputs.is_release == 'true'
118+
run: |
119+
VERSION="${{ steps.version.outputs.version }}"
120+
git tag -a "v$VERSION" -m "Release version $VERSION"
121+
git push origin "v$VERSION"
122+
123+
- name: Create GitHub Release (release only)
124+
if: steps.version.outputs.is_release == 'true'
125+
uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0
126+
with:
127+
tag: v${{ steps.version.outputs.version }}
128+
name: Release ${{ steps.version.outputs.version }}
129+
body: |
130+
## Release ${{ steps.version.outputs.version }}
131+
132+
### Changes
133+
This release was automatically generated.
134+
135+
### Maven Dependency
136+
```xml
137+
<dependency>
138+
<groupId>net.airvantage</groupId>
139+
<artifactId>proxy-socket-core</artifactId>
140+
<version>${{ steps.version.outputs.version }}</version>
141+
</dependency>
142+
```
143+
144+
### GitHub Packages
145+
To use this library from GitHub Packages, add the following repository to your `pom.xml`:
146+
```xml
147+
<repositories>
148+
<repository>
149+
<id>github</id>
150+
<url>https://maven.pkg.github.com/${{ github.repository }}</url>
151+
</repository>
152+
</repositories>
153+
```
154+
draft: false
155+
prerelease: false
156+
generateReleaseNotes: true
157+
158+
- name: Summary
159+
env:
160+
VERSION: ${{ steps.version.outputs.version }}
161+
if: always()
162+
run: |
163+
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
164+
echo "" >> $GITHUB_STEP_SUMMARY
165+
echo "- **Version**: $VERSION" >> $GITHUB_STEP_SUMMARY
166+
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
167+
echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
168+
echo "- **Repository**: https://github.com/${{ github.repository }}/packages" >> $GITHUB_STEP_SUMMARY

pom.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77

88
<groupId>net.airvantage</groupId>
99
<artifactId>proxy-socket-java</artifactId>
10-
<version>1.0.0-SNAPSHOT</version>
10+
<version>${revision}</version>
1111
<packaging>pom</packaging>
1212

1313
<description>ProxyProtocol Java implementation.</description>
1414

15+
<distributionManagement>
16+
<repository>
17+
<id>github</id>
18+
<name>GitHub Packages</name>
19+
<url>https://maven.pkg.github.com/${github.repository}</url>
20+
</repository>
21+
</distributionManagement>
22+
1523
<properties>
1624

25+
<!-- Version managed by CI/CD workflow -->
26+
<revision>0.0.0-SNAPSHOT</revision>
27+
28+
<!-- GitHub repository (format: owner/repo) -->
29+
<github.repository>airvantage/proxy-socket-java</github.repository>
30+
1731
<!-- Dependency versions -->
1832
<junit.version>5.10.3</junit.version>
1933
<guava.version>33.5.0-jre</guava.version>
@@ -79,7 +93,6 @@
7993
</execution>
8094
</executions>
8195
</plugin>
82-
8396
</plugins>
8497
</build>
8598
</project>

proxy-socket-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>net.airvantage</groupId>
88
<artifactId>proxy-socket-java</artifactId>
9-
<version>1.0.0-SNAPSHOT</version>
9+
<version>${revision}</version>
1010
</parent>
1111
<artifactId>proxy-socket-core</artifactId>
1212
<name>Proxy Protocol - Core</name>

proxy-socket-guava/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>net.airvantage</groupId>
88
<artifactId>proxy-socket-java</artifactId>
9-
<version>1.0.0-SNAPSHOT</version>
9+
<version>${revision}</version>
1010
</parent>
1111
<artifactId>proxy-socket-guava</artifactId>
1212
<name>Proxy Protocol - Guava Cache</name>

proxy-socket-udp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>net.airvantage</groupId>
88
<artifactId>proxy-socket-java</artifactId>
9-
<version>1.0.0-SNAPSHOT</version>
9+
<version>${revision}</version>
1010
</parent>
1111
<artifactId>proxy-socket-udp</artifactId>
1212
<name>Proxy Protocol - UDP</name>

0 commit comments

Comments
 (0)