Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #141: adds jobs for validating version bump #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6b2ffec
Issue #141: adds jobs for validating version bump
SonOfLope Aug 20, 2024
0205af2
Issue #141: yaml lint
SonOfLope Aug 20, 2024
7def3d3
Issue #141: Fetch tags in checkout
SonOfLope Aug 20, 2024
bd8a6c9
Issue #141: Fetch tags in checkout with right key
SonOfLope Aug 20, 2024
95175dc
Issue #141: Fetch depth for all history
SonOfLope Aug 20, 2024
fa434f8
Issue #141: optional : provide path for test folder
SonOfLope Aug 20, 2024
21405ce
Issue #141: extract version from latest tag
SonOfLope Aug 20, 2024
26b7eb8
Issue #141: optional : adds project path
SonOfLope Aug 20, 2024
045b077
Issue #141: update coverage command since python adds the current dir…
SonOfLope Aug 20, 2024
e9e1a24
Issue #141: filter tags based on package-name
SonOfLope Aug 20, 2024
6d12d24
Issue #141: update coverage with folder path
SonOfLope Aug 21, 2024
bd6be5c
Issue #141: adds boolean to run coverage for monorepo ailab-datastore
SonOfLope Aug 21, 2024
0385df1
Issue #141: remove project path to coverage
SonOfLope Aug 21, 2024
601be7b
Issue #141: update boolean check value
SonOfLope Aug 21, 2024
2db34c0
Issue #141: Change to skip coverage variable
SonOfLope Aug 22, 2024
a9d464f
Issue #141: update condition
SonOfLope Aug 22, 2024
ec6ce0f
Issue #141: update coverage scope
SonOfLope Aug 22, 2024
61af05c
Issue #141: Switch to pytest for testing
SonOfLope Oct 3, 2024
6e2d269
Issue #141: optional project path
SonOfLope Oct 3, 2024
5f7d2b8
Issue #141: Refactor pipelines
SonOfLope Oct 3, 2024
700a07d
Issue #141: move requirements.txt
SonOfLope Oct 3, 2024
d4aa62a
Issue #141: trailing quote
SonOfLope Oct 3, 2024
b97ea71
Issue #141: update to pytest
SonOfLope Oct 3, 2024
eb94acd
Issue #141: revert requirements.txt installation validation
SonOfLope Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .github/workflows/workflow-lint-test-python.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
name: Reusable lint and test workflow for Python projects

Check warning on line 1 in .github/workflows/workflow-lint-test-python.yml

View workflow job for this annotation

GitHub Actions / yaml-lint-check

1:1 [document-start] missing document start "---"

on:
workflow_call:
inputs:
skip-coverage:
required: false
type: string
default: 'false'

permissions:
actions: read
Expand Down Expand Up @@ -31,21 +35,20 @@

- 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 .

- uses: oNaiPs/secrets-to-env-action@v1
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
14 changes: 14 additions & 0 deletions .github/workflows/workflow-version-bump-python.md
Original file line number Diff line number Diff line change
@@ -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'
```
49 changes: 49 additions & 0 deletions .github/workflows/workflow-version-bump-python.yml
Original file line number Diff line number Diff line change
@@ -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
Loading