Skip to content

Commit

Permalink
IGNITE-20466 Remove tmp artifact; no external actions; fix maven cach…
Browse files Browse the repository at this point in the history
…e; cancel concurrent jobs; checkout PR base master
  • Loading branch information
skorotkov committed Jul 25, 2024
1 parent 30a67ad commit 8582dd5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 41 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/sonar-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ on:
- master
- 'ignite-[0-9].[0-9]+.[0-9]+*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
sonarcloud:
name: Sonar Analysis
Expand All @@ -32,13 +36,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

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

- name: Cache SonarCloud packages
uses: actions/cache@v4
Expand All @@ -50,7 +54,7 @@ jobs:
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

Expand All @@ -59,14 +63,13 @@ jobs:

- name: Build with Maven
run: |
./mvnw install -P all-java,lgpl,examples,skip-docs -DskipTests -B -V
./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: >
Expand Down
32 changes: 17 additions & 15 deletions .github/workflows/sonar-pr-from-fork-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
with:
ref: "refs/pull/${{ github.event.number }}/merge"
fetch-depth: 0
persist-credentials: false

- 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
Expand All @@ -57,7 +57,21 @@ jobs:

- name: Build with Maven
run: |
./mvnw clean install -P all-java,lgpl,examples,skip-docs -DskipTests -B -V
./mvnw install -P all-java,lgpl,examples,skip-docs -DskipTests -B -V
- 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
id: target-artifact-upload-step
with:
name: target-artifact
path: |
target.tar
if-no-files-found: error
retention-days: 1

- name: Prepare pull request artifact
shell: bash
Expand All @@ -66,6 +80,7 @@ jobs:
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
echo ${{ steps.target-artifact-upload-step.outputs.artifact-id }} >> pr-event.txt
- name: Upload pull request event artifact
uses: actions/upload-artifact@v4
Expand All @@ -75,16 +90,3 @@ jobs:
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
89 changes: 67 additions & 22 deletions .github/workflows/sonar-pr-from-fork-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ on:
workflows: [SonarBuild]
types: [completed]

concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}}
cancel-in-progress: true

jobs:
sonarcloud:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.repository == 'apache/ignite' }}
name: Sonar Analysis
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
actions: write
checks: write
steps:
- name: Download pull request event artifact
Expand All @@ -47,35 +51,50 @@ jobs:
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"
echo "target_artifact_id=$(sed '5q;d' pr-event.txt)" >> "$GITHUB_ENV"
- uses: actions/github-script@v7
id: job-url
- name: Create new PR check
uses: actions/github-script@v7
id: check
with:
script: |
const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({
const jobs_response = await github.rest.actions.listJobsForWorkflowRunAttempt({
...context.repo,
run_id: context.runId,
attempt_number: process.env.GITHUB_RUN_ATTEMPT,
});
return data.jobs[0].html_url
const job_url = jobs_response.data.jobs[0].html_url;
const check_response = await github.rest.checks.create({
...context.repo,
name: 'Sonar Quality Pull Request Analysis',
head_sha: process.env.pr_head_sha,
status: 'in_progress',
output: {
title: 'Sonar Quality Pull Request Analysis',
summary: '[Details ...](' + job_url + ')'
}
});
return check_response.data.id;
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
- name: Checkout PR head branch
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: Checkout PR base branch
run: |
git remote add upstream ${{ github.event.repository.clone_url }}
git fetch upstream
git checkout -B $pr_base_ref upstream/$pr_base_ref
git checkout ${{ github.event.workflow_run.head_branch }}
git clean -ffdx && git reset --hard HEAD
- name: Download compiled classes artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -84,6 +103,16 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
merge-multiple: true

- name: Delete compiled classes artifact
if: always()
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.deleteArtifact({
...context.repo,
artifact_id: process.env.target_artifact_id
});
- name: Extract compiled classes artifact
shell: bash
run: tar -xf target.tar
Expand All @@ -93,7 +122,6 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'
cache: ${{ env.build_type }}

- name: Cache SonarCloud packages
uses: actions/cache@v4
Expand All @@ -102,6 +130,14 @@ jobs:
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- 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: Sonar Analyze Upload
shell: bash
run: >
Expand All @@ -122,10 +158,19 @@ jobs:
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
- name: Update status of PR check
uses: actions/github-script@v7
if: always()
env:
CHECK_ID: ${{ steps.check.outputs.result }}
JOB_STATUS: ${{ job.status }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
check_id: ${{ steps.init.outputs.check_id }}
status: completed
conclusion: ${{ job.status }}
script: |
const { CHECK_ID, JOB_STATUS } = process.env;
await github.rest.checks.update({
...context.repo,
check_run_id: CHECK_ID,
status: 'completed',
conclusion: JOB_STATUS
});

0 comments on commit 8582dd5

Please sign in to comment.