Skip to content

Add CD action for macOS platform #208

Add CD action for macOS platform

Add CD action for macOS platform #208

name: Contribution Evaluation
on:
pull_request_target:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
# Job 1: Workload Analysis
workload-analysis:
runs-on: ubuntu-latest
concurrency:
group: "workload-analysis-${{ github.event.pull_request.number }}"
cancel-in-progress: true # Don't cancel in-progress jobs
permissions:
pull-requests: write
steps:
- name: Checkout target branch code (using pull_request_target)
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: pip install requests lizard
- name: Run workload analysis script
id: analyze_workload
run: |
git clone https://github.com/TSGU-OSC/OpenRate.git
python OpenRate/scripts/workload_analyzation.py \
--owner ${{ github.repository_owner }} \
--repo ${{ github.event.repository.name }} \
--pr-number ${{ github.event.number }} \
--token ${{ secrets.GITHUB_TOKEN }}
workload=$(grep "Estimated workload" workload_output.txt | awk -F': ' '{print $2}')
changedLines=$(grep "Estimated changedLine" workload_output.txt | awk -F': ' '{print $2}')
# Output the values for the next job
echo "workload=$workload" >> $GITHUB_OUTPUT
echo "changedLines=$changedLines" >> $GITHUB_OUTPUT
- name: Post or Update PR Comment
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('workload_output.txt', 'utf8');
// Print the output to the logs for debugging
console.log('Workload analysis output:', output);
const marker = '<!-- contribution-evaluation-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### Workload Analysis:\n${output}\n### SonarQube Analysis Status:\nCode quality analysis is still in progress...`;
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
});
}
# Job 2: SonarQube Analysis
sonarqube-analysis:
runs-on: ubuntu-20.04
concurrency:
group: "sonarqube-analysis-${{ github.event.pull_request.number }}"
cancel-in-progress: true # Don't cancel in-progress jobs
needs: workload-analysis # Ensure this job runs after workload analysis
env:
BUILD_WRAPPER_OUT_DIR: src/build
steps:
- name: Checkout target branch code (using pull_request_target)
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Fetch and checkout PR branch
run: |
git remote add pr_origin https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git fetch pr_origin ${{ github.event.pull_request.head.ref }}:pr_branch
git checkout pr_branch
- name: Print current branch and commit hash
run: |
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Current commit hash: $(git rev-parse HEAD)"
- 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 nasm yasm libx264-dev libx265-dev libnuma-dev
sudo apt install -y python3.9 python3-dev python3-pip libsndfile1 libsndfile1-dev
git clone https://github.com/JackLau1222/bmf.git
- name: Cache FFmpeg build
uses: actions/cache@v3
with:
path: |
ffmpeg
key: ${{ runner.os }}-ffmpeg-${{ hashFiles('bmf/scripts/build_ffmpeg.sh') }}
restore-keys: |
${{ runner.os }}-ffmpeg-linux-x86
- 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-linux-x86
- name: Compile FFmpeg if not cached
run: |
if [ ! -d "$(pwd)/ffmpeg" ]; then
echo "FFmpeg not found, starting build..."
wget https://ffmpeg.org/releases/ffmpeg-5.1.6.tar.bz2 && tar xjvf ffmpeg-5.1.6.tar.bz2
(cd ffmpeg-5.1.6 && ./configure --pkg-config-flags=--static --enable-shared --disable-static --extra-libs=-lpthread --extra-libs=-lm --enable-gpl --enable-nonfree --enable-libx264 --enable-libx265 --prefix=../ffmpeg)
(cd ffmpeg-5.1.6 && make -j$(nproc) && make install)
else
echo "FFmpeg is already installed, skipping build."
fi
echo "FFMPEG_ROOT_PATH=$(pwd)/ffmpeg" >> $GITHUB_ENV
- name: Set up BMF if not cached
run: |
if [ ! -d "$(pwd)/bmf/output/" ]; then
(cd bmf && git checkout fork_by_oc && ./build.sh)
else
echo "BMF is already installed, skipping build."
fi
echo "BMF_ROOT_PATH=$(pwd)/bmf/output/bmf" >> $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: |
export PATH=$PATH:$FFMPEG_ROOT_PATH/bin
(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
cat ${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
- 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.pullrequest.key=${{ github.event.pull_request.number }}
--define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
--define sonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
--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: |
git clone https://github.com/TSGU-OSC/OpenRate.git
python OpenRate/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: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
- name: Update PR comment with SonarQube result
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const sonarOutput = fs.readFileSync('code_quality_output.txt', 'utf8');
const marker = '<!-- contribution-evaluation-comment -->';
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});
// const sonarStatus = process.env.SONAR_STATUS || "Code quality analysis is still in progress...";
const workload = '${{ needs.workload-analysis.outputs.workload }}';
const changedLines = '${{ needs.workload-analysis.outputs.changedLines }}';
// Print workload and changedLines for debugging
console.log('Sonar Output:', sonarOutput);
const existingComment = comments.data.find(comment => comment.body.includes(marker));
// If the comment exists, update it, otherwise create a new one
let combinedBody;
if (existingComment) {
// Split the existing comment body into lines
let lines = existingComment.body.split('\n');
// Modify only the last line
const lastLine = lines[lines.length - 1];
// Replace the last two line with the new information
lines[lines.length - 2] = `### SonarQube Analysis Result:`;
lines[lines.length - 1] = sonarOutput;
// Reassemble the comment body
combinedBody = lines.join('\n');
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: combinedBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: combinedBody
});
}