Просмотр исходного кода

Get information about the source run (#540)

Dominik Fuchß 4 лет назад
Родитель
Сommit
be17ca0ba3
1 измененных файлов с 30 добавлено и 1 удалено
  1. 30 1
      .github/workflows/sonarcloud.yml

+ 30 - 1
.github/workflows/sonarcloud.yml

@@ -13,10 +13,33 @@ on:
   workflow_dispatch:
   workflow_dispatch:
 
 
 jobs:
 jobs:
+  get-info:
+    name: "Get information about the source run"
+    runs-on: ubuntu-latest
+    if: ${{ github.actor != 'dependabot[bot]' && github.event.workflow_run.conclusion == 'success' }}
+    outputs:
+      sourceHeadRepo: ${{ steps.source-run-info.outputs.sourceHeadRepo }}
+      sourceHeadBranch: ${{ steps.source-run-info.outputs.sourceHeadBranch }}
+      sourceHeadSha: ${{ steps.source-run-info.outputs.sourceHeadSha }}
+      mergeCommitSha: ${{ steps.source-run-info.outputs.mergeCommitSha }}
+      targetCommitSha: ${{ steps.source-run-info.outputs.targetCommitSha }}
+      pullRequestNumber: ${{ steps.source-run-info.outputs.pullRequestNumber }}
+      pullRequestLabels: ${{ steps.source-run-info.outputs.pullRequestLabels }}
+      targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
+      sourceEvent: ${{ steps.source-run-info.outputs.sourceEvent }}
+    steps:
+      - name: "Get information about the origin 'CI' run"
+        uses: potiuk/get-workflow-origin@v1_3
+        id: source-run-info
+        with:
+          token: ${{ secrets.GITHUB_TOKEN }}
+          sourceRunId: ${{ github.event.workflow_run.id }}
+
   sonar:
   sonar:
     name: SonarCloud Scan
     name: SonarCloud Scan
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     if: ${{ github.actor != 'dependabot[bot]' && github.event.workflow_run.conclusion == 'success' }}
     if: ${{ github.actor != 'dependabot[bot]' && github.event.workflow_run.conclusion == 'success' }}
+    needs: get-info
 
 
     steps:
     steps:
       - uses: actions/checkout@v3
       - uses: actions/checkout@v3
@@ -46,4 +69,10 @@ jobs:
         env:
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
           SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
-        run: mvn -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0] != null && github.event.workflow_run.pull_requests[0].number }} -Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0] != null && github.event.workflow_run.pull_requests[0].head.ref }} -Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0] != null && github.event.workflow_run.pull_requests[0].base.ref }} -U -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
+        run: >
+          mvn 
+          -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} 
+          -Dsonar.pullrequest.key=${{ needs.get-info.outputs.pullRequestNumber }} 
+          -Dsonar.pullrequest.branch=${{ needs.get-info.outputs.sourceHeadBranch }} 
+          -Dsonar.pullrequest.base=${{ needs.get-info.outputs.pullRequestNumber }} 
+          -U -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar