-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (138 loc) · 5.46 KB
/
release.yml
File metadata and controls
159 lines (138 loc) · 5.46 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
name: Release Publish
on:
pull_request:
types: [closed]
branches: [main]
concurrency:
group: release-publish
cancel-in-progress: false
jobs:
release:
name: Create & Publish Release
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout (full history & tags)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch all tags
run: |
git fetch --tags --quiet
echo "Existing tags:"
git tag -l | sort -V | tail -n 20 || true
- name: Derive release version (with Hotfix fallback)
id: version
shell: bash
run: |
set -euo pipefail
RAW_VERSION=$(grep -m1 '<version>' pom.xml | sed -E 's/.*<version>([^<]+)<\/version>.*/\1/')
if [[ -z "${RAW_VERSION}" ]]; then
echo "Could not extract version from pom.xml"
exit 1
fi
# Strip -SNAPSHOT suffix if present.
BASE_VERSION="${RAW_VERSION%-SNAPSHOT}"
echo "Base version from pom: ${BASE_VERSION}"
# Determine if base version tag already exists.
if git rev-parse -q --verify "refs/tags/${BASE_VERSION}" >/dev/null; then
echo "Tag ${BASE_VERSION} already exists. Deriving Hotfix version..."
i=1
while git rev-parse -q --verify "refs/tags/${BASE_VERSION}-Hotfix-${i}" >/dev/null; do
i=$((i+1))
done
FINAL_VERSION="${BASE_VERSION}-Hotfix-${i}"
echo "Using hotfix version: ${FINAL_VERSION}"
echo "hotfix=true" >> "$GITHUB_OUTPUT"
echo "hotfix_index=${i}" >> "$GITHUB_OUTPUT"
else
FINAL_VERSION="${BASE_VERSION}"
echo "Using base version: ${FINAL_VERSION}"
echo "hotfix=false" >> "$GITHUB_OUTPUT"
fi
echo "raw_version=${RAW_VERSION}" >> "$GITHUB_OUTPUT"
echo "base_version=${BASE_VERSION}" >> "$GITHUB_OUTPUT"
echo "version=${FINAL_VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up JDK 23 (generate settings.xml)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '23'
server-id: github
settings-path: ${{ github.workspace }}
- name: Cache Maven
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-${{ runner.os }}-
- name: Set release version in pom.xml
run: |
set -e
mvn -B -s $GITHUB_WORKSPACE/settings.xml versions:set -DnewVersion="${{ steps.version.outputs.version }}" -DgenerateBackupPoms=false
echo "Effective pom version line:"
grep -m1 '<version>' pom.xml
- name: Commit version change (if modified)
run: |
set -e
if ! git diff --quiet; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add pom.xml
git commit -m "chore(release): set version ${{ steps.version.outputs.version }}"
git push origin HEAD:main
else
echo "No changes to commit."
fi
- name: Build (package)
run: mvn -B -s $GITHUB_WORKSPACE/settings.xml -DskipTests -Pwith-shade package
- name: Deploy Release to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn -B -s $GITHUB_WORKSPACE/settings.xml -DskipTests deploy
- name: Create & Push Git Tag
run: |
set -e
TAG="${{ steps.version.outputs.version }}"
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
echo "Tag ${TAG} already exists unexpectedly (race condition?)."
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "${TAG}" -m "Release ${TAG}"
git push origin "${TAG}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: "SingularityLib ${{ steps.version.outputs.version }}"
generate_release_notes: true
files: |
`target/*.jar`
- name: Summary
run: |
echo "Published release ${{ steps.version.outputs.version }}"
echo "Hotfix: ${{ steps.version.outputs.hotfix }}"
- name: Bump to next snapshot
if: always()
run: |
set -e
CURRENT="${{ steps.version.outputs.version }}"
# Basic semver increment of patch for next snapshot (ignoring hotfix tags)
CORE="${CURRENT%%-Hotfix-*}"
IFS='.' read -r MA MI PA <<< "$CORE"
NEXT_PATCH=$((PA + 1))
NEXT_VERSION="${MA}.${MI}.${NEXT_PATCH}-SNAPSHOT"
mvn -B versions:set -DnewVersion="${NEXT_VERSION}" -DgenerateBackupPoms=false
if ! git diff --quiet; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add pom.xml
git commit -m "chore: prepare next development iteration ${NEXT_VERSION}"
git push origin HEAD:main
fi