From 6b2ffecb6c5a23f6831e27d1ef96c347bd72d4cd Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 09:50:27 -0400 Subject: [PATCH 01/24] Issue #141: adds jobs for validating version bump --- .../workflows/workflow-lint-test-python.yml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 64bbd401..5e86595a 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -3,6 +3,13 @@ name: Reusable lint and test workflow for Python projects on: workflow_call: + inputs: + pyproject-path: + required: false + type: string + package-name: + required: false + type: string permissions: actions: read @@ -49,3 +56,35 @@ jobs: - name: Run tests with coverage (coverage must be at least 80% to pass) run: | pytest --cov=. --cov-fail-under=80 tests/ # default value, coverage must be at least 80% + + version-bump-check: + runs-on: ubuntu-latest + if: inputs.pyproject-path != '' + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Parse version from pyproject.toml + id: parse_version + run: | + version=$(grep -Po '(?<=^version = ")[^"]*' ${{ inputs.pyproject-path }}) + echo "version=$version" >> $GITHUB_ENV + + - name: Get latest tag + id: get_latest_tag + run: | + latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) + echo "latest_tag=$latest_tag" >> $GITHUB_ENV + + - name: Check version bump + run: | + if [ "$version" == "$latest_tag" ]; then + echo "Version has not been bumped!" + exit 1 + else + echo "Version has been bumped." + fi From 0205af2ab12c28f15d4493c428a347945521c772 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 09:52:07 -0400 Subject: [PATCH 02/24] Issue #141: yaml lint --- .../workflows/workflow-lint-test-python.yml | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 5e86595a..dce0a4e1 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -58,33 +58,33 @@ jobs: pytest --cov=. --cov-fail-under=80 tests/ # default value, coverage must be at least 80% version-bump-check: - runs-on: ubuntu-latest - if: inputs.pyproject-path != '' - steps: - - uses: actions/checkout@v3 + runs-on: ubuntu-latest + if: inputs.pyproject-path != '' + steps: + - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' - - name: Parse version from pyproject.toml - id: parse_version - run: | - version=$(grep -Po '(?<=^version = ")[^"]*' ${{ inputs.pyproject-path }}) - echo "version=$version" >> $GITHUB_ENV + - name: Parse version from pyproject.toml + id: parse_version + run: | + version=$(grep -Po '(?<=^version = ")[^"]*' ${{ inputs.pyproject-path }}) + echo "version=$version" >> $GITHUB_ENV - - name: Get latest tag - id: get_latest_tag - run: | - latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) - echo "latest_tag=$latest_tag" >> $GITHUB_ENV + - name: Get latest tag + id: get_latest_tag + run: | + latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) + echo "latest_tag=$latest_tag" >> $GITHUB_ENV - - name: Check version bump - run: | - if [ "$version" == "$latest_tag" ]; then - echo "Version has not been bumped!" - exit 1 - else - echo "Version has been bumped." - fi + - name: Check version bump + run: | + if [ "$version" == "$latest_tag" ]; then + echo "Version has not been bumped!" + exit 1 + else + echo "Version has been bumped." + fi From 7def3d3a41da70a5378d57d50d5f6bbba358ddfb Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 10:17:26 -0400 Subject: [PATCH 03/24] Issue #141: Fetch tags in checkout --- .github/workflows/workflow-lint-test-python.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index dce0a4e1..faccf931 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -62,6 +62,8 @@ jobs: if: inputs.pyproject-path != '' steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 From bd8a6c992c59a7a7e14f4a8d3373bec8fb55f7f7 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 10:20:07 -0400 Subject: [PATCH 04/24] Issue #141: Fetch tags in checkout with right key --- .github/workflows/workflow-lint-test-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index faccf931..9516a5f1 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -63,7 +63,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-tags: true - name: Set up Python uses: actions/setup-python@v4 From 95175dc58ac90ad24923409b5169e071861c386c Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 10:27:22 -0400 Subject: [PATCH 05/24] Issue #141: Fetch depth for all history --- .github/workflows/workflow-lint-test-python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 9516a5f1..2d2db4d3 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -64,6 +64,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-tags: true + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 From fa434f8cd4ac7e3710f1144017f5d6674f17d498 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 10:30:58 -0400 Subject: [PATCH 06/24] Issue #141: optional : provide path for test folder --- .github/workflows/workflow-lint-test-python.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 2d2db4d3..5e648800 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -10,6 +10,9 @@ on: package-name: required: false type: string + test-path: + required: false + type: string permissions: actions: read @@ -51,11 +54,13 @@ jobs: - name: Test with unittest run: | - python -m unittest discover -s tests + test_path="${{ inputs.test-path || 'tests' }}" + python -m unittest discover -s $test_path - name: Run tests with coverage (coverage must be at least 80% to pass) run: | - pytest --cov=. --cov-fail-under=80 tests/ # default value, coverage must be at least 80% + test_path="${{ inputs.test-path || 'tests' }}" + pytest --cov=. --cov-fail-under=80 $test_path # default value, coverage must be at least 80% version-bump-check: runs-on: ubuntu-latest From 21405ced084c4602f6cfc992fbb9695d8028a1a6 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 10:37:28 -0400 Subject: [PATCH 07/24] Issue #141: extract version from latest tag --- .../workflows/workflow-lint-test-python.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 5e648800..95dcc2ec 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -66,7 +66,7 @@ jobs: runs-on: ubuntu-latest if: inputs.pyproject-path != '' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-tags: true fetch-depth: 0 @@ -76,21 +76,22 @@ jobs: with: python-version: '3.11' - - name: Parse version from pyproject.toml - id: parse_version + - name: Parse new version from pyproject.toml + id: parse_new_version run: | - version=$(grep -Po '(?<=^version = ")[^"]*' ${{ inputs.pyproject-path }}) - echo "version=$version" >> $GITHUB_ENV + new_version=$(grep -Po '(?<=^version = ")[^"]*' ${{ inputs.pyproject-path }}) + echo "new_version=$new_version" >> $GITHUB_ENV - - name: Get latest tag - id: get_latest_tag + - name: Get latest version + id: get_latest_version run: | latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) - echo "latest_tag=$latest_tag" >> $GITHUB_ENV + 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 [ "$version" == "$latest_tag" ]; then + if [ "${{ env.new_version }}" == "${{ env.latest_version }}" ]; then echo "Version has not been bumped!" exit 1 else From 26b7eb83082111fd3024bf8d837e89aeb59f81ed Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 10:44:12 -0400 Subject: [PATCH 08/24] Issue #141: optional : adds project path --- .../workflows/workflow-lint-test-python.yml | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 95dcc2ec..73b25c53 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -1,4 +1,3 @@ ---- name: Reusable lint and test workflow for Python projects on: @@ -10,7 +9,7 @@ on: package-name: required: false type: string - test-path: + project-path: required: false type: string @@ -32,19 +31,18 @@ jobs: - name: Install dependencies run: | + project_path="${{ inputs.project-path || '.' }}" python -m pip install --upgrade pip pip install ruff==0.1.0 - if [ -f requirements.txt ]; then \ - pip install -r requirements.txt; \ + if [ -f $project_path/requirements.txt ]; then \ + pip install -r $project_path/requirements.txt; \ fi pip install pytest pytest-cov # for coverage - 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 . @@ -54,13 +52,13 @@ jobs: - name: Test with unittest run: | - test_path="${{ inputs.test-path || 'tests' }}" - python -m unittest discover -s $test_path + project_path="${{ inputs.project-path || '.' }}" + python -m unittest discover -s $project_path/tests - name: Run tests with coverage (coverage must be at least 80% to pass) run: | - test_path="${{ inputs.test-path || 'tests' }}" - pytest --cov=. --cov-fail-under=80 $test_path # default value, coverage must be at least 80% + project_path="${{ inputs.project-path || '.' }}" + pytest --cov=. --cov-fail-under=80 $project_path/tests version-bump-check: runs-on: ubuntu-latest From 045b077e865adf8dd5a88fdded7bf59c117e9492 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 14:49:36 -0400 Subject: [PATCH 09/24] Issue #141: update coverage command since python adds the current directory in the PYTHONPATH for you --- .github/workflows/workflow-lint-test-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 73b25c53..96d3a0b6 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -58,7 +58,7 @@ jobs: - name: Run tests with coverage (coverage must be at least 80% to pass) run: | project_path="${{ inputs.project-path || '.' }}" - pytest --cov=. --cov-fail-under=80 $project_path/tests + python -m pytest --cov=. --cov-fail-under=80 $project_path/tests version-bump-check: runs-on: ubuntu-latest From e9e1a249a497e448256b48844709eae639866a26 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 20 Aug 2024 16:04:03 -0400 Subject: [PATCH 10/24] Issue #141: filter tags based on package-name --- .github/workflows/workflow-lint-test-python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 96d3a0b6..477b3785 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -83,7 +83,8 @@ jobs: - name: Get latest version id: get_latest_version run: | - latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) + 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 From 6d12d24b3a367060f15ccda0c04b5741aefe754e Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 21 Aug 2024 09:17:51 -0400 Subject: [PATCH 11/24] Issue #141: update coverage with folder path --- .github/workflows/workflow-lint-test-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 477b3785..236f05ad 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -58,7 +58,7 @@ jobs: - name: Run tests with coverage (coverage must be at least 80% to pass) run: | project_path="${{ inputs.project-path || '.' }}" - python -m pytest --cov=. --cov-fail-under=80 $project_path/tests + python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests version-bump-check: runs-on: ubuntu-latest From bd6be5c7c997812c3a3a90707121adbb27a1e170 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 21 Aug 2024 16:39:17 -0400 Subject: [PATCH 12/24] Issue #141: adds boolean to run coverage for monorepo ailab-datastore --- .github/workflows/workflow-lint-test-python.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 236f05ad..c47a62c6 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -12,6 +12,10 @@ on: project-path: required: false type: string + run-coverage: + required: false + type: boolean + default: true permissions: actions: read @@ -56,6 +60,7 @@ jobs: python -m unittest discover -s $project_path/tests - name: Run tests with coverage (coverage must be at least 80% to pass) + if: inputs.run-coverage == 'true' run: | project_path="${{ inputs.project-path || '.' }}" python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests From 0385df178bd6a4e77ff35560471753d9c88410ee Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 21 Aug 2024 16:41:30 -0400 Subject: [PATCH 13/24] Issue #141: remove project path to coverage --- .github/workflows/workflow-lint-test-python.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index c47a62c6..9b6ce1e4 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -62,8 +62,7 @@ jobs: - name: Run tests with coverage (coverage must be at least 80% to pass) if: inputs.run-coverage == 'true' run: | - project_path="${{ inputs.project-path || '.' }}" - python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests + python -m pytest --cov=. --cov-fail-under=80 version-bump-check: runs-on: ubuntu-latest From 601be7bf8dcf677bb7a3a5c2e24b04bd7a9beee8 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 21 Aug 2024 16:52:45 -0400 Subject: [PATCH 14/24] Issue #141: update boolean check value --- .github/workflows/workflow-lint-test-python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 9b6ce1e4..c47a62c6 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -62,7 +62,8 @@ jobs: - name: Run tests with coverage (coverage must be at least 80% to pass) if: inputs.run-coverage == 'true' run: | - python -m pytest --cov=. --cov-fail-under=80 + project_path="${{ inputs.project-path || '.' }}" + python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests version-bump-check: runs-on: ubuntu-latest From 2db34c045fc899af94b3914060455a57f0aa1289 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 22 Aug 2024 08:56:20 -0400 Subject: [PATCH 15/24] Issue #141: Change to skip coverage variable --- .github/workflows/workflow-lint-test-python.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index c47a62c6..4c396762 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -12,10 +12,10 @@ on: project-path: required: false type: string - run-coverage: + skip-coverage: required: false - type: boolean - default: true + type: string + default: 'false' permissions: actions: read @@ -60,7 +60,7 @@ jobs: python -m unittest discover -s $project_path/tests - name: Run tests with coverage (coverage must be at least 80% to pass) - if: inputs.run-coverage == 'true' + if: inputs.skip-coverage == 'true' run: | project_path="${{ inputs.project-path || '.' }}" python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests From a9d464f137f1837bf41e563b86e91c6708a3e0bb Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 22 Aug 2024 09:02:20 -0400 Subject: [PATCH 16/24] Issue #141: update condition --- .github/workflows/workflow-lint-test-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 4c396762..279cd25b 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -60,7 +60,7 @@ jobs: python -m unittest discover -s $project_path/tests - name: Run tests with coverage (coverage must be at least 80% to pass) - if: inputs.skip-coverage == 'true' + if: inputs.skip-coverage != 'true' run: | project_path="${{ inputs.project-path || '.' }}" python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests From ec6ce0f24dccb6337f169a7665dea1672ff912ff Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 22 Aug 2024 09:07:24 -0400 Subject: [PATCH 17/24] Issue #141: update coverage scope --- .github/workflows/workflow-lint-test-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 279cd25b..7b407520 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -63,7 +63,7 @@ jobs: if: inputs.skip-coverage != 'true' run: | project_path="${{ inputs.project-path || '.' }}" - python -m pytest --cov=$project_path --cov-fail-under=80 $project_path/tests + python -m pytest --cov=. --cov-fail-under=80 version-bump-check: runs-on: ubuntu-latest From 61af05c030d006680d23de30e304beea5ae9ee7e Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 3 Oct 2024 13:55:31 -0400 Subject: [PATCH 18/24] Issue #141: Switch to pytest for testing --- .github/workflows/workflow-lint-test-python.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 7b407520..10a03761 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -54,15 +54,13 @@ jobs: with: secrets: ${{ toJSON(secrets) }} - - name: Test with unittest + - name: Test with pytest run: | - project_path="${{ inputs.project-path || '.' }}" - python -m unittest discover -s $project_path/tests + python -m pytest - name: Run tests with coverage (coverage must be at least 80% to pass) if: inputs.skip-coverage != 'true' run: | - project_path="${{ inputs.project-path || '.' }}" python -m pytest --cov=. --cov-fail-under=80 version-bump-check: From 6e2d269708dee53c439991bf26ae9c3b22cb5167 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 3 Oct 2024 13:57:41 -0400 Subject: [PATCH 19/24] Issue #141: optional project path --- .github/workflows/workflow-lint-test-python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 10a03761..50739e42 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -56,7 +56,8 @@ jobs: - name: Test with pytest run: | - python -m pytest + project_path="${{ inputs.project-path || '.' }}" + python -m pytest $project_path - name: Run tests with coverage (coverage must be at least 80% to pass) if: inputs.skip-coverage != 'true' From 5f7d2b858b697ee7531337902dc6c843028a8c19 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 3 Oct 2024 14:19:54 -0400 Subject: [PATCH 20/24] Issue #141: Refactor pipelines --- .../workflows/workflow-lint-test-python.yml | 54 ++----------------- .../workflows/workflow-version-bump-python.md | 14 +++++ .../workflow-version-bump-python.yml | 49 +++++++++++++++++ 3 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/workflow-version-bump-python.md create mode 100644 .github/workflows/workflow-version-bump-python.yml diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 50739e42..7664a322 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -3,15 +3,6 @@ name: Reusable lint and test workflow for Python projects on: workflow_call: inputs: - pyproject-path: - required: false - type: string - package-name: - required: false - type: string - project-path: - required: false - type: string skip-coverage: required: false type: string @@ -35,11 +26,10 @@ jobs: - name: Install dependencies run: | - project_path="${{ inputs.project-path || '.' }}" python -m pip install --upgrade pip pip install ruff==0.1.0 if [ -f $project_path/requirements.txt ]; then \ - pip install -r $project_path/requirements.txt; \ + pip install -r requirements.txt; \ fi pip install pytest pytest-cov # for coverage @@ -54,49 +44,11 @@ jobs: with: secrets: ${{ toJSON(secrets) }} - - name: Test with pytest + - name: Test with unittest run: | - project_path="${{ inputs.project-path || '.' }}" - python -m pytest $project_path + python -m unittest discover -s tests - name: Run tests with coverage (coverage must be at least 80% to pass) if: inputs.skip-coverage != 'true' run: | python -m pytest --cov=. --cov-fail-under=80 - - version-bump-check: - runs-on: ubuntu-latest - if: inputs.pyproject-path != '' - 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 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 From 700a07d7ae29e385164330da6d72b66adb69195d Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 3 Oct 2024 14:23:52 -0400 Subject: [PATCH 21/24] Issue #141: move requirements.txt --- .github/workflows/workflow-lint-test-python.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 7664a322..c489026b 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -28,9 +28,7 @@ jobs: run: | python -m pip install --upgrade pip pip install ruff==0.1.0 - if [ -f $project_path/requirements.txt ]; then \ - pip install -r requirements.txt; \ - fi + pip install -r requirements.txt; pip install pytest pytest-cov # for coverage - name: Lint with ruff From d4aa62af5c34f3af2a637e190cea864e2c8a7b02 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 3 Oct 2024 14:24:22 -0400 Subject: [PATCH 22/24] Issue #141: trailing quote --- .github/workflows/workflow-lint-test-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index c489026b..3e0fa934 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -28,7 +28,7 @@ jobs: run: | python -m pip install --upgrade pip pip install ruff==0.1.0 - pip install -r requirements.txt; + pip install -r requirements.txt pip install pytest pytest-cov # for coverage - name: Lint with ruff From b97ea71e4057cc3ed95b5cfe77aa0efa7dd6b28b Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 3 Oct 2024 14:32:09 -0400 Subject: [PATCH 23/24] Issue #141: update to pytest --- .github/workflows/workflow-lint-test-python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 3e0fa934..4fd2e9a0 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -42,9 +42,9 @@ 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' From eb94acd03c8a307ecefd856c9bce975a0c133427 Mon Sep 17 00:00:00 2001 From: Jonathan Lopez Date: Thu, 3 Oct 2024 15:28:58 -0400 Subject: [PATCH 24/24] Issue #141: revert requirements.txt installation validation --- .github/workflows/workflow-lint-test-python.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow-lint-test-python.yml b/.github/workflows/workflow-lint-test-python.yml index 4fd2e9a0..456e91c8 100644 --- a/.github/workflows/workflow-lint-test-python.yml +++ b/.github/workflows/workflow-lint-test-python.yml @@ -28,7 +28,9 @@ jobs: run: | python -m pip install --upgrade pip pip install ruff==0.1.0 - pip install -r requirements.txt + if [ -f requirements.txt ]; then \ + pip install -r requirements.txt; \ + fi pip install pytest pytest-cov # for coverage - name: Lint with ruff