From 521051eb9ce72c721aceb2c6a1af1cb6aa430633 Mon Sep 17 00:00:00 2001 From: Ali Zahedigol Date: Thu, 28 Mar 2024 17:42:55 +0200 Subject: [PATCH] fix!: use pypi on github action --- .editorconfig | 32 ++++++++++++++++ .github/workflows/linters.yaml | 37 ++++++++++++++++++ .github/workflows/release.yaml | 70 ++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 67 -------------------------------- .pre-commit-config.yaml | 67 +++++++++++++++++++++++++------- .releaserc.yaml | 22 +++++++++++ .releaserc.yml | 13 ------- .yamllint.yml | 6 +++ pyproject.toml | 30 ++++++++------- setup.cfg | 4 -- tox.ini | 37 ++++++++++++++++++ 11 files changed, 274 insertions(+), 111 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/linters.yaml create mode 100644 .github/workflows/release.yaml delete mode 100644 .gitlab-ci.yml create mode 100644 .releaserc.yaml delete mode 100644 .releaserc.yml create mode 100644 .yamllint.yml delete mode 100644 setup.cfg create mode 100644 tox.ini diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b0f4844 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.py] +indent_size = 4 +continuation_indent_size = 8 +indent_style = space +max_line_length = 120 + +[*.{html,js,css,scss,json}] +indent_style = space +indent_size = 4 + +[*.cfg] +indent_size = 4 +indent_style = space + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml new file mode 100644 index 0000000..469a398 --- /dev/null +++ b/.github/workflows/linters.yaml @@ -0,0 +1,37 @@ +--- + +name: Linters + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + pre-commit-linter: + name: pre-commit-linter + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.base_ref }} + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + - run: python -m pip install pre-commit + - name: linter + run: >- + pre-commit run --color always --all-files + -s ${GITHUB_BASE_REF_SHA} -o HEAD + env: + GITHUB_BASE_REF_SHA: ${{ github.event.pull_request.base.sha }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..df60446 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,70 @@ +--- +name: Version + +on: + push: + branches: + - main + - develop + +jobs: + versioning_pipeline: + environment: + name: ${{ github.ref_name }} + runs-on: ubuntu-latest + outputs: + version: ${{ steps.set_output.outputs.version }} + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: Setup package.json + run: | + echo '{"name":"demo", "devDependencies":{"@semantic-release/github":"9.0.4","@semantic-release/exec":"6.0.3","semantic-release":"21.0.7"}}' > package.json + + - name: Install semantic-release + run: | + npm install + + - name: Run semantic-release + id: semantic + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npx semantic-release + # Extract the version from the new git tag + NEW_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV + + - name: Set version output + id: set_output + run: echo "::set-output name=version::$NEW_TAG" + + pypi-publish: + name: Upload release to PyPI + runs-on: ubuntu-latest + needs: versioning_pipeline + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: + - name: Checkout Code + uses: actions/checkout@v3 + - name: Build package + uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Update package version + run: | + VERSION=${{ needs.versioning_pipeline.outputs.version }} + echo "Version: $VERSION" + sed -i "s/__version__ = \"1.0.0\"/__version__ = \"$VERSION\"/g" setup.py + - name: Install build + run: python -m pip install build + - name: Build dist + run: python -m build + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 20b7d06..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,67 +0,0 @@ -stages: - - fetch-version - - production - - release - -variables: - AUTHOR: 'Ali Zahedigol' - -.node: &node - image: node:latest - tags: - - node - -.python: &python - image: python:3.7 - tags: - - python - - -fetch-version: - # Requires Node >= 10.13 version - <<: *node - stage: fetch-version - only: - refs: - - master - - develop - script: - - npm install @semantic-release/gitlab @semantic-release/exec @semantic-release/changelog - - npx semantic-release --generate-notes false --dry-run - artifacts: - paths: - - VERSION.txt - -production: - <<: *python - stage: production - environment: - name: production - script: - - echo "Version is $(cat VERSION.txt)" - - sed -i "s/version='1.0.0',/version='$(cat VERSION.txt)',/g" setup.py - - pip install twine - - python setup.py sdist bdist_wheel - - TWINE_PASSWORD=${TWINE_TOKEN} TWINE_USERNAME=${TWINE_USERNAME} python -m twine upload dist/* - only: - - master - - develop - dependencies: - - fetch-version - -release: - <<: *node - stage: release - only: - refs: - - master - - develop - script: - - touch CHANGELOG.md - - npm install @semantic-release/gitlab @semantic-release/changelog @semantic-release/exec - - npx semantic-release - artifacts: - paths: - - CHANGELOG.md - dependencies: - - production diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03779e9..64fab04 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,60 @@ +--- + repos: - - repo: https://github.com/pycqa/isort - rev: 5.8.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 hooks: - - id: isort - name: isort (python) - - - repo: https://github.com/ambv/black - rev: stable + - id: check-ast + - id: check-case-conflict + - id: check-merge-conflict + - id: debug-statements + - id: end-of-file-fixer + exclude_types: [svg, plain-text] + - id: trailing-whitespace + exclude_types: [svg] + - id: check-added-large-files + - id: check-shebang-scripts-are-executable + - id: check-yaml + - id: mixed-line-ending + - repo: https://github.com/psf/black + rev: 23.7.0 hooks: - id: black - language_version: python3 - - - repo: https://github.com/pycqa/flake8 - rev: '' # pick a git hash / tag to point to + args: ['--config=pyproject.toml'] + - repo: https://github.com/adamchainz/blacken-docs + rev: 1.13.0 + hooks: + - id: blacken-docs + additional_dependencies: + - black==23.7.0 + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + types: [python] + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 hooks: - id: flake8 + language: python + language_version: python3.11 + types: [python] additional_dependencies: - - flake8-black>=0.2.2 - language_version: python3 - + - flake8-black>=0.2.2 + - flake8-mutable + - flake8-gl-codeclimate + - flake8-bugbear + - flake8-comprehensions + - flake8-print + - flake8-simplify + - flake8-django + - repo: https://github.com/adamchainz/django-upgrade + rev: 1.16.0 + hooks: + - id: django-upgrade + args: [--target-version, "5.0"] + types: [python] + - repo: https://github.com/adrienverge/yamllint + rev: v1.32.0 + hooks: + - id: yamllint diff --git a/.releaserc.yaml b/.releaserc.yaml new file mode 100644 index 0000000..2f6cd3d --- /dev/null +++ b/.releaserc.yaml @@ -0,0 +1,22 @@ +--- + +{ + "plugins": [ + "@semantic-release/commit-analyzer", + [ + "@semantic-release/exec", + { + "verifyReleaseCmd": "echo ${nextRelease.version} > VERSION.txt", + "prepareCmd": "echo ${nextRelease.version} > VERSION.txt" + } + ], + "@semantic-release/github" + ], + "branches": [ + "main", + { + "name": "develop", + "prerelease": "alpha" + } + ] +} diff --git a/.releaserc.yml b/.releaserc.yml deleted file mode 100644 index e103d87..0000000 --- a/.releaserc.yml +++ /dev/null @@ -1,13 +0,0 @@ -plugins: - - "@semantic-release/commit-analyzer" - - '@semantic-release/release-notes-generator' - - - '@semantic-release/exec' - - verifyReleaseCmd: 'echo ${nextRelease.version} > VERSION.txt' - prepareCmd: 'echo ${nextRelease.version} > VERSION.txt' - - - '@semantic-release/changelog' - - changelogFile: CHANGELOG.md - - "@semantic-release/gitlab" -branches: - - "master" - - name: "develop" - prerelease: "alpha" diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..cf0bbc6 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,6 @@ +extends: default + +rules: + line-length: + # TODO: fix it! + max: 500 diff --git a/pyproject.toml b/pyproject.toml index 95df454..ecd5a0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,26 @@ +[build-system] +requires = ['setuptools>=40.8.0'] +build-backend = 'setuptools.build_meta' + [tool.black] +indent = 4 +line-length = 110 skip-string-normalization=1 -line-length = 119 -include = '\.pyi?$' +max_attribute_length = 10 +profile = 'django' exclude = ''' /( - \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - | frontend - | .+/migrations + migrations + | __pycache__ + | \.git )/ ''' [tool.isort] profile = "black" +combine_as_imports = true +include_trailing_comma = true +lines_after_imports = 2 +multi_line_output = 3 +skip = ["migrations", "__pycache__", ".git", "env", ".env", "venv", ".venv", ".direnv"] +sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 1936ad2..0000000 --- a/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -exclude = .git,*migrations*,*frontend* -max-line-length = 119 -extend-ignore = E203 # Flake8 will raise E203 whitespace before ':' warnings. Since this warning is not PEP 8 compliant diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..715c603 --- /dev/null +++ b/tox.ini @@ -0,0 +1,37 @@ +[tox] +envlist = py38, py39, py310, py311, lint + +[flake8] +max-line-length = 110 +max-complexity = 10 +ignore = C901,E203,W503 +exclude = + .git, + __pycache__, + */migrations/*, + static, + staticfiles, + media, + docs, + env, + .env, + venv, + .venv, + .direnv +per-file-ignores = + # Ignore line length for migrations (E501) + */migrations/*:E501, + # Ignore import but unused violations in __init__ files + */__init__.py:F401, + + +[testenv] +deps = + pytest +commands = pytest + +[testenv:lint] +basepython = python3.11 +deps = + pre-commit +commands = pre-commit run --all-files