Skip to content

Commit bc56b56

Browse files
committed
tweakrs
1 parent 5b0eef9 commit bc56b56

5 files changed

Lines changed: 189 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
push:
6+
workflow_dispatch:
7+
inputs:
8+
version_bump:
9+
description: 'Version bump type - only for main branch'
10+
required: true
11+
type: choice
12+
options:
13+
- patch
14+
- minor
15+
- major
16+
default: patch
17+
18+
permissions:
19+
contents: write
20+
packages: write
21+
22+
jobs:
23+
release:
24+
name: Build and Release
25+
runs-on: ubuntu-latest
26+
outputs:
27+
version: ${{ steps.version.outputs.version }}
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 1
34+
35+
- name: Set up JDK 17
36+
uses: actions/setup-java@v4
37+
with:
38+
java-version: '17'
39+
distribution: 'temurin'
40+
cache: 'maven'
41+
42+
- name: Configure Git
43+
run: |
44+
git config user.name "github-actions[bot]"
45+
git config user.email "github-actions[bot]@users.noreply.github.com"
46+
47+
- name: Determine version
48+
id: version
49+
env:
50+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
51+
CURRENT_BRANCH: ${{ github.ref_name }}
52+
run: |
53+
# Get the latest tag
54+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
55+
echo "Latest tag: $LATEST_TAG"
56+
57+
# Remove 'v' prefix if present
58+
LATEST_VERSION=${LATEST_TAG#v}
59+
echo "Latest version: $LATEST_VERSION"
60+
61+
# Parse version components
62+
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION"
63+
64+
# Determine if we're on the default branch
65+
if [ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ]; then
66+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
67+
BUMP_TYPE="${{ inputs.version_bump }}"
68+
else
69+
BUMP_TYPE="patch"
70+
fi
71+
72+
case $BUMP_TYPE in
73+
major)
74+
MAJOR=$((MAJOR + 1))
75+
MINOR=0
76+
PATCH=0
77+
;;
78+
minor)
79+
MINOR=$((MINOR + 1))
80+
PATCH=0
81+
;;
82+
patch)
83+
PATCH=$((PATCH + 1))
84+
;;
85+
esac
86+
87+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
88+
IS_RELEASE=true
89+
else
90+
# Snapshot build - increment patch and add -SNAPSHOT
91+
PATCH=$((PATCH + 1))
92+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-SNAPSHOT"
93+
IS_RELEASE=false
94+
fi
95+
96+
echo "New version: $NEW_VERSION"
97+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
98+
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
99+
echo "bump_type=${BUMP_TYPE:-none}" >> $GITHUB_OUTPUT
100+
101+
- name: "Build and test (version: ${{ steps.version.outputs.version }})"
102+
env:
103+
VERSION: ${{ steps.version.outputs.version }}
104+
run: |
105+
mvn clean verify -B -Drevision=$VERSION
106+
107+
- name: Publish to GitHub Packages
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
GITHUB_ACTOR: ${{ github.actor }}
111+
VERSION: ${{ steps.version.outputs.version }}
112+
run: |
113+
mvn deploy -DskipTests -B -Drevision=$VERSION
114+
115+
- name: Create and push tag (release only)
116+
env:
117+
VERSION: ${{ steps.version.outputs.version }}
118+
if: steps.version.outputs.is_release == 'true'
119+
run: |
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@2c591bcc8eff11a27a959b7bcf72fddf9e1ed2e8 # v1.14.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+
notify:
159+
name: Notify
160+
needs: release
161+
runs-on: ubuntu-latest
162+
if: always()
163+
steps:
164+
- name: Summary
165+
run: |
166+
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
167+
echo "" >> $GITHUB_STEP_SUMMARY
168+
echo "- **Version**: ${{ needs.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
169+
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
170+
echo "- **Status**: ${{ needs.release.result }}" >> $GITHUB_STEP_SUMMARY
171+
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)