diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08f321c..55169cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,30 +3,25 @@ name: build on: [push] jobs: - build: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8, 3.9] - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.6, 3.7, 3.8, 3.9] - - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: lint with ruff + run: ruff check --output-format=github . + - name: Test with pytest + run: | + pytest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 15b6f86..6f0d514 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,26 +1,128 @@ name: publish on: - release: - types: [created] + workflow_dispatch: + inputs: + VERSION: + description: "The version to release" + required: true + IS_PRE_RELEASE: + description: "It IS a pre-release" + required: true + default: false + type: boolean jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + bump: # This job is used to bump the version and create a release + runs-on: ubuntu-latest + env: + VERSION: ${{ inputs.VERSION }} + GH_TOKEN: ${{ github.token }} + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + permissions: + contents: write + steps: + - name: set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: install dependencies + run: | + pip install --upgrade pip + pip install build hatch + + - name: configure git with the bot credentials + run: | + mkdir -p ~/.ssh + ssh-keyscan github.com >> ~/.ssh/known_hosts + ssh-agent -a $SSH_AUTH_SOCK > /dev/null + ssh-add - <<< "${{ secrets.BOT_SSH_KEY }}" + + echo "${{ secrets.BOT_SIGNING_KEY }}" > ~/.ssh/signing.key + chmod 600 ~/.ssh/signing.key + + git config --global user.name "Merschbotmann" + git config --global user.email "bot.merschformann@gmail.com" + git config --global gpg.format ssh + git config --global user.signingkey ~/.ssh/signing.key + + git clone git@github.com:merschformann/brickmos.git + + - name: upgrade version with hatch + run: hatch version ${{ env.VERSION }} + working-directory: ./brickmos + + - name: commit new version + run: | + git add brickmos/__about__.py + git commit -S -m "Bump version to $VERSION" + git push + git tag $VERSION + git push origin $VERSION + working-directory: ./brickmos + + - name: create release + run: | + PRERELEASE_FLAG="" + if [ ${{ inputs.IS_PRE_RELEASE }} = true ]; then + PRERELEASE_FLAG="--prerelease" + fi + + gh release create $VERSION \ + --verify-tag \ + --generate-notes \ + --title $VERSION $PRERELEASE_FLAG + working-directory: ./brickmos + + - name: ensure passing build + run: python -m build + working-directory: ./brickmos + + publish: # This job is used to publish the release to PyPI/TestPyPI + runs-on: ubuntu-latest + needs: bump + strategy: + matrix: + include: + - target-env: pypi + target-url: https://pypi.org/p/brickmos + - target-env: testpypi + target-url: https://test.pypi.org/p/brickmos + environment: + name: ${{ matrix.target-env }} + url: ${{ matrix.target-url }} + permissions: + contents: read + id-token: write # This is required for trusted publishing to PyPI + steps: + - name: git clone main + uses: actions/checkout@v4 + with: + ref: main + + - name: set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: install dependencies + run: | + pip install --upgrade pip + pip install build hatch + + - name: build binary wheel and source tarball + run: python -m build + + - name: Publish package distributions to PyPI + if: ${{ matrix.target-env == 'pypi' }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: ./dist + + - name: Publish package distributions to TestPyPI + if: ${{ matrix.target-env == 'testpypi' }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + packages-dir: ./dist diff --git a/brickmos/__about__.py b/brickmos/__about__.py new file mode 100644 index 0000000..14b43dc --- /dev/null +++ b/brickmos/__about__.py @@ -0,0 +1 @@ +__version__ = "v0.0.4" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..003831a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,57 @@ +[build-system] +build-backend = "hatchling.build" +requires = ["hatchling >= 1.13.0"] + +[project] +authors = [ + { email = "marius.merschformann@gmail.com", name = "Marius Merschformann" } +] +maintainers = [ + { email = "marius.merschformann@gmail.com", name = "Marius Merschformann" } +] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", +] +dependencies = [ + "opencv-python>=4.8.1.78", +] +description = "brickmos is a humble Lego mosaic generator." +dynamic = [ + "version", +] +keywords = [ + "lego", + "mosaic", + "bricklink", +] +license = { file = "LICENSE" } +name = "brickmos" +readme = "README.md" +requires-python = ">=3.10" + +[project.urls] +Homepage = "https://github.com/merschformann/brickmos" +Repository = "https://github.com/merschformann/brickmos" + +[project.scripts] +brickmos = "brickmos.brickify:main" + +[tool.ruff] +target-version = "py312" +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "I", # isort + "C", # flake8-comprehensions + "B", # flake8-bugbear + "UP", # pyupgrade +] +line-length = 120 +[tool.ruff.lint.mccabe] +max-complexity = 15 + +[tool.hatch.version] +path = "brickmos/__about__.py" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 97cf07f..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -opencv-python~=4.4.0.44 \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 913a601..0000000 --- a/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -import setuptools - -# read the contents of README -from os import path - -current_dir = path.abspath(path.dirname(__file__)) -with open(path.join(current_dir, "README.md"), encoding="utf-8") as f: - long_description = f.read() - - -setuptools.setup( - name="brickmos", - description="brickmos - A simple brick mosaic generator", - long_description=long_description, - long_description_content_type="text/markdown", - version="0.0.3", - author="Marius Merschformann", - author_email="marius.merschformann@gmail.com", - url="https://github.com/merschformann/brickmos", - packages=setuptools.find_packages(), - install_requires=[ - "opencv-python~=4.4.0.44", - ], - entry_points={ - "console_scripts": ["brickmos=brickmos.brickify:main"], - }, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Environment :: Console", - ], -)