Skip to content

Commit c7a428d

Browse files
authored
JCR-5157: configure CI for PRs on github - wip (#252)
1 parent 0975711 commit c7a428d

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

.github/workflows/build.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# ~ Licensed to the Apache Software Foundation (ASF) under one
2+
# ~ or more contributor license agreements. See the NOTICE file
3+
# ~ distributed with this work for additional information
4+
# ~ regarding copyright ownership. The ASF licenses this file
5+
# ~ to you under the Apache License, Version 2.0 (the
6+
# ~ "License"); you may not use this file except in compliance
7+
# ~ with the License. You may obtain a copy of the License at
8+
# ~
9+
# ~ http://www.apache.org/licenses/LICENSE-2.0
10+
# ~
11+
# ~ Unless required by applicable law or agreed to in writing,
12+
# ~ software distributed under the License is distributed on an
13+
# ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# ~ KIND, either express or implied. See the License for the
15+
# ~ specific language governing permissions and limitations
16+
# ~ under the License.
17+
18+
name: Build
19+
on:
20+
push:
21+
branches:
22+
- trunk
23+
pull_request:
24+
types: [opened, synchronize, reopened]
25+
jobs:
26+
build:
27+
name: Maven Build
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Git clone
31+
uses: actions/checkout@v4
32+
- name: Set up JDK 11
33+
uses: actions/setup-java@v4
34+
with:
35+
java-version: 11
36+
distribution: temurin
37+
cache: maven
38+
server-id: apache.snapshots.https # Value of the distributionManagement/repository/id field of the pom.xml
39+
server-username: MAVEN_APACHE_NEXUS_USERNAME # env variable for username in deploy
40+
server-password: MAVEN_APACHE_NEXUS_PASSWORD # env variable for token in deploy
41+
# sets environment variables to be used in subsequent steps: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
42+
- name: Set environment variables
43+
shell: bash
44+
run: |
45+
if [ "${{github.ref}}" = "refs/heads/trunk" ] && [ "${{github.event_name}}" = "push" ] && [ "${{github.repository_owner}}" = "apache" ]; then
46+
echo 'Running on main branch of the canonical repo'
47+
echo "MVN_ADDITIONAL_OPTS=-DdeployAtEnd=true" >> $GITHUB_ENV
48+
echo "MVN_GOAL=deploy" >> $GITHUB_ENV
49+
echo "MAVEN_APACHE_NEXUS_USERNAME=${{ secrets.NEXUS_USER }}" >> $GITHUB_ENV
50+
echo "MAVEN_APACHE_NEXUS_PASSWORD=${{ secrets.NEXUS_PW }}" >> $GITHUB_ENV
51+
else
52+
echo 'Running outside main branch/canonical repo'
53+
echo "MVN_ADDITIONAL_OPTS=" >> $GITHUB_ENV
54+
echo "MVN_GOAL=install" >> $GITHUB_ENV
55+
fi
56+
- name: Build
57+
# executing ITs requires installing artifacts to the local repository
58+
run: mvn -B ${{ env.MVN_GOAL }} ${{ env.MVN_ADDITIONAL_OPTS }} -Pcoverage,integrationTesting,javadoc -Dorg.ops4j.pax.url.mvn.repositories="https://repo1.maven.org/maven2@id=central"
59+
- name: Upload build result
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: compiled-classes-and-coverage
63+
# compare with https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/java/#java-analysis-and-bytecode
64+
path: |
65+
**/target/**/*.class
66+
**/target/site/jacoco*/*.xml
67+
68+
# execute analysis in a separate job for better visualization and usage of matrix builds
69+
# https://docs.sonarsource.com/sonarcloud/advanced-setup/ci-based-analysis/sonarscanner-for-maven/#invoking-the-goal
70+
sonar:
71+
name: SonarQube Analysis
72+
runs-on: ubuntu-latest
73+
needs: build
74+
# not supported on forks, https://portal.productboard.com/sonarsource/1-sonarqube-cloud/c/50-sonarcloud-analyzes-external-pull-request
75+
if: ${{ github.repository == 'apache/jackrabbit' }}
76+
steps:
77+
- uses: actions/checkout@v4
78+
with:
79+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
80+
- name: Set up JDK 17
81+
uses: actions/setup-java@v4
82+
with:
83+
java-version: 17
84+
distribution: temurin
85+
cache: maven
86+
- name: Download compiled classes
87+
uses: actions/download-artifact@v4
88+
with:
89+
name: compiled-classes-and-coverage
90+
- name: Cache SonarQube packages
91+
uses: actions/cache@v4
92+
with:
93+
path: ~/.sonar/cache
94+
key: ${{ runner.os }}-sonar
95+
restore-keys: ${{ runner.os }}-sonar
96+
- name: Analyze with SonarQube
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
99+
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
100+
run: SONAR_SCANNER_JAVA_OPTS="-Xmx8g" mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:5.1.0.4751:sonar -Dsonar.projectKey=apache_jackrabbit -Dsonar.organization=apache -Dsonar.scanner.skipJreProvisioning=true

0 commit comments

Comments
 (0)