diff --git a/.github/workflows/maven.yml b/.github/workflows/maven_pull_request.yml similarity index 68% rename from .github/workflows/maven.yml rename to .github/workflows/maven_pull_request.yml index c07083a5..d7b477c1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven_pull_request.yml @@ -1,15 +1,9 @@ # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven -name: Java CI with Maven - -# The API requires write permission on the repository to submit dependencies -permissions: - contents: write +name: Java CI with Maven on Pull Request on: - push: - branches: ["main"] pull_request: branches: ["main"] @@ -28,16 +22,11 @@ jobs: run: mvn -B verify --file pom.xml - name: Scan with Sonar run: | - if [ $FORK = false ] || [ "$PUSH_REF" = "refs/heads/main" ] + if [ $FORK = false ] then mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BerryCloud_xapi-java -Dsonar.organization=berry-cloud -Dsonar.host.url=https://sonarcloud.io --file pom.xml fi env: FORK: ${{ github.event.pull_request.head.repo.fork }} - PUSH_REF: ${{ github.event.ref }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@v3 diff --git a/.github/workflows/maven_push.yml b/.github/workflows/maven_push.yml new file mode 100644 index 00000000..ea330936 --- /dev/null +++ b/.github/workflows/maven_push.yml @@ -0,0 +1,31 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +name: Java CI with Maven on Push + +on: + push: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "temurin" + cache: maven + - name: Build with Maven + run: mvn -B verify --file pom.xml + - name: Scan with Sonar + run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BerryCloud_xapi-java -Dsonar.organization=berry-cloud -Dsonar.host.url=https://sonarcloud.io --file pom.xml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@v3