Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sonar action can't get PR number #2048

Merged
merged 8 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,20 @@ jobs:
with:
name: sonarcloud-data
path: ${{ env.SONARCLOUD_OUTPUT_DIR }}


- name: Save PR info
if: ${{ (github.event_name == 'pull_request') && matrix.sonarcloud }}
run: |
mkdir -p ./pr
echo "number=${{ github.event.number }}" >> ./pr/info

- name: Upload PR info
uses: actions/upload-artifact@v3
if: ${{ matrix.sonarcloud }}
with:
name: pr
path: pr/
jihuayu marked this conversation as resolved.
Show resolved Hide resolved

check-docker:
name: Check Docker image
needs: [precondition, check-and-lint, check-typos]
Expand Down
53 changes: 33 additions & 20 deletions .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,45 @@ jobs:
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "sonarcloud-data"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/sonarcloud-data.zip`, Buffer.from(download.data));
async function getData(name) {
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == name
})[0];
if(!matchArtifact) return;
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${name}.zip`, Buffer.from(download.data));
}
await getData("sonarcloud-data");
await getData("pr");
jihuayu marked this conversation as resolved.
Show resolved Hide resolved

- name: 'Unzip code coverage'
run: |
unzip sonarcloud-data.zip -d sonarcloud-data
ls -a sonarcloud-data


- name: 'Unzip PR info'
id: info
run: |
if [ -f pr.zip ]; then
unzip pr.zip
cat info >> "$GITHUB_OUTPUT"
fi

- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Configure Kvrocks
run: |
./x.py build -j$(nproc) --compiler gcc --skip-build
Expand All @@ -78,6 +93,4 @@ jobs:
--define sonar.projectKey=apache_kvrocks \
--define sonar.organization=apache \
--define sonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
--define sonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} \
--define sonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} \
--define sonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }}
--define sonar.pullrequest.key=${{ steps.info.outputs.number }}