Skip to content

Add contribution evaluation github action #25

Add contribution evaluation github action

Add contribution evaluation github action #25

Workflow file for this run

name: SonarQube PR Analysis
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "**" ]
jobs:
sonarqube:
name: SonarQube Scan
runs-on: ubuntu-20.04
env:
BUILD_WRAPPER_OUT_DIR: src/build
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Post "still analyzing" comment to PR
uses: actions/github-script@v6
with:
script: |
const marker = '<!-- sonar-analysis-comment -->';
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});
const existingComment = comments.data.find(comment => comment.body.includes(marker));
const stillAnalyzingBody = `${marker}\nCode quality analysis is still in progress... Please wait.`;
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: stillAnalyzingBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: stillAnalyzingBody
});
}
- name: Checkout BMF repository (specific branch)
run: |
sudo apt update
sudo apt install -y make git pkg-config libssl-dev cmake binutils-dev libgoogle-glog-dev gcc g++ golang wget libgl1
sudo apt install -y python3.9 python3-dev python3-pip libsndfile1 libsndfile1-dev
# sudo python3 -m pip install timeout_decorator numpy onnxruntime pytest opencv-python librosa
git clone https://github.com/JackLau1222/bmf.git
# - name: Cache FFmpeg build
# uses: actions/cache@v3
# with:
# path: |
# /usr/local/bin/ffmpeg
# /usr/local/lib/
# /usr/local/include/
# key: ${{ runner.os }}-ffmpeg-${{ hashFiles('bmf/scripts/build_ffmpeg.sh') }}
# restore-keys: |
# ${{ runner.os }}-ffmpeg-
# - name: Cache BMF build
# uses: actions/cache@v3
# with:
# path: bmf/output/
# key: ${{ runner.os }}-bmf-${{ hashFiles('bmf/build.sh') }}
# restore-keys: |
# ${{ runner.os }}-bmf-
- name: Compile FFmpeg and BMF if not cached
run: |
if [ ! -f "/usr/local/bin/ffmpeg" ]; then
echo "FFmpeg not found, starting build..."
(cd bmf && git checkout fork_by_oc && sudo scripts/build_ffmpeg.sh nasm yasm x264 x265 opus && ./build.sh )
else
echo "FFmpeg is already installed, skipping build."
fi
- name: Set up BMF
run: |
cd bmf
echo "C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include" >> $GITHUB_ENV
echo "CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include" >> $GITHUB_ENV
echo "LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib" >> $GITHUB_ENV
- name: Set up Qt
run: |
sudo apt-get install -y qt5-qmake qtbase5-dev qtchooser qtbase5-dev-tools cmake build-essential
- name: Install Build Wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v4
- name: Run Build Wrapper
run: |
(cd src && mkdir build && cmake -S . -B build)
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build src/build/ --config Release
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v4
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
--define sonar.coverage.exclusions=**/*
--define sonar.coverage.reportPaths=
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: pip install requests
- name: Run code quality analysis script
id: analyze_workload
run: |
python scripts/quality_rate.py \
--owner ${{ github.repository_owner }} \
--repo ${{ github.event.repository.name }} \
--pr-number ${{ github.event.number }} \
--token ${{ secrets.SONAR_TOKEN }} \
--output-type RATE > code_quality_output.txt
cat code_quality_output.txt
- name: Post or Update PR Comment
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('code_quality_output.txt', 'utf8');
const marker = '<!-- sonar-analysis-comment -->';
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});
const existingComment = comments.data.find(comment => comment.body.includes(marker));
const newBody = `${marker}\n${output}`;
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: newBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: newBody
});
}