1- name : Master Build
1+ # Example: Copy this to your repo as .github/workflows/maven.yml
2+ # Configuration is read from .github/project.yml - no inputs needed!
3+ name : Maven Build
24
35on :
46 push :
5- branches : [ "main ", "feature /*" ]
7+ branches : [main, "feature/* ", "fix /*", "dependabot/**" ]
68 pull_request :
7- branches : [ "main" ]
9+ branches : [main]
10+ workflow_dispatch :
811
912jobs :
1013 build :
11-
12- runs-on : ubuntu-latest
13- strategy :
14- matrix :
15- version : [ 21,24 ]
16-
17- steps :
18- - name : Harden the runner (Audit all outbound calls)
19- uses : step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
20- with :
21- egress-policy : audit
22-
23- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24- - name : Set up JDK ${{ matrix.version }}
25- uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
26- with :
27- java-version : ${{ matrix.version }}
28- distribution : ' temurin'
29- cache : maven
30- - name : Build with Maven, Java ${{ matrix.version }}
31- run : ./mvnw --no-transfer-progress verify -Dmaven.compiler.release=${{ matrix.version }}
32-
33- sonar-build :
34- needs : build
35- runs-on : ubuntu-latest
36-
37- steps :
38- - name : Harden the runner (Audit all outbound calls)
39- uses : step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
40- with :
41- egress-policy : audit
42-
43- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44- with :
45- fetch-depth : 0
46-
47- - name : Set up JDK 21 for Sonar-build
48- uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
49- with :
50- java-version : ' 21'
51- distribution : ' temurin'
52- cache : maven
53-
54- - name : Cache SonarCloud packages
55- uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
56- with :
57- path : ~/.sonar/cache
58- key : ${{ runner.os }}-sonar
59- restore-keys : ${{ runner.os }}-sonar
60-
61- - uses : radcortez/project-metadata-action@203f7ffba8db2669b2c9b4d4c2e90b186c588fa5 # 1.1
62- name : Retrieve project metadata from '.github/project.yml'
63- id : metadata
64- with :
65- github-token : ${{secrets.GITHUB_TOKEN}}
66- metadata-file-path : ' .github/project.yml'
67- local-file : true
68-
69- - name : Build and analyze
70- env :
71- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
72- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
73- run : ./mvnw -B --no-transfer-progress verify -Psonar -Dsonar.projectKey=${{steps.metadata.outputs.sonar-project-key}} sonar:sonar
74-
75- deploy-snapshot :
76- needs : sonar-build
77- if : github.ref == 'refs/heads/main'
78- runs-on : ubuntu-latest
79- steps :
80- - name : Harden the runner (Audit all outbound calls)
81- uses : step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
82- with :
83- egress-policy : audit
84-
85- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
86- - name : Set up JDK 17 for snapshot release
87- uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
88- with :
89- java-version : ' 21'
90- distribution : ' temurin'
91- server-id : central
92- server-username : MAVEN_USERNAME
93- server-password : MAVEN_PASSWORD
94- gpg-private-key : ${{ secrets.GPG_PRIVATE_KEY }}
95- gpg-passphrase : MAVEN_GPG_PASSPHRASE
96- cache : maven
97-
98- - name : Extract project version
99- id : project
100- run : echo ::set-output name=version::$(./mvnw --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout)
101-
102- - name : Deploy Snapshot with Maven, version ${{ steps.project.outputs.version }}
103- if : ${{endsWith(steps.project.outputs.version, '-SNAPSHOT')}}
104- run : |
105- ./mvnw -B --no-transfer-progress -Prelease-snapshot,javadoc deploy -Dmaven.test.skip=true
106- env :
107- MAVEN_USERNAME : ${{ secrets.OSS_SONATYPE_USERNAME }}
108- MAVEN_PASSWORD : ${{ secrets.OSS_SONATYPE_PASSWORD }}
109- MAVEN_GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
14+ # Run on push events, OR on pull_request only if from a fork
15+ # This prevents duplicate runs: push handles internal branches, PR handles forks
16+ if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
17+ uses : cuioss/cuioss-organization/.github/workflows/reusable-maven-build.yml@288f393bf5407c87ffd95c128cdf694761941308 # v0.2.0
18+ secrets : inherit
0 commit comments