diff --git a/.github/actions/python/test/action.yaml b/.github/actions/python/test/action.yaml deleted file mode 100644 index efff7ccc..00000000 --- a/.github/actions/python/test/action.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: "Code for Life - Python - Test" -description: "Tests python code written in the CFL workspace." -inputs: - python-version: - description: "The python version to set up." - required: true - default: "3.8" - working-directory: - description: "The current working directory." - required: true - default: "." - check-django-migrations: - description: "Check if there are pending Django migrations." - required: true - default: "true" -runs: - using: composite - steps: - - uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main - with: - python-version: ${{ inputs.python-version }} - working-directory: ${{ inputs.working-directory }} - install-args: "--dev" - - - name: ๐Ÿ”Ž Check Code Format - shell: bash - working-directory: ${{ inputs.working-directory }} - run: if ! pipenv run black --check .; then exit 1; fi - - # TODO: check static type hints with mypy - - # TODO: check linter error with pylint - - - name: ๐Ÿ”Ž Check Django Migrations - if: inputs.check-django-migrations == 'true' - shell: bash - working-directory: ${{ inputs.working-directory }} - run: pipenv run python manage.py makemigrations --check --dry-run - - - name: ๐Ÿงช Test Code Units - shell: bash - working-directory: ${{ inputs.working-directory }} - run: pipenv run pytest -n auto - - # TODO: assert code coverage target. diff --git a/.github/workflows/test-python-code.yaml b/.github/workflows/test-python-code.yaml new file mode 100644 index 00000000..3da2ba40 --- /dev/null +++ b/.github/workflows/test-python-code.yaml @@ -0,0 +1,68 @@ +name: Test Python Code + +on: + workflow_call: + inputs: + python-version: + description: "The python version to set up." + type: number + required: true + default: 3.8 + working-directory: + description: "The current working directory." + type: string + required: true + default: "." + source-path: + description: "The path of the source files." + type: string + required: true + default: "." + check-django-migrations: + description: "Check if there are pending Django migrations." + type: boolean + required: true + default: true + pyproject-toml: + description: "The path to the pyproject.toml file." + type: string + required: true + default: "pyproject.toml" + +jobs: + test-py-code: + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ Set up Python ${{ inputs.python-version }} Environment + uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main + with: + python-version: ${{ inputs.python-version }} + working-directory: ${{ inputs.working-directory }} + install-args: --dev + + - name: ๐Ÿ”Ž Check Import Sort + working-directory: ${{ inputs.working-directory }} + run: pipenv run isort --settings-file=${{ inputs.pyproject-toml }} --check ${{ inputs.source-path }} + + - name: ๐Ÿ”Ž Check Code Format + working-directory: ${{ inputs.working-directory }} + run: if ! pipenv run black --config=${{ inputs.pyproject-toml }} --check ${{ inputs.source-path }}; then exit 1; fi + + - name: ๐Ÿ”Ž Check Static Type Hints + working-directory: ${{ inputs.working-directory }} + run: pipenv run mypy --config-file=${{ inputs.pyproject-toml }} ${{ inputs.source-path }} + + - name: ๐Ÿ”Ž Check Static Code + working-directory: ${{ inputs.working-directory }} + run: pipenv run pylint --rcfile=${{ inputs.pyproject-toml }} ${{ inputs.source-path }} + + - name: ๐Ÿ”Ž Check Django Migrations + if: inputs.check-django-migrations + working-directory: ${{ inputs.working-directory }} + run: pipenv run python manage.py makemigrations --check --dry-run + + - name: ๐Ÿงช Test Code Units + working-directory: ${{ inputs.working-directory }} + run: pipenv run pytest -n=auto -c=${{ inputs.pyproject-toml }} ${{ inputs.source-path }} + + # TODO: assert code coverage target.