diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 64bbd401..456e91c8 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -1,8 +1,12 @@ ---- name: Reusable lint and test workflow for Python projects on: workflow_call: + inputs: + skip-coverage: + required: false + type: string + default: 'false' permissions: actions: read @@ -31,10 +35,8 @@ jobs: - name: Lint with ruff run: | - # stop the build if there are Python syntax errors or undefined - # names - ruff --output-format=github --select=E9,F63,F7,F82 \ - --target-version=py311 . + # stop the build if there are Python syntax errors or undefined names + ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py311 . # default set of ruff rules with GitHub Annotations ruff --output-format=github --target-version=py311 . @@ -42,10 +44,11 @@ jobs: with: secrets: ${{ toJSON(secrets) }} - - name: Test with unittest + - name: Test with pytest run: | - python -m unittest discover -s tests + python -m pytest - name: Run tests with coverage (coverage must be at least 80% to pass) + if: inputs.skip-coverage != 'true' run: | - pytest --cov=. --cov-fail-under=80 tests/ # default value, coverage must be at least 80% + python -m pytest --cov=. --cov-fail-under=80 diff --git a/.github/workflows/workflow-version-bump-python.md b/.github/workflows/workflow-version-bump-python.md new file mode 100644 index 00000000..1bece79c --- /dev/null +++ b/.github/workflows/workflow-version-bump-python.md @@ -0,0 +1,14 @@ +# Reusable version bump check validation workflow for Python projects + +- **Purpose:** Validate the version bump in a Python project. +- **Usage:** Call this workflow in your Python projects. + + ```yaml + lint-test: + uses: + ai-cfia/github-workflows/.github/workflows/workflow-version-bump-python.yml@main + secrets: inherit + with: + pyproject-path: 'pyproject.toml' + package-name: 'my-package' + ``` diff --git a/.github/workflows/workflow-version-bump-python.yml b/.github/workflows/workflow-version-bump-python.yml new file mode 100644 index 00000000..c01032ba --- /dev/null +++ b/.github/workflows/workflow-version-bump-python.yml @@ -0,0 +1,49 @@ +name: Reusable version bump check validation workflow for Python projects + + +on: + workflow_call: + inputs: + pyproject-path: + required: false + type: string + package-name: + required: false + type: string + +jobs: + version-bump-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Parse new version from pyproject.toml + id: parse_new_version + run: | + new_version=$(grep -Po '(?<=^version = ")[^"]*' ${{ inputs.pyproject-path }}) + echo "new_version=$new_version" >> $GITHUB_ENV + + - name: Get latest version + id: get_latest_version + run: | + package_name="${{ inputs.package-name }}" + latest_tag=$(git tag --list "v*-*${package_name}" --sort=-creatordate | head -n 1) + latest_version=$(echo $latest_tag | grep -oP '(?<=v)[0-9]+\.[0-9]+\.[0-9]+') + echo "latest_version=$latest_version" >> $GITHUB_ENV + + - name: Check version bump + run: | + if [ "${{ env.new_version }}" == "${{ env.latest_version }}" ]; then + echo "Version has not been bumped!" + exit 1 + else + echo "Version has been bumped." + fi