@@ -3,6 +3,11 @@ name: Release Version
33
44on :
55 workflow_dispatch :
6+ inputs :
7+ version :
8+ description : ' Custom version (optional)'
9+ required : false
10+ type : string
611 pull_request_target :
712 types :
813 - closed
@@ -14,123 +19,134 @@ on:
1419 - ' main'
1520
1621jobs :
17- deploy :
22+ release :
23+ if : github.repository_owner == 'guacsec'
1824 runs-on : ubuntu-latest
19- name : Deploy release
20- environment : staging
21- # only trigger the workflow on the base repository and if the merged branch name starts with release.
22- if : (github.repository_owner == 'guacsec' && github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') ) || (github.repository_owner == 'guacsec' && github.ref_name == 'main' && contains(github.event.commits[0].message, 'release/directly'))
23- outputs :
24- project_version : ${{ steps.project.outputs.version }}
25- last_release_tag : ${{ steps.last-release.outputs.tag-name }}
25+ permissions :
26+ contents : write
27+ pull-requests : write
28+ id-token : write
2629 steps :
27- - name : Checkout sources
28- uses : actions/checkout@v3
29- with :
30- ssh-key : ${{ secrets.GITHUB_TOKEN }}
31- fetch-depth : 0
32-
30+ - name : Checkout
31+ uses : actions/checkout@v5
3332
34- - name : Setup Java 17
35- uses : actions/setup-java@v4
33+ - name : Set up Java 17
34+ uses : actions/setup-java@v5
3635 with :
37- distribution : temurin
38- java-version : 17
39- cache : maven
36+ java-version : ' 17'
37+ distribution : ' temurin'
38+ cache : ' maven'
39+ gpg-private-key : ${{ secrets.GPG_PRIVATE_KEY }}
40+ gpg-passphrase : GPG_PASSPHRASE
41+ env :
42+ GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
4043
41- - name : create ssh agent
42- uses :
webfactory/[email protected] 43- with :
44- ssh-private-key : ${{ secrets.GITHUB_TOKEN }}
44+ - name : Import GPG key for Maven
45+ run : |
46+ mkdir -p ~/.gnupg
47+ echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
48+ env :
49+ GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
4550
4651 - name : Configure git
4752 run : |
4853 git config user.name "${{ github.actor }}"
4954 git config user.email "${{ github.actor }}@users.noreply.github.com"
5055
51-
5256 - name : get previous released annotated tag
5357 id : last-release
5458 run : |
5559 echo "tag-name=$(git describe | awk -F '-' '{print $1}')" >> "$GITHUB_OUTPUT"
5660
57- - name : Deploy release to GitHub
58- run : |
59- mvn release:prepare release:perform -B -ff
61+ - name : Set version
62+ if : github.event.inputs.version != ''
63+ run : mvn -B versions:set -DnewVersion=${{ github.event.inputs.version }} -DgenerateBackupPoms=false
6064
61- env :
62- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
65+ - name : Remove snapshot
66+ if : github.event.inputs.version == ''
67+ run : mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
6368
64- - name : Get pom version of released artifact
65- id : project
69+ - name : Get version
70+ id : get_version
6671 run : |
67- git checkout HEAD^ pom.xml
6872 echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
69- git restore pom.xml --staged --worktree
7073
74+ - name : Check if Maven artifact version exists
75+ id : check_maven
76+ run : |
77+ VERSION="${{ steps.get_version.outputs.version }}"
78+ GROUP_ID="io.github.guacsec"
79+ ARTIFACT_ID="trustify-da-java-client"
80+ echo "Checking if Maven artifact $GROUP_ID:$ARTIFACT_ID:$VERSION exists..."
81+
82+ # Check Maven Central for the artifact
83+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://repo1.maven.org/maven2/io/github/guacsec/trustify-da-java-client/$VERSION/trustify-da-java-client-$VERSION.pom")
84+ if [ "$HTTP_CODE" = "200" ]; then
85+ echo "maven_exists=true" >> $GITHUB_OUTPUT
86+ echo "Maven artifact $GROUP_ID:$ARTIFACT_ID:$VERSION already exists, skipping Maven publish"
87+ else
88+ echo "maven_exists=false" >> $GITHUB_OUTPUT
89+ echo "Maven artifact $GROUP_ID:$ARTIFACT_ID:$VERSION does not exist (HTTP $HTTP_CODE), will publish"
90+ fi
91+ continue-on-error : true
92+
93+ - name : Show artifact check results
94+ run : |
95+ echo "=== Artifact Check Results ==="
96+ echo "Maven artifact exists: ${{ steps.check_maven.outputs.maven_exists }}"
97+ echo "Will publish to Maven Central: ${{ steps.check_maven.outputs.maven_exists == 'false' }}"
7198
72- release :
73- runs-on : ubuntu-latest
74- name : Release
75- if : (github.repository_owner == 'guacsec' && startsWith(github.head_ref, 'release/')) || (github.repository_owner == 'guacsec' && github.ref_name == 'main' && contains(github.event.commits[0].message, 'release/directly'))
76- environment : staging
77- needs : deploy
78- steps :
99+ - name : Compute Maven profiles
100+ id : compute_profiles
101+ run : |
102+ PROFILES="gpg-sign"
103+ if [ "${{ steps.check_maven.outputs.maven_exists }}" = "false" ]; then
104+ PROFILES="${PROFILES},publish-maven"
105+ fi
106+ echo "profiles=$PROFILES" >> $GITHUB_OUTPUT
107+
108+ - name : Build and publish to Maven Central
109+ if : steps.check_maven.outputs.maven_exists == 'false'
110+ run : |
111+ mvn -B deploy -P${{ steps.compute_profiles.outputs.profiles }} --settings .github/workflows/maven/settings.xml
79112
80- - name : Create release notes for ${{ needs.deploy.outputs.project_version }} release
81- uses : actions/github-script@v7
82- id : release-notes
83- with :
84- github-token : ${{ secrets.GITHUB_TOKEN }}
85- script : |
86- const repo_name = context.payload.repository.full_name
87- const response = await github.request('POST /repos/' + repo_name + '/releases' + '/generate-notes', {
88- tag_name: '${{ needs.deploy.outputs.project_version }}',
89- previous_tag_name: '${{ needs.deploy.outputs.last_release_tag }}'
90- })
91- return response.data.body
92-
93- - name : Create new ${{ needs.deploy.outputs.project_version }} release
94- uses : actions/github-script@v7
95- with :
96- github-token : ${{ secrets.GITHUB_TOKEN }}
97- script : |
98- const repo_name = context.payload.repository.full_name
99- const response = await github.request('POST /repos/' + repo_name + '/releases', {
100- tag_name: '${{ needs.deploy.outputs.project_version }}',
101- name: '${{ needs.deploy.outputs.project_version }}',
102- body: ${{ steps.release-notes.outputs.result }},
103- draft: false,
104- prerelease: false,
105- make_latest: 'true'
106- })
107-
108- - name : Checkout sources
109- uses : actions/checkout@v3
110- with :
111- ssh-key : ${{ secrets.GITHUB_TOKEN }}
112- fetch-depth : 0
113+ env :
114+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
115+ MAVEN_GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
116+ MAVEN_CENTRAL_USERNAME : ${{ secrets.MAVEN_CENTRAL_USERNAME }}
117+ MAVEN_CENTRAL_TOKEN : ${{ secrets.MAVEN_CENTRAL_TOKEN }}
113118
114- - name : Configure git
119+ - name : Skip publishing - artifact already exists
120+ if : steps.check_maven.outputs.maven_exists == 'true'
115121 run : |
116- git config user.name "${{ github.actor }} "
117- git config user.email " ${{ github.actor }}@users.noreply.github.com "
122+ echo "Maven artifact already exists, skipping publish step "
123+ echo "Maven exists: ${{ steps.check_maven.outputs.maven_exists }}"
118124
119- - name : Get pom version of new snapshot artifact
120- id : project_snapshot
121- run : |
122- git pull
123- echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
125+ - name : Create Release
126+ id : create_release
127+ uses : softprops/action-gh-release@v1
128+ with :
129+ name : Release ${{ github.event.inputs.version || steps.get_version.outputs.version }}
130+ tag_name : v${{ github.event.inputs.version || steps.get_version.outputs.version }}
131+ generate_release_notes : true
132+ env :
133+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124134
135+ - name : Update to next version
136+ if : success()
137+ run : |
138+ mvn -B release:update-versions
139+ # Run the phase that triggers README.md update
140+ mvn -B validate
125141
126- - name : Update readme usage section
127- run : >
128- sed -i
129- 's/<version>.*<\/version>/<version>${{ steps.project_snapshot.outputs.version }}<\/version>/g'
130- README.md
142+ - name : Create Pull Request with next version
143+ id : cpr
144+ uses : peter-evans/create-pull-request@v5
145+ with :
146+ commit-message : " build(release): update to next development version"
147+ branch : chore/bump-version
148+ title : " chore: bump to next development version"
149+ signoff : true
150+ body : |
151+ This PR updates the project to the next development version after the release.
131152
132- - name : Push modifications
133- run : |
134- git add README.md
135- git commit -m "docs: updated usage section with version ${{ steps.project_snapshot.outputs.version }} [skip ci]"
136- git push
0 commit comments