openrewrite / rewrite-github-actions

OpenRewrite recipes for performing GitHub action hygiene and migration tasks.
Apache License 2.0
9 stars 9 forks source link

Set `fetch-depth` to 0 for workflows using Sonar #62

Open yeikel opened 1 year ago

yeikel commented 1 year ago

This recipe should :

  1. Detect usages of actions/checkout and Sonar
  2. Change the fetch-depth to 0 for actions/checkout

Example pull request : https://github.com/kobylynskyi/graphql-java-codegen/pull/1061


diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml
index 78fa738a..6b6710b0 100644
--- a/.github/workflows/github.yml
+++ b/.github/workflows/github.yml
@@ -86,7 +86,8 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-
+        with:
+         fetch-depth: 0
       - name: Setup Java
         uses: actions/setup-java@v1
         with:

There are a few ways to run Sonar as far as I know :

Gradle :

 ./gradlew sonarqube ...
 gradle sonarqube ...

Maven :

 mvn sonar:sonar 
 ./mvnw sonar:sonar 

Using sonarqube-action

Additional information : https://community.sonarsource.com/t/git-fetch-depth-implications/75260

Common error after results are processed:

image