diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ccc1653c..dc251d00 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,24 +1,119 @@ name: Release Pytest agent on: - release: - types: [published] + push: + branches: ['master'] + paths-ignore: + - '.github/**' + - CHANGELOG.md + - README.rst + - CONTRIBUTING.rst + +env: + VERSION_FILE: setup.py + VERSION_EXTRACT_PATTERN: >- + __version__\s*=\s*'([^']+) + VERSION_REPLACE_PATTERN: >- + __version__ = '\1' + TMP_SUFFIX: _updated + CHANGE_LOG_FILE: CHANGELOG.md jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.6' - - name: Install dependencies - run: python -m pip install --upgrade pip setuptools wheel - - name: Build package - run: python setup.py sdist bdist_wheel - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: ${{ secrets.PYPI_USERNAME }} - password: ${{ secrets.PYPI_PASSWORD }} + - uses: actions/checkout@v2 + + - name: Generate versions + uses: HardNorth/github-version-generate@v1.1.2 + with: + version-source: file + version-file: ${{ env.VERSION_FILE }} + version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }} + + - name: Setup git credentials + uses: oleksiyrudenko/gha-git-credentials@v2 + with: + name: 'reportportal.io' + email: 'support@reportportal.io' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Tagging new version + id: newVersionTag + run: | + git tag -a ${{ env.RELEASE_VERSION }} -m "Release ${{ env.RELEASE_VERSION }}" + git push --tags + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6' + + - name: Install dependencies + run: python -m pip install --upgrade pip setuptools wheel + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: ${{ secrets.PYPI_USERNAME }} + password: ${{ secrets.PYPI_PASSWORD }} + + - name: Checkout develop branch + uses: actions/checkout@v2 + with: + ref: 'develop' + fetch-depth: 0 + + - name: Update CHANGELOG.md + id: changelogUpdate + run: | + sed '/\[Unreleased\]/q' ${{ env.CHANGE_LOG_FILE }} >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} + sed -E '1,/#?#\s*\[Unreleased\]/d' ${{ env.CHANGE_LOG_FILE }} | sed -E '/#?#\s*\[/q' | \ + { echo -e '\n## [${{ env.RELEASE_VERSION }}]'; sed '$d'; } >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} + grep -E '#?#\s*\[[0-9]' ${{ env.CHANGE_LOG_FILE }} | head -n1 >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} + sed -E '1,/#?#\s*\[[0-9]/d' ${{ env.CHANGE_LOG_FILE }} >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} + rm ${{ env.CHANGE_LOG_FILE }} + mv ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} ${{ env.CHANGE_LOG_FILE }} + git add ${{ env.CHANGE_LOG_FILE }} + git commit -m "Changelog update" + + - name: Read changelog Entry + id: readChangelogEntry + uses: mindsers/changelog-reader-action@v1.3.1 + with: + version: ${{ env.RELEASE_VERSION }} + path: ./${{ env.CHANGE_LOG_FILE }} + + - name: Create Release + id: createRelease + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.RELEASE_VERSION }} + release_name: Release ${{ env.RELEASE_VERSION }} + body: ${{ steps.readChangelogEntry.outputs.log_entry }} + draft: false + prerelease: false + + - name: Merge release branch into develop + id: mergeIntoDevelop + run: | + git merge -m 'Merge master branch into develop after a release' origin/master + git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \ + | { echo -e 'Unable to merge master into develop, merge conflicts:'; (! grep -Eo '[^ ]+$') } + + - name: Update version file + id: versionFileUpdate + run: | + export CURRENT_VERSION_VALUE=`echo '${{ env.CURRENT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'` + export NEXT_VERSION_VALUE=`echo '${{ env.NEXT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'` + sed "s/${CURRENT_VERSION_VALUE}/${NEXT_VERSION_VALUE}/g" ${{ env.VERSION_FILE }} > ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} + rm ${{ env.VERSION_FILE }} + mv ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} ${{ env.VERSION_FILE }} + git add ${{ env.VERSION_FILE }} + git commit -m "Version update" + git push diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e5fc22bb..b37ec457 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [2.7, 3.5, 3.6, 3.7, 3.8] + python-version: [2.7, 3.6, 3.7, 3.8, 3.9, '3.10'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..36d2f762 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +## [Unreleased] +### Fixed +- Issue [#304](https://github.com/reportportal/agent-python-pytest/issues/304): +SSL certificate flag handling issue, by @HardNorth + +## [5.1.0] +### Changed +- Agent complete rewrite, by @HardNorth diff --git a/pytest_reportportal/config.py b/pytest_reportportal/config.py index 5b7b1e74..0a11a2d3 100644 --- a/pytest_reportportal/config.py +++ b/pytest_reportportal/config.py @@ -1,5 +1,6 @@ """This module contains class that stores RP agent configuration data.""" +from distutils.util import strtobool from os import getenv try: @@ -64,7 +65,11 @@ def __init__(self, pytest_config): 'true', '1', 'yes', 'y') self.rp_uuid = getenv('RP_UUID') or self.find_option(pytest_config, 'rp_uuid') - self.rp_verify_ssl = self.find_option(pytest_config, 'rp_verify_ssl') + rp_verify_ssl = self.find_option(pytest_config, 'rp_verify_ssl', True) + try: + self.rp_verify_ssl = bool(strtobool(rp_verify_ssl)) + except (ValueError, AttributeError): + self.rp_verify_ssl = rp_verify_ssl # noinspection PyMethodMayBeStatic def find_option(self, pytest_config, option_name, default=None): @@ -85,4 +90,6 @@ def find_option(self, pytest_config, option_name, default=None): getattr(pytest_config.option, option_name, None) or pytest_config.getini(option_name) ) + if isinstance(value, bool): + return value return value if value else default diff --git a/pytest_reportportal/config.pyi b/pytest_reportportal/config.pyi index 54c896bf..b90a635d 100644 --- a/pytest_reportportal/config.pyi +++ b/pytest_reportportal/config.pyi @@ -1,5 +1,5 @@ from _pytest.config import Config as Config -from typing import List, Optional, Text, Union +from typing import List, Optional, Text, Union, Any class AgentConfig: rp_rerun: Optional[bool] = ... @@ -28,8 +28,9 @@ class AgentConfig: rp_retries: int = ... rp_skip_connection_test: bool = ... rp_uuid: Text = ... - rp_verify_ssl: bool = ... + rp_verify_ssl: Union[bool, Text] = ... def __init__(self, pytest_config: Config) -> None: ... - def find_option(self, pytest_config, param: Text) -> Union[Text, bool, list]: ... + def find_option(self, pytest_config, param: Text, + default: Any = ...) -> Union[Text, bool, list]: ... diff --git a/setup.py b/setup.py index 06caa7ae..91beab6d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup -__version__ = '5.1.0' +__version__ = '5.1.1' def read_file(fname): @@ -33,10 +33,11 @@ def read_file(fname): classifiers=[ 'Framework :: Pytest', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8' + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10' ], entry_points={ 'pytest11': [ diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py new file mode 100644 index 00000000..900a8405 --- /dev/null +++ b/tests/unit/test_config.py @@ -0,0 +1,36 @@ +# Copyright (c) 2022 https://reportportal.io . +# 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 +# +# https://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 + +import pytest +from pytest_reportportal.config import AgentConfig + + +@pytest.mark.parametrize( + ['verify_ssl', 'expected_result'], + [ + ('True', True), + ('False', False), + ('true', True), + ('false', False), + (True, True), + (False, False), + ('path/to/certificate', 'path/to/certificate'), + (None, True) + ] +) +def test_verify_ssl_true(mocked_config, verify_ssl, expected_result): + mocked_config.getini.side_effect = \ + lambda x: verify_ssl if x == 'rp_verify_ssl' else None + config = AgentConfig(mocked_config) + + assert config.rp_verify_ssl == expected_result