Skip to content

Commit

Permalink
IGNITE-20466 Support sonar check from forks
Browse files Browse the repository at this point in the history
  • Loading branch information
skorotkov committed Jul 23, 2024
1 parent b158d2f commit f20cae6
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 106 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
java: [ '8', '11' ]
name: Check java code on JDK ${{ matrix.java }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
Expand Down Expand Up @@ -75,12 +75,12 @@ jobs:
name: Сheck .NET code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'

Expand All @@ -100,12 +100,12 @@ jobs:
- { python: "3.8", toxenv: "py38" }
- { python: "3.8", toxenv: "codestyle" }
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.cfg.python}}

Expand Down
23 changes: 15 additions & 8 deletions .github/workflows/sonar-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ on:
jobs:
sonarcloud:
name: Sonar Analysis
if: github.repository == 'apache/ignite'
if: github.repository == 'skorotkov/ignite'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup java
uses: actions/setup-java@v3
- name: Setup JDK11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
cache: 'maven'

- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand All @@ -61,13 +61,20 @@ jobs:
run: |
./mvnw install -P all-java,lgpl,examples,skip-docs -DskipTests -B -V
- name: Setup JDK17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: 'maven'

- name: Sonar Analyze Upload
run: >
./mvnw org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
-P all-java,lgpl,examples,skip-docs
-Dsonar.branch.name=${{ github.ref_name }}
-Dsonar.projectKey=apache_ignite
-Dsonar.login=${SONARCLOUD_TOKEN}
-Dsonar.projectKey=skorotkov_ignite
-Dsonar.token=${SONARCLOUD_TOKEN}
-B -V
env:
MAVEN_OPTS: "-XX:+UseG1GC -XX:InitialHeapSize=2g -XX:MaxHeapSize=6g -XX:+UseStringDeduplication"
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/sonar-pr-from-fork-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: SonarBuild

on: pull_request

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
if: github.repository == 'skorotkov/ignite'
name: Build artifacts for Sonar Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.number }}/merge"
fetch-depth: 0

- name: Set up JDK11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'maven'

- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-m2
- name: Install Libnuma
run: sudo apt-get update && sudo apt-get install libnuma-dev

- name: Build with Maven
run: |
./mvnw clean install -P all-java,lgpl,examples,skip-docs -DskipTests -B -V
- name: Prepare pull request artifact
shell: bash
run: |
echo ${{ github.event.pull_request.number }} >> pr-event.txt
echo ${{ github.event.pull_request.head.ref }} >> pr-event.txt
echo ${{ github.event.pull_request.base.ref }} >> pr-event.txt
echo ${{ github.event.pull_request.head.sha }} >> pr-event.txt
- name: Upload pull request event artifact
uses: actions/upload-artifact@v4
with:
name: pr-event-artifact
path: |
pr-event.txt
if-no-files-found: error
retention-days: 1

- name: Prepare compiled classes artifact
shell: bash
run: find -iname "*target" -type d -exec tar -rf target.tar {} \+

- name: Upload compiled classes artifact
uses: actions/upload-artifact@v4
with:
name: target-artifact
path: |
target.tar
if-no-files-found: error
retention-days: 1
131 changes: 131 additions & 0 deletions .github/workflows/sonar-pr-from-fork-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Sonar Quality Pull Request Analysis

on:
workflow_run:
workflows: [SonarBuild]
types: [completed]

jobs:
sonarcloud:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.repository == 'skorotkov/ignite' }}
name: Sonar Analysis
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
checks: write
steps:
- name: Download pull request event artifact
uses: actions/download-artifact@v4
with:
name: pr-event-artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
merge-multiple: true

- name: Read pull request event
shell: bash
run: |
echo "pr_number=$(sed '1q;d' pr-event.txt)" >> "$GITHUB_ENV"
echo "pr_head_ref=$(sed '2q;d' pr-event.txt)" >> "$GITHUB_ENV"
echo "pr_base_ref=$(sed '3q;d' pr-event.txt)" >> "$GITHUB_ENV"
echo "pr_head_sha=$(sed '4q;d' pr-event.txt)" >> "$GITHUB_ENV"
- uses: actions/github-script@v7
id: job-url
with:
script: |
const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({
...context.repo,
run_id: context.runId,
attempt_number: process.env.GITHUB_RUN_ATTEMPT,
});
return data.jobs[0].html_url
result-encoding: string

- uses: LouisBrunner/checks-action@v2.0.0
id: init
with:
sha: ${{ env.pr_head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
name: Sonar Quality Pull Request Analysis
output: |
${{ format('{{"summary": "[Details ...]({0})"}}', steps.job-url.outputs.result) }}
status: in_progress

- uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0

- name: Download compiled classes artifact
uses: actions/download-artifact@v4
with:
name: target-artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
merge-multiple: true

- name: Extract compiled classes artifact
shell: bash
run: tar -xf target.tar

- name: Set up JDK17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: ${{ env.build_type }}

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Sonar Analyze Upload
shell: bash
run: >
./mvnw org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
-P all-java,lgpl,examples,skip-docs
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.pullrequest.branch=${{ env.pr_head_ref }}
-Dsonar.pullrequest.base=${{ env.pr_base_ref }}
-Dsonar.pullrequest.key=${{ env.pr_number }}
-Dsonar.pullrequest.github.repository=skorotkov/ignite
-Dsonar.pullrequest.provider=GitHub
-Dsonar.pullrequest.github.summary_comment=true
-Dsonar.projectKey=skorotkov_ignite
-Dsonar.token=${{ secrets.SONARCLOUD_TOKEN }}
-B -V
env:
MAVEN_OPTS: "-XX:+UseG1GC -XX:InitialHeapSize=2g -XX:MaxHeapSize=6g -XX:+UseStringDeduplication"
SONAR_OPTS: "-XX:+UseG1GC -XX:InitialHeapSize=2g -XX:MaxHeapSize=6g -XX:+UseStringDeduplication"
JAVA_OPTS: "-XX:+UseG1GC -XX:InitialHeapSize=2g -XX:MaxHeapSize=6g -XX:+UseStringDeduplication"

- uses: LouisBrunner/checks-action@v2.0.0
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
check_id: ${{ steps.init.outputs.check_id }}
status: completed
conclusion: ${{ job.status }}
Loading

0 comments on commit f20cae6

Please sign in to comment.