Initial commit #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java CI | |
on: | |
push: | |
branches: [ master ] | |
jobs: | |
build-and-analyze: | |
runs-on: ubuntu-latest | |
name: Build and Run Sonar analysis on JDK 21 | |
steps: | |
- name: Checkout sourcecode | |
uses: actions/checkout@v3 | |
- name: Cache Local Maven Repository | |
uses: actions/cache@v3 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Setup Java 8 (1/2) | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 8 | |
- name: Setup Java 8 (2/2) | |
run: echo "JAVA_8=$JAVA_HOME" >> $GITHUB_ENV | |
- name: Setup Java 19 (1/2) | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 19 | |
- name: Setup Java 19 (2/2) | |
run: echo "JAVA_19=$JAVA_HOME" >> $GITHUB_ENV | |
- name: Setup Java 20 (1/2) | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 20 | |
- name: Setup Java 20 (2/2) | |
run: echo "JAVA_20=$JAVA_HOME" >> $GITHUB_ENV | |
- name: Setup Java 17 (1/2) | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 17 | |
- name: Setup Java 17 (2/2) | |
run: echo "JAVA_17=$JAVA_HOME" >> $GITHUB_ENV | |
# The LAST Java in the list becomes the default (because each overwrites the settings)! | |
- name: Setup Java 21 (1/2) | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 21 | |
- name: Setup Java 21 (2/2) | |
run: echo "JAVA_21=$JAVA_HOME" >> $GITHUB_ENV | |
- name: Create toolchains.xml | |
shell: bash | |
run: | | |
mkdir -p $HOME/.m2 \ | |
&& cat << EOF > $HOME/.m2/toolchains.xml | |
<?xml version="1.0" encoding="UTF8"?> | |
<toolchains> | |
<toolchain> | |
<type>jdk</type> | |
<provides> | |
<version>8</version> | |
</provides> | |
<configuration> | |
<jdkHome>${{ env.JAVA_8 }}</jdkHome> | |
</configuration> | |
</toolchain> | |
<toolchain> | |
<type>jdk</type> | |
<provides> | |
<version>17</version> | |
</provides> | |
<configuration> | |
<jdkHome>${{ env.JAVA_17 }}</jdkHome> | |
</configuration> | |
</toolchain> | |
<toolchain> | |
<type>jdk</type> | |
<provides> | |
<version>19</version> | |
</provides> | |
<configuration> | |
<jdkHome>${{ env.JAVA_19 }}</jdkHome> | |
</configuration> | |
</toolchain> | |
<toolchain> | |
<type>jdk</type> | |
<provides> | |
<version>20</version> | |
</provides> | |
<configuration> | |
<jdkHome>${{ env.JAVA_20 }}</jdkHome> | |
</configuration> | |
</toolchain> | |
<toolchain> | |
<type>jdk</type> | |
<provides> | |
<version>21</version> | |
</provides> | |
<configuration> | |
<jdkHome>${{ env.JAVA_21 }}</jdkHome> | |
</configuration> | |
</toolchain> | |
</toolchains> | |
EOF | |
- name: Verify setup | |
shell: bash | |
run: | | |
echo "Showing currently installed Java versions:";\ | |
echo "======================================";\ | |
echo "Default Java"; \ | |
java -version ; \ | |
javac -version ; \ | |
echo JAVA_HOME=${JAVA_HOME} ; \ | |
echo "======================================";\ | |
echo "Java 8"; \ | |
${{ env.JAVA_8 }}/bin/java -version ; \ | |
${{ env.JAVA_8 }}/bin/javac -version ; \ | |
echo "======================================";\ | |
echo "Java 17"; \ | |
${{ env.JAVA_17 }}/bin/java -version ; \ | |
${{ env.JAVA_17 }}/bin/javac -version ; \ | |
echo "======================================";\ | |
echo "Java 19"; \ | |
${{ env.JAVA_19 }}/bin/java -version ; \ | |
${{ env.JAVA_19 }}/bin/javac -version ; \ | |
echo "======================================";\ | |
echo "Java 20"; \ | |
${{ env.JAVA_20 }}/bin/java -version ; \ | |
${{ env.JAVA_20 }}/bin/javac -version ; \ | |
echo "======================================";\ | |
echo "Java 21"; \ | |
${{ env.JAVA_21 }}/bin/java -version ; \ | |
${{ env.JAVA_21 }}/bin/javac -version ; \ | |
echo "======================================";\ | |
cat $HOME/.m2/toolchains.xml; \ | |
echo "======================================"; | |
# Cache Sonar packages which as used to run analysis and collect metrics | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
# Some tests need screen access | |
- name: Install xvfb | |
run: sudo apt-get install -y xvfb | |
- name: Build with Maven and run SonarQube analysis | |
run: xvfb-run ./mvnw -B clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=tu-yucheng_taketoday-tutorial4j -Dsonar.organization=tuyucheng -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Pall | |
env: | |
# These two env variables are needed for sonar analysis | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |