Skip to content

comment

comment #24

Workflow file for this run

name: Java CI
on:
push:
branches: [ master ]
jobs:
build-and-analyze:
runs-on: ubuntu-latest
name: Build and Run Sonar analysis on JDK 23
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
# The LAST Java in the list becomes the default (because each overwrites the settings)!
- name: Setup Java 23 (1/2)
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 23
- name: Setup Java 23 (2/2)
run: echo "JAVA_23=$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>21</version>
</provides>
<configuration>
<jdkHome>${{ env.JAVA_23 }}</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 23"; \
${{ env.JAVA_23 }}/bin/java -version ; \
${{ env.JAVA_23 }}/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=tuyucheng777_taketoday-tutorial4j -Dsonar.organization=tuyucheng777 -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 }}