-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (99 loc) · 4.35 KB
/
Copy pathjava-jar-release.yml
File metadata and controls
107 lines (99 loc) · 4.35 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
name: java-jar-release
# Reusable: publica un JAR Maven versionado.
# - mvn release:prepare -> quita el -SNAPSHOT, commitea, taggea vX.Y.Z y bumpea a la siguiente -SNAPSHOT
# - mvn release:perform -> checkout del tag y 'mvn deploy' a GitHub Packages (registry Maven)
# - sube el JAR al GitHub Release vX.Y.Z
# El caller aporta el trigger (push a main) y las permissions.
on:
workflow_call:
inputs:
java-version:
type: string
default: '25'
java-distribution:
type: string
default: 'temurin'
skip-tests:
type: boolean
default: false
changelog-path:
type: string
default: 'CHANGELOG.md' # de aca se extrae la seccion de la version -> descripcion del Release
generate-release-notes:
type: boolean
default: false # true -> ademas anexa las notas autogeneradas por GitHub (PRs/commits)
jobs:
publish:
name: Publish versioned JAR
runs-on: ubuntu-latest
permissions:
contents: write # push del bump/tag y creacion del GitHub Release
packages: write # deploy a GitHub Packages (Maven registry)
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-java@v5
with:
java-version: ${{ inputs.java-version }}
distribution: ${{ inputs.java-distribution }}
cache: maven
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN
- name: Setup git user and auth
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@identicum.com"
# release:perform hace un 'git clone' nuevo (target/checkout) que NO hereda las
# credenciales que persiste actions/checkout; inyectamos el token para github.com https.
git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release (prepare + perform)
run: mvn -B ${{ inputs.skip-tests && '-DskipTests' || '' }} clean release:prepare release:perform
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve released version and JAR path
id: artifact
run: |
VERSION=$(git describe --tags --abbrev=0) # ej: v1.0.0
NUM=${VERSION#v} # ej: 1.0.0
JAR=$(find target/checkout/target -maxdepth 1 -name '*.jar' \
! -name '*-sources.jar' ! -name '*-javadoc.jar' | head -n1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "num=$NUM" >> "$GITHUB_OUTPUT"
echo "jar=$JAR" >> "$GITHUB_OUTPUT"
# Extrae del CHANGELOG.md la seccion "## [<version>]" (hasta el proximo "## [" o "---"),
# recorta lineas en blanco sobrantes y la deja en RELEASE_NOTES.md como cuerpo del Release.
- name: Build release notes from CHANGELOG
run: |
CHANGELOG="${{ inputs.changelog-path }}"
NUM="${{ steps.artifact.outputs.num }}"
if [ -f "$CHANGELOG" ]; then
awk -v ver="$NUM" '
index($0, "## [" ver "]") == 1 { found=1; next }
found && (/^## \[/ || /^---[[:space:]]*$/) { exit }
found { buf[n++]=$0 }
END {
s=0; while (s<n && buf[s] ~ /^[[:space:]]*$/) s++
e=n-1; while (e>=s && buf[e] ~ /^[[:space:]]*$/) e--
for (i=s;i<=e;i++) print buf[i]
}
' "$CHANGELOG" > RELEASE_NOTES.md
fi
if [ ! -s RELEASE_NOTES.md ]; then
echo "Release ${{ steps.artifact.outputs.version }}" > RELEASE_NOTES.md
echo "_(sin entrada en $CHANGELOG para $NUM)_" >> RELEASE_NOTES.md
fi
echo "----- RELEASE_NOTES.md -----"; cat RELEASE_NOTES.md
- name: Upload JAR to GitHub Release
uses: softprops/action-gh-release@v3
with:
name: ${{ steps.artifact.outputs.version }}
tag_name: ${{ steps.artifact.outputs.version }}
body_path: RELEASE_NOTES.md
generate_release_notes: ${{ inputs.generate-release-notes }}
files: ${{ steps.artifact.outputs.jar }}