-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (147 loc) · 5.4 KB
/
release.yml
File metadata and controls
168 lines (147 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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: 0 # required to get all tags
- 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