Skip to content

Commit 9189ced

Browse files
authored
👷 Upload sonar analysis to Pixee (#291)
* 👷 Upload sonar analysis to Pixee when it is complete and conditionally trigger PR analysis if it is a PR * 🎨 fix lint
1 parent 1c4b4b4 commit 9189ced

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎.github/workflows/sonar_pixee.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Publish Sonar JSON to Pixee"
2+
on:
3+
check_run:
4+
types: [completed]
5+
6+
permissions:
7+
contents: read
8+
id-token: write
9+
10+
jobs:
11+
publish:
12+
name: "Publish Sonar JSON to Pixee"
13+
runs-on: ubuntu-latest
14+
if: ${{ github.event.check_run.name == 'SonarCloud Code Analysis' }}
15+
steps:
16+
- name: "Publish Sonar JSON to Pixee"
17+
shell: bash
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
run: |
21+
PR_NUMBER=${{ join(github.event.check_run.pull_requests.*.number, '') }}
22+
URL="https://sonarcloud.io/api/issues/search?componentKeys=pixee_codemodder-python&resolved=false"
23+
24+
if [ -n "$PR_NUMBER" ]; then
25+
URL="${URL}&pullRequest=$PR_NUMBER"
26+
fi
27+
28+
curl -v "$URL" -o sonar_issues.json
29+
cat sonar_issues.json
30+
ANALYSIS_SHA=${{ github.event.check_run.head_sha }}
31+
SECRET=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=https://app.pixee.ai" | jq -j '.value')
32+
API_RESPONSE=$(curl -v -X PUT -H "Authorization: Bearer $SECRET" -H "Content-Type: multipart/form-data" -F "file=@sonar_issues.json" "https://api.pixee.ai/analysis-input/pixee/codemodder-python/$ANALYSIS_SHA/sonar")
33+
echo "$API_RESPONSE"
34+
35+
- name: "Trigger Pixee Analysis"
36+
if : ${{ toJson(github.event.check_run.pull_requests) != '[]' }}
37+
run: |
38+
SECRET=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=https://app.pixee.ai" | jq -j '.value')
39+
API_RESPONSE=$(curl -v -X POST -H "Authorization: Bearer $SECRET" "https://api.pixee.ai/analysis-input/pixee/codemodder-python/${{ github.event.check_run.pull_requests[0].number }}")
40+
echo $API_RESPONSE

0 commit comments

Comments
 (0)