Skip to content

Commit 8ec1bb7

Browse files
authored
Automate package release (#347)
1 parent 351bdf1 commit 8ec1bb7

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

.github/get_staging_repository_id.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import base64
2+
import json
3+
import os
4+
import sys
5+
import urllib.request
6+
7+
username = os.environ.get('NEXUS_USERNAME')
8+
password = os.environ.get('NEXUS_PASSWORD')
9+
10+
def get(url, username, password):
11+
req = urllib.request.Request(url)
12+
base64_auth = base64.b64encode(bytes('{}:{}'.format(username, password),'ascii'))
13+
req.add_header("Authorization", "Basic {}".format(base64_auth.decode('utf-8')))
14+
req.add_header('Accept', 'application/json')
15+
with urllib.request.urlopen(req) as response:
16+
return response.read()
17+
18+
def getRepositories(username, password):
19+
return json.loads(get("https://oss.sonatype.org/service/local/staging/profile_repositories", username, password))
20+
21+
repositories = getRepositories(username, password).get("data")
22+
if len(repositories) != 1:
23+
sys.stderr.write("Zero or more than one staging repository. Exiting. Please execute the process manually.")
24+
exit(1)
25+
26+
repositoryId = repositories[0].get("repositoryId")
27+
print(repositoryId)
28+
29+

.github/workflows/release.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,21 @@ jobs:
8282
- name: Publish
8383
run: |
8484
./gradlew publish
85+
86+
finish-release:
87+
runs-on: ubuntu-latest
88+
needs: publish
89+
env:
90+
NEXUS_USERNAME: ${{ secrets.MAVEN_USERNAME }}
91+
NEXUS_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
92+
steps:
93+
- id: get_staging_repository_id
94+
name: Get staging repository id
95+
run: |
96+
echo "staging_repository_id=$(python3 .github/get_staging_repository_id.py)" >> $GITHUB_OUTPUT
97+
- name: Release
98+
uses: nexus-actions/release-nexus-staging-repo@main
99+
with:
100+
username: ${{ secrets.MAVEN_USERNAME }}
101+
password: ${{ secrets.MAVEN_PASSWORD }}
102+
staging_repository_id: ${{ steps.get_staging_repository_id.outputs.staging_repository_id }}

0 commit comments

Comments
 (0)