Skip to content

Commit 86507fe

Browse files
sonar & release flows
1 parent 8d19069 commit 86507fe

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

.github/workflows/release.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Publish RELEASE to Maven Central
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up JDK
20+
uses: actions/setup-java@v4
21+
with:
22+
distribution: 'temurin'
23+
java-version: '21'
24+
server-id: central
25+
server-username: MAVEN_USERNAME
26+
server-password: MAVEN_PASSWORD
27+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
28+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
29+
30+
- name: Verify tag matches pom.xml version
31+
run: |
32+
TAG_NAME=${GITHUB_REF_NAME} # e.g., v1.2.3
33+
RELEASE_VERSION=${TAG_NAME#v} # remove leading 'v'
34+
POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
35+
echo "Git tag: $RELEASE_VERSION"
36+
echo "Pom version: $POM_VERSION"
37+
38+
if [ "$RELEASE_VERSION" != "$POM_VERSION" ]; then
39+
echo "Error: Git tag ($RELEASE_VERSION) does not match pom.xml version ($POM_VERSION)"
40+
exit 1
41+
fi
42+
shell: bash
43+
44+
- name: Set up Git
45+
run: |
46+
git config --global user.name "GitHub Actions"
47+
git config --global user.email "[email protected]"
48+
49+
- name: Extract release version
50+
run: |
51+
TAG_NAME=${GITHUB_REF_NAME}
52+
VERSION=${TAG_NAME#v}
53+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
54+
shell: bash
55+
56+
- name: Update pom.xml to release version
57+
run: |
58+
mvn versions:set -DnewVersion=${{ env.RELEASE_VERSION }} -B -q
59+
git commit -am "Set version to ${{ env.RELEASE_VERSION }}" || echo "No changes"
60+
git push origin HEAD
61+
env:
62+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Run tests
65+
run: mvn clean verify -B
66+
67+
- name: Publish RELEASE to Maven Central
68+
run: mvn deploy -P release -B -DskipTests
69+
env:
70+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
71+
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
72+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

.github/workflows/sonar.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ name: SonarQube Analysis
22

33
on:
44
pull_request:
5+
branches: [ main, develop ]
56
push:
67
branches:
78
- main
9+
- develop
810

911
jobs:
1012
sonar:
@@ -13,14 +15,24 @@ jobs:
1315
steps:
1416
- name: Checkout repository
1517
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
1620

1721
- name: Set up JDK
1822
uses: actions/setup-java@v4
1923
with:
2024
distribution: 'temurin'
2125
java-version: '21'
2226

27+
- name: Cache Maven packages
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.m2
31+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
32+
restore-keys: ${{ runner.os }}-m2
33+
2334
- name: Run SonarQube
24-
run: mvn clean verify sonar:sonar -Dsonar.projectKey=ComputerDaddyGuy_JFileTreePrettyPrinter
35+
run: mvn -B clean verify sonar:sonar -Dsonar.projectKey=ComputerDaddyGuy_JFileTreePrettyPrinter -Dsonar.organization=computerdaddyguy
2536
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2638
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)