Repository navigation
90 lines (79 loc) · 3.66 KB
/
Copy pathrelease.yml
File metadata and controls
90 lines (79 loc) · 3.66 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
# on:
# workflow_dispatch:
# inputs:
# releaseVersion:
# description: "Default version to use when preparing a release."
# required: true
# default: "X.Y.Z"
# developmentVersion:
# description: "Default version to use for new local working copy."
# required: true
# default: "X.Y.Z-SNAPSHOT"
on:
release:
types: [created] # Trigger on release creation
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: oracle
java-version: 21
# server-id: ossrh
# server-username: MAVEN_USERNAME
# server-password: MAVEN_PASSWORD
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Configure Git User
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
# - name: Maven Release
# run: mvn release:prepare release:perform -B -DreleaseVersion=${{ github.event.inputs.releaseVersion }} -DdevelopmentVersion=${{ github.event.inputs.developmentVersion }}
# env:
# CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
# CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}
- name: Set up GPG
run: |
export GPG_TTY=$(tty)
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
echo "${{ secrets.GPG_PUBLIC_KEY }}" | gpg --import
gpg --list-keys # Verify the keys are imported
- uses: s4u/maven-settings-action@v3.1.0
with:
servers: |
[{
"id": "ossrh",
"username": "${{ secrets.SONATYPE_USERNAME }}",
"password": "${{ secrets.SONATYPE_PASSWORD }}"
}]
- name: Build and Deploy
run: mvn --batch-mode deploy -DskipTests -Dmaven.test.skip=true -Drevision=${{ github.event.release.tag_name }} -P ci-execution
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_SECRET_KEYRING: ${{ secrets.GPG_SECRET_KEYRING }}
GPG_PUBLIC_KEYRING: ${{ secrets.GPG_PUBLIC_KEYRING }}
- name: Release to Maven Central (Manual trigger after staging)
if: github.event_name == 'release' && github.event.action == 'created'
uses: actions/github-script@v6
with:
script: |
const version = context.payload.release.tag_name.replace('v', ''); // Extract version
console.log(`Releasing version ${version}`);
// Add your logic to close and release the staging repository on Sonatype.
// This usually involves making a REST API call to Sonatype's Nexus.
// Example using curl (you'll need to install curl in the workflow if needed):
// run: |
// curl -u "${{ secrets.SONATYPE_USERNAME }}:${{ secrets.SONATYPE_PASSWORD }}" -X POST "https://oss.sonatype.org/service/local/staging/promote" -H "Content-Type: application/json" -d '{"stagedRepositoryIds":["your-staging-repo-id"],"description":"Release ${version}"}'
// Replace your-staging-repo-id with the actual ID. You might need to fetch this ID.
// Consult the Sonatype Nexus API documentation for the correct endpoint and payload.
console.log('Staging repository release triggered (manual action required)');