1- name : Snapshot Deploy (Central + GitHub)
1+ name : Publish SNAPSHOT
22
33on :
44 push :
@@ -10,60 +10,54 @@ jobs:
1010 permissions :
1111 contents : read
1212 packages : write
13+
1314 steps :
1415 - uses : actions/checkout@v4
1516
16- - name : Read version
17- id : v
17+ - name : Extract version
18+ id : version
1819 run : |
19- VER=$(grep -m1 '<version>' pom.xml | sed -E 's/.*<version>([^<]+)<\/version>.*/\1/')
20- echo "version=$VER" >> $GITHUB_OUTPUT
21- if [[ "$VER" == *-SNAPSHOT ]]; then echo "deploy=true" >> $GITHUB_OUTPUT; else echo "deploy=false" >> $GITHUB_OUTPUT; fi
22-
23- - name : Abort (not SNAPSHOT)
24- if : steps.v.outputs.deploy != 'true'
25- run : echo "Version ${{ steps.v.outputs.version }} not snapshot."
26-
27- - name : Setup Java
28- if : steps.v.outputs.deploy == 'true'
20+ VERSION=$(grep -m1 '<version>' pom.xml | sed -E 's/.*<version>([^<]+)<\/version>.*/\1/')
21+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
22+ if [[ "$VERSION" == *-SNAPSHOT ]]; then
23+ echo "deploy=true" >> "$GITHUB_OUTPUT"
24+ else
25+ echo "deploy=false" >> "$GITHUB_OUTPUT"
26+ fi
27+
28+ - name : Abort (not a SNAPSHOT)
29+ if : steps.version.outputs.deploy != 'true'
30+ run : echo "Version ${{ steps.version.outputs.version }} is not a SNAPSHOT. Skipping deploy."
31+
32+ - name : Set up JDK 23 (generate settings.xml)
33+ if : steps.version.outputs.deploy == 'true'
2934 uses : actions/setup-java@v4
3035 with :
3136 distribution : temurin
3237 java-version : ' 23'
38+ server-id : github
39+ settings-path : ${{ github.workspace }}
3340
34- - name : Write settings.xml
35- if : steps.v.outputs.deploy == 'true'
36- env :
37- SONATYPE_USERNAME : ${{ secrets.SONATYPE_USERNAME }}
38- SONATYPE_PASSWORD : ${{ secrets.SONATYPE_PASSWORD }}
39- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
40- run : |
41- mkdir -p ~/.m2
42- cat > ~/.m2/settings.xml <<'EOF'
43- <settings>
44- <servers>
45- <server>
46- <id>sonatype</id>
47- <username>${env.SONATYPE_USERNAME}</username>
48- <password>${env.SONATYPE_PASSWORD}</password>
49- </server>
50- <server>
51- <id>github</id>
52- <username>${env.GITHUB_ACTOR}</username>
53- <password>${env.GITHUB_TOKEN}</password>
54- </server>
55- </servers>
56- </settings>
57- EOF
58- sed 's/<password>.*<\/password>/<password>***<\/password>/' ~/.m2/settings.xml
41+ - name : Cache Maven
42+ if : steps.version.outputs.deploy == 'true'
43+ uses : actions/cache@v4
44+ with :
45+ path : ~/.m2/repository
46+ key : maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
47+ restore-keys : |
48+ maven-${{ runner.os }}-
5949
60- - name : Deploy Snapshot to Sonatype
61- if : steps.v .outputs.deploy == 'true'
62- run : mvn -B -DskipTests deploy
50+ - name : Build (package)
51+ if : steps.version .outputs.deploy == 'true'
52+ run : mvn -B -s $GITHUB_WORKSPACE/settings.xml package
6353
64- - name : Deploy Snapshot to GitHub Packages
65- if : steps.v.outputs.deploy == 'true'
66- run : mvn -B -DskipTests -Pgithub -Dgpg.skip=true deploy
54+ - name : Deploy SNAPSHOT
55+ if : steps.version.outputs.deploy == 'true'
56+ env :
57+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
58+ run : mvn -B -s $GITHUB_WORKSPACE/settings.xml -DskipTests deploy
6759
6860 - name : Summary
69- run : echo "Snapshot ${{ steps.v.outputs.version }} deployed."
61+ run : |
62+ echo "Version: ${{ steps.version.outputs.version }}"
63+ echo "Deployed: ${{ steps.version.outputs.deploy }}"
0 commit comments