Skip to content

Commit

Permalink
Merge pull request #203 from rtdip/develop
Browse files Browse the repository at this point in the history
v0.2.2
  • Loading branch information
cching95 authored Apr 28, 2023
2 parents 1496026 + 4fdf52b commit 89189aa
Show file tree
Hide file tree
Showing 62 changed files with 1,081 additions and 253 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"python.testing.pytestEnabled": true,
"python.testing.cwd": "${workspaceFolder}",
"python.analysis.extraPaths": ["${workspaceFolder}"],
"python.defaultInterpreterPath": "~/micromamba/envs/rtdip-sdk/bin/python",
// "python.defaultInterpreterPath": "~/micromamba/envs/rtdip-sdk/bin/python",
"terminal.integrated.env.linux":{
"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}"
},
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ on:
- develop

jobs:
job_run_unit_tests_and_sonarqube:
job_run_unit_tests_previous_versions:
uses: rtdip/core/.github/workflows/test.yml@develop

job_run_unit_tests_and_sonarqube:
uses: rtdip/core/.github/workflows/sonarcloud_reusable.yml@develop
with:
REPO_NAME: ""
HEAD_BRANCH: ""
HEAD_SHA: ""
PR_NUMBER: ""
PR_HEAD_REF: ""
PR_BASE_REF: ""
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

job_build_python_package_and_docker_container:
runs-on: ubuntu-latest
needs: job_run_unit_tests_and_sonarqube
needs: [job_run_unit_tests_and_sonarqube, job_run_unit_tests_previous_versions]
permissions:
packages: write
contents: read
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ on:
- main

jobs:
job_run_unit_tests_and_sonarqube:
job_run_unit_tests_previous_versions:
uses: rtdip/core/.github/workflows/test.yml@main

job_run_unit_tests_and_sonarqube:
uses: rtdip/core/.github/workflows/sonarcloud_reusable.yml@main
with:
REPO_NAME: ""
HEAD_BRANCH: ""
HEAD_SHA: ""
PR_NUMBER: ""
PR_HEAD_REF: ""
PR_BASE_REF: ""
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
28 changes: 25 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,29 @@ on:
types: [opened, synchronize, reopened]

jobs:
job_run_unit_tests_and_sonarqube:
job_run_unit_tests:
uses: rtdip/core/.github/workflows/test.yml@develop
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

job_pr_artifact:
needs: job_run_unit_tests
defaults:
run:
shell: bash -l {0}
runs-on: ubuntu-latest
steps:
- name: Save PR number to file
env:
PR_NUMBER: ${{ github.event.number }}
PR_HEAD_REF: ${{ github.head_ref }}
PR_BASE_REF: ${{ github.base_ref }}
run: |
JSON_FMT='{"pr_number":"%s","pr_head_ref":"%s","pr_base_ref":"%s"}\n'
mkdir -p ./pr
printf "$JSON_FMT" "$PR_NUMBER" "$PR_HEAD_REF" "$PR_BASE_REF" > ./pr/pr_number
- name: Upload PR Json
uses: actions/upload-artifact@v3
with:
name: pr_number
path: pr/
retention-days: 5
6 changes: 0 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ on:
types: [published]

jobs:
job_run_unit_tests_and_sonarqube:
uses: rtdip/core/.github/workflows/test.yml@main
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

job_build_python_whl:
runs-on: ubuntu-latest
needs: job_run_unit_tests_and_sonarqube
steps:
- uses: actions/checkout@v3
- name: Setup Python
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2022 RTDIP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: 'Sonarcloud Scan'

run-name: ${{ github.event.workflow_run.display_title }}

on:
workflow_run:
workflows: [PR]
types: [requested]
branches-ignore:
- "develop"
- "main"
- "release/**"

jobs:
job_download_pr_artifact:
outputs:
pr_info: ${{ steps.pr.outputs.result }}
runs-on: ubuntu-latest
steps:
- name: 'Download Artifact'
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 == "pr_number"
})[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}/pr_number.zip`, Buffer.from(download.data));
- name: 'Unzip Artifact'
run: unzip pr_number.zip

- name: 'Read Artifact'
id: pr
uses: actions/github-script@v6
with:
script: |
let fs = require('fs');
return fs.readFileSync('./pr_number');
result-encoding: string

job_run_unit_tests_and_sonarqube:
needs: job_download_pr_artifact
uses: rtdip/core/.github/workflows/sonarcloud_reusable.yml@develop
with:
REPO_NAME: ${{ github.event.workflow_run.head_repository.full_name }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
PR_NUMBER: ${{ fromJSON(needs.job_download_pr_artifact.outputs.pr_info).pr_number }}
PR_HEAD_REF: ${{ fromJSON(needs.job_download_pr_artifact.outputs.pr_info).pr_head_ref }}
PR_BASE_REF: ${{ fromJSON(needs.job_download_pr_artifact.outputs.pr_info).pr_base_ref }}
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
108 changes: 108 additions & 0 deletions .github/workflows/sonarcloud_reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright 2022 RTDIP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: 'Reusable Sonarcloud Scan'

on:
workflow_call:
inputs:
REPO_NAME:
required: true
type: string
HEAD_BRANCH:
required: true
type: string
HEAD_SHA:
required: true
type: string
PR_NUMBER:
required: true
type: string
PR_HEAD_REF:
required: true
type: string
PR_BASE_REF:
required: true
type: string
secrets:
SONAR_TOKEN:
required: true

jobs:
job_test_python_latest_version:
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
repository: ${{ inputs.REPO_NAME }}
ref: ${{ inputs.HEAD_BRANCH }}
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install Boost
run: |
sudo apt update
sudo apt install -y libboost-all-dev
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install Conda environment with Micromamba
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment.yml
cache-env: true

- name: Test
run: |
mkdir -p coverage-reports
coverage run -m pytest --junitxml=xunit-reports/xunit-result-unitttests.xml tests && tests_ok=true
coverage xml --omit "venv/**,maintenance/**,xunit-reports/**" -i -o coverage-reports/coverage-unittests.xml
echo Coverage `coverage report --omit "venv/**" | grep TOTAL | tr -s ' ' | cut -d" " -f4`
- name: Mkdocs Test
run: |
mkdocs build --strict
- name: Override Coverage Source Path for Sonar
run: |
sed -i "s/<source>\/home\/runner\/work\/core\/core<\/source>/<source>\/github\/workspace<\/source>/g" /home/runner/work/core/core/coverage-reports/coverage-unittests.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=rtdip
-Dsonar.projectKey=rtdip_core
-Dsonar.python.coverage.reportPaths=coverage-reports/coverage-unittests.xml
-Dsoner.python.version=3.11
-Dsonar.scm.revision=${{ inputs.HEAD_SHA }}
-Dsonar.pullrequest.key=${{ inputs.PR_NUMBER }}
-Dsonar.pullrequest.branch=${{ inputs.PR_HEAD_REF }}
-Dsonar.pullrequest.base=${{ inputs.PR_BASE_REF }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
70 changes: 0 additions & 70 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,8 @@ name: 'Reusable Test Workflow'

on:
workflow_call:
secrets:
SONAR_TOKEN:
required: true

jobs:
job_test_python_latest_version:
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install Boost
run: |
sudo apt update
sudo apt install -y libboost-all-dev
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install Conda environment with Micromamba
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment.yml
cache-env: true

- name: Test
run: |
python setup.py pytest
mkdir -p coverage-reports
coverage run -m pytest --junitxml=xunit-reports/xunit-result-unitttests.xml tests && tests_ok=true
coverage xml --omit "venv/**,maintenance/**,xunit-reports/**" -i -o coverage-reports/coverage-unittests.xml
echo Coverage `coverage report --omit "venv/**" | grep TOTAL | tr -s ' ' | cut -d" " -f4`
env:
RTDIP_SDK_NEXT_VER: "0.0.1"

- name: Mkdocs Test
run: |
mkdocs build --strict
- name: Override Coverage Source Path for Sonar
run: |
sed -i "s/<source>\/home\/runner\/work\/core\/core<\/source>/<source>\/github\/workspace<\/source>/g" /home/runner/work/core/core/coverage-reports/coverage-unittests.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=rtdip
-Dsonar.projectKey=rtdip_core
-Dsonar.python.coverage.reportPaths=coverage-reports/coverage-unittests.xml
-Dsoner.python.version=3.11
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

job_test_python_previous_version:
defaults:
run:
Expand Down Expand Up @@ -122,10 +55,7 @@ jobs:

- name: Test
run: |
python setup.py pytest
mkdir -p coverage-reports-previous
coverage run -m pytest --junitxml=xunit-reports/xunit-result-unitttests.xml tests && tests_ok=true
coverage xml --omit "venv/**,maintenance/**,xunit-reports/**" -i -o coverage-reports-previous/coverage-unittests.xml
echo Coverage `coverage report --omit "venv/**" | grep TOTAL | tr -s ' ' | cut -d" " -f4`
env:
RTDIP_SDK_NEXT_VER: "0.0.1"
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"python.testing.pytestEnabled": true,
"python.testing.cwd": "${workspaceFolder}",
"python.analysis.extraPaths": ["${workspaceFolder}"],
"python.defaultInterpreterPath": "~/micromamba/envs/rtdip-sdk/bin/python",
// "python.defaultInterpreterPath": "~/micromamba/envs/rtdip-sdk/bin/python",
"terminal.integrated.env.osx":{
"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}"
},
Expand Down
Loading

0 comments on commit 89189aa

Please sign in to comment.