-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mykhailo
committed
Oct 15, 2024
1 parent
eae82fa
commit 966a9ea
Showing
3 changed files
with
236 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
--- | ||
name: build-and-check-python-package | ||
|
||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
path: | ||
description: Where to look for the Python package to inspect. | ||
required: false | ||
type: string | ||
default: . | ||
outputs: | ||
dist: | ||
description: The location of the built packages. | ||
value: ${{ jobs.build-package.outputs.dist }} | ||
|
||
|
||
jobs: | ||
build-package: | ||
name: Build and Verify package | ||
runs-on: ubuntu-latest | ||
outputs: | ||
dist: ${{ steps.setter.outputs.dist }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
id: python-bavp | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Create venv for tools | ||
run: ${{ steps.python-bavp.outputs.python-path }} -Im venv /tmp/bavp | ||
shell: bash | ||
|
||
- name: Install dependencies | ||
run: > | ||
/tmp/bavp/bin/python | ||
-Im pip | ||
--disable-pip-version-check | ||
--no-python-version-warning | ||
install build check-wheel-contents==0.6.0 twine==5.1.1 wheel==0.42.0 wheel-filename==1.4.1 | ||
shell: bash | ||
|
||
- name: Build package | ||
run: | | ||
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) | ||
/tmp/bavp/bin/python -m build --outdir /tmp/bavp/dist | ||
shell: bash | ||
working-directory: ${{ inputs.path }} | ||
|
||
- name: Set output | ||
id: setter | ||
run: echo "dist=/tmp/bavp/dist" >>$GITHUB_OUTPUT | ||
shell: bash | ||
working-directory: ${{ inputs.path }} | ||
|
||
- run: ls -l /tmp/bavp/dist | ||
shell: bash | ||
working-directory: ${{ inputs.path }} | ||
|
||
- name: Upload built artifacts. | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Packages | ||
path: /tmp/bavp/dist/* | ||
|
||
- run: /tmp/bavp/bin/check-wheel-contents /tmp/bavp/dist/*.whl | ||
shell: bash | ||
working-directory: ${{ inputs.path }} | ||
|
||
- name: Check PyPI README | ||
shell: bash | ||
working-directory: ${{ inputs.path }} | ||
run: > | ||
/tmp/bavp/bin/python | ||
-m twine check | ||
--strict | ||
/tmp/bavp/dist/* | ||
- name: Show wheel and SDist contents hierarchically, including metadata. | ||
shell: bash | ||
working-directory: ${{ inputs.path }} | ||
run: | | ||
cd /tmp/bavp/dist | ||
mkdir -p out/sdist | ||
mkdir -p out/wheels | ||
/tmp/bavp/bin/python -m wheel unpack --dest out/wheels *.whl | ||
tar xf *.tar.gz -C out/sdist | ||
echo -e '\n<details><summary>SDist contents</summary>\n' >> $GITHUB_STEP_SUMMARY | ||
(cd /tmp/bavp/dist/out/sdist && tree -Da --timefmt="%Y-%m-%dT%H:%M:%SZ" * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY) | ||
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY | ||
echo -e '\n<details><summary>Wheel contents</summary>\n' >> $GITHUB_STEP_SUMMARY | ||
(cd /tmp/bavp/dist/out/wheels && tree -Da --timefmt="%Y-%m-%dT%H:%M:%SZ" * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY) | ||
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY | ||
echo ----- Metadata Follows ----- | ||
echo -e '\n<details><summary>Metadata</summary>\n' >> $GITHUB_STEP_SUMMARY | ||
cat out/sdist/*/PKG-INFO | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY | ||
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY | ||
echo ----- End of Metadata ----- | ||
- name: Upload metadata | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Package Metadata | ||
path: /tmp/bavp/dist/out/sdist/*/PKG-INFO | ||
|
||
- name: Extract PyPI README | ||
shell: bash | ||
working-directory: /tmp/bavp/dist/out/sdist/ | ||
run: | | ||
cat */PKG-INFO | python -c ' | ||
import email.parser | ||
import sys | ||
em = email.parser.Parser().parsestr(sys.stdin.read()) | ||
suffix = { | ||
"text/markdown": "md", | ||
"text/x-rst": "rst", | ||
}[em["Description-Content-Type"]] | ||
with open(f"PyPI-README.{suffix}", "w") as f: | ||
f.write(em.get_payload()) | ||
' | ||
- name: Upload PyPI README | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: PyPI README | ||
path: /tmp/bavp/dist/out/sdist/PyPI-README.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: ci-for-build-and-tests | ||
|
||
on: | ||
push: | ||
branches: [ "feature/ci_implement_tests" ] | ||
pull_request: | ||
branches: [ "main", "develop" ] | ||
|
||
jobs: | ||
# build-package: | ||
# uses: ./.github/workflows/build-and-check-python-package.yml | ||
# with: | ||
# path: ./r8s | ||
|
||
tests: | ||
# needs: build-package | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Check modified files | ||
id: check_files | ||
run: | | ||
git fetch origin ${{ github.pull_request_target }} | ||
changed_files=$(git diff --name-only origin/main) #${{ github.pull_request_target }} | ||
echo "Changed files: ${changed_files}" | ||
checked_directory="r8s/" | ||
for file in ${changed_files} | ||
do | ||
if [[ ${file} == ${checked_directory}* ]] | ||
then | ||
echo "Target directory was modified." | ||
echo "changes_found=true" >>$GITHUB_OUTPUT | ||
exit 0 | ||
fi | ||
done | ||
echo "Target directory was not modified." | ||
echo "changes_found=false" >>$GITHUB_OUTPUT | ||
echo "dist=/tmp/bavp/dist" >>$GITHUB_OUTPUT | ||
shell: bash | ||
|
||
|
||
- name: Setup test env | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
run: | | ||
python -VV | ||
pip install virtualenv | ||
virtualenv .venv | ||
source .venv/bin/activate | ||
pip install tox | ||
- name: tests | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
run: tox -e py310-lambdas | ||
|
||
- name: Upload coverage report | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: lambdas-coverage-report | ||
path: coverage.xml | ||
retention-days: 1 | ||
|
||
- name: Upload test report | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: lambdas-test-report | ||
path: report.xml | ||
retention-days: 1 | ||
|
||
- name: docker-tests | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
run: tox -e py310-docker | ||
|
||
- name: Upload coverage report | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: docker-coverage-report | ||
path: coverage.xml | ||
retention-days: 1 | ||
|
||
- name: Upload test report | ||
if: steps.check_files.outputs.changes_found == 'true' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: docker-test-report | ||
path: report.xml | ||
retention-days: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,35 @@ | ||
[tox] | ||
envlist = lint,py38,py310,coverage-report | ||
envlist = py310 | ||
skipsdist = True | ||
isolated_build = False | ||
skip_install = True | ||
|
||
|
||
[pytest] | ||
python_files = test_*.py, tests_*.py | ||
norecursedirs = scripts docs pics | ||
norecursedirs = scripts docs | ||
|
||
|
||
[testenv] | ||
setenv = | ||
AWS_REGION=eu-central-1 | ||
|
||
|
||
[testenv:py38-lambdas] | ||
[testenv:py310-lambdas] | ||
deps = | ||
-rtests/requirements-test.txt | ||
-e./mcdm_sdk | ||
pytest | ||
pytest-cov | ||
install_command = python -m pip install --no-compile {packages} | ||
commands = | ||
pytest tests/ -v --cov=src --cov-report term-missing --cov-report xml:coverage.xml --junitxml=report.xml | ||
|
||
|
||
[testenv:py38-docker] | ||
[testenv:py310-docker] | ||
deps = | ||
-rdocker/requirements-dev.txt | ||
-e./mcdm_sdk | ||
pytest | ||
pytest-cov | ||
install_command = python -m pip install --no-compile {packages} | ||
commands = | ||
pytest docker/tests_executor/ -v --cov=docker --cov-report term-missing --cov-report xml:coverage.xml --junitxml=report.xml | ||
|
||
|
||
[testenv:py310] | ||
commands = | ||
coverage run -m pytest --junitxml=report.xml tests/ -v {posargs} | ||
coverage report | ||
coverage xml | ||
|
||
|
||
[testenv:coverage-report] | ||
basepython = python3.8 | ||
depends = py38 | ||
skip_install = true | ||
commands = | ||
coverage combine | ||
coverage report | ||
coverage xml | ||
|
||
|
||
[testenv:lint] | ||
deps = | ||
flake8 | ||
commands = | ||
flake8 ./ {env:M3_ADMIN_HOME}/lowlevel {env:M3_ADMIN_HOME}/private {env:M3_ADMIN_HOME}/billing | ||
|
||
[flake8] | ||
exclude = setup.py,.git,.venv*,venv,python2.7,.tox,scripts,pics,docs,build,report_commands_to_tables_script | ||
; W291 trailing whitespace | ||
; E501 line too long | ||
; W504 line break after binary operator | ||
; W503 line break before binary operator | ||
; E251 unexpected spaces around keyword / parameter equals | ||
; W605 invalid escape sequence '\/' | ||
; E741 ambiguous variable name 'l' | ||
; E126 continuation line over-indented for hanging indent | ||
; E127 continuation line over-indented for visual indent | ||
; F811 redefinition of unused # remove when mobile-team synchronize its part after our renaming of parameters in commands | ||
; F841 local variable '_LOG' is assigned to but never used | ||
; E121 continuation line under-indented for hanging indent | ||
ignore = W291,W503,W504,E251,W605,E741,E126,E127,F811,E501,F841, E121 | ||
max-line-length = 82 | ||
|
||
|
||
[testenv:pylint] | ||
deps = | ||
pylint | ||
commands = | ||
pylint --rcfile=tox.ini {toxinidir} {env:R8S_HOME}/src {env:R8S_HOME}/docker {env:R8S_HOME}/scripts | ||
|
||
[MESSAGES CONTROL] | ||
; C0111 Missing docstring | ||
; I0011: Locally disabling %s | ||
; I0012: Locally enabling %s | ||
; W0704 Except doesn't do anything Used when an except clause does nothing but "pass" and there is no "else" clause | ||
; W0142 Used * or * magic* Used when a function or method is called using *args or **kwargs to dispatch arguments. | ||
; W0212 Access to a protected member %s of a client class | ||
; W0232 Class has no __init__ method Used when a class has no __init__ method, neither its parent classes. | ||
; W0613 Unused argument %r Used when a function or method argument is not used. | ||
; W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch. | ||
; R0201 Method could be a function | ||
; W0614 Unused import XYZ from wildcard import | ||
; R0903 Too few public methods | ||
; R0904 Too many public methods | ||
; R0914 Too many local variables | ||
; R0912 Too many branches | ||
; R0915 Too many statements | ||
; R0913 Too many arguments | ||
; R0923: Interface not implemented | ||
disable = I0011,I0012,C0111,W0142,R0913 |