-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split sonar cloud action to support pull requests
- Loading branch information
Showing
4 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,73 @@ | ||
name: SonarCloud C/C++ CI | ||
|
||
on: | ||
push: | ||
branches: [ "master", '*-ci' ] | ||
pull_request: | ||
branches: [ "master" ] | ||
workflow_dispatch: | ||
workflow_run: | ||
workflows: [ 'SonarCloud C/C++ CI Trigger' ] | ||
types: [ completed ] | ||
|
||
jobs: | ||
build: | ||
run: | ||
name: sonar_cloud | ||
runs-on: ubuntu-latest | ||
if: github.event.workflow_run.conclusion == 'success' | ||
env: | ||
BUILD_WRAPPER_OUT_DIR: build_wrapper | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
# checkout out the proper repository in case of pull request | ||
repository: ${{ github.event.workflow_run.head_repository.full_name }} | ||
ref: ${{ github.event.workflow_run.head_branch }} | ||
fetch-depth: 0 # shallow clones should be disabled for a better relevancy of analysis | ||
submodules: recursive | ||
|
||
# BEGIN PULL REQUEST | ||
|
||
- name: Download pull request number artifact | ||
if: github.event.workflow_run.event == 'pull_request' | ||
uses: dawidd6/action-download-artifact@v6 | ||
with: | ||
workflow: sonar_cloud_trigger | ||
run_id: ${{ github.event.workflow_run.id }} | ||
name: pull_request_number | ||
|
||
- name: "Read pull request number" | ||
if: github.event.workflow_run.event == 'pull_request' | ||
id: pull_request_number | ||
uses: juliangruber/read-file-action@v1 | ||
with: | ||
path: ./pull_request_number.txt | ||
|
||
- name: Request GitHub API for pull_request data | ||
if: github.event.workflow_run.event == 'pull_request' | ||
uses: octokit/[email protected] | ||
id: get_pull_request_data | ||
with: | ||
route: GET /repos/${{ github.event.repository.full_name }}/pulls/${{ steps.pull_request_number.outputs.content }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Checkout upstream base branch and checkout pull request head branch | ||
if: github.event.workflow_run.event == 'pull_request' | ||
run: | | ||
git remote add upstream ${{ github.event.repository.clone_url }} | ||
git fetch upstream | ||
git checkout -B ${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }} \ | ||
upstream/${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }} | ||
git checkout origin/${{ github.event.workflow_run.head_branch }} | ||
git clean -ffdx && git reset --hard HEAD | ||
- name: Set pull request variables | ||
if: github.event.workflow_run.event == 'pull_request' | ||
run: | | ||
echo "PULL_REQUEST_KEY=${{ fromJson(steps.get_pull_request_data.outputs.data).number }}" >> ${GITHUB_ENV} | ||
echo "PULL_REQUEST_BRANCH=${{ fromJson(steps.get_pull_request_data.outputs.data).head.ref }}" >> ${GITHUB_ENV} | ||
echo "PULL_REQUEST_BASE=${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }}" >> ${GITHUB_ENV} | ||
# END PULL REQUEST | ||
|
||
- name: Install sonar-scanner and build-wrapper | ||
uses: SonarSource/sonarcloud-github-c-cpp@v2 | ||
|
||
|
@@ -68,4 +115,7 @@ jobs: | |
--define sonar.tests="compiler/extensions/cpp/runtime/test,test" \ | ||
--define sonar.test.inclusions="compiler/**/test/**/*.h,compiler/**/test/**/.cpp,test/**/*.h,test/**/*.cpp" \ | ||
--define sonar.scm.exclusions.disabled="true" \ | ||
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" | ||
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \ | ||
--define sonar.pullrequest.key="${{ env.PULL_REQUEST_KEY }}" \ | ||
--define sonar.pullrequest.branch="${{ env.PULL_REQUEST_BRANCH }}" \ | ||
--define sonar.pullrequest.base="${{ env.PULL_REQUEST_BASE }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: SonarCloud C/C++ CI Trigger | ||
|
||
on: | ||
push: | ||
branches: [ master, '*-ci' ] | ||
pull_request: | ||
branches: [ master, '*-ci' ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run: | ||
name: sonar_cloud_trigger | ||
runs-on: ubuntu-latest | ||
|
||
# just save the pull request number in case of pull request | ||
steps: | ||
- name: Save pull request number to file | ||
if: github.event_name == 'pull_request' | ||
run: echo ${{ github.event.number }} > pull_request_number.txt | ||
|
||
- name: Archive pull request number | ||
if: github.event_name == 'pull_request' | ||
# update when https://github.com/actions/upload-artifact/issues/543 is fixed | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: pull_request_number | ||
path: pull_request_number.txt |