diff options
author | Milas Bowman <milas.bowman@docker.com> | 2022-07-30 12:14:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-30 12:14:27 -0400 |
commit | cd2c35a9b699522b282cc4f024efa5699df24896 (patch) | |
tree | 18717584169b7cbbd1196be5fe327dd36136aad7 | |
parent | 828d06f5f5e2c8ecd9a8d53c1ef40f37d19a62f5 (diff) | |
download | docker-py-cd2c35a9b699522b282cc4f024efa5699df24896.tar.gz |
ci: add workflow for releases (#3018)
GitHub Actions workflow to create a release: will upload to PyPI
and create a GitHub release with the `sdist` and `bdist_wheel`
as well.
The version code is switched to `setuptools_scm` to work well
with this flow (e.g. avoid needing to write a script that does
a `sed` on the version file and commits as part of release).
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
-rw-r--r-- | .editorconfig | 3 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 3 | ||||
-rw-r--r-- | .github/workflows/release.yml | 44 | ||||
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Dockerfile | 4 | ||||
-rw-r--r-- | docker/__init__.py | 3 | ||||
-rw-r--r-- | docker/constants.py | 4 | ||||
-rw-r--r-- | docker/version.py | 16 | ||||
-rw-r--r-- | docs/conf.py | 11 | ||||
-rw-r--r-- | pyproject.toml | 5 | ||||
-rw-r--r-- | setup.py | 8 | ||||
-rw-r--r-- | tests/Dockerfile | 13 |
12 files changed, 96 insertions, 22 deletions
diff --git a/.editorconfig b/.editorconfig index d7f2776..65d0c51 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,6 @@ max_line_length = 80 [*.md] trim_trailing_whitespace = false + +[*.{yaml,yml}] +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 296bf0d..d163412 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,9 @@ name: Python package on: [push, pull_request] +env: + DOCKER_BUILDKIT: '1' + jobs: flake8: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..50695b1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: Release + +on: + workflow_dispatch: + inputs: + tag: + description: "Release Tag WITHOUT `v` Prefix (e.g. 6.0.0)" + required: true + dry-run: + description: 'Dry run' + required: false + type: boolean + default: true + +jobs: + publish: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - run: python setup.py sdist bdist_wheel + env: + SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DOCKER: ${{ inputs.tag }} + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + if: ! inputs.dry-run + with: + password: ${{ secrets.PYPI_API_TOKEN }} + + - name: Create GitHub release + uses: ncipollo/release-action@v1 + if: ! inputs.dry-run + with: + artifacts: "dist/*" + generateReleaseNotes: true + draft: true + commit: ${{ github.sha }} + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ inputs.tag }} @@ -13,6 +13,10 @@ html/* _build/ README.rst +# setuptools_scm +_version.py + env/ venv/ .idea/ +*.iml @@ -2,7 +2,6 @@ ARG PYTHON_VERSION=3.10 FROM python:${PYTHON_VERSION} -RUN mkdir /src WORKDIR /src COPY requirements.txt /src/requirements.txt @@ -11,5 +10,6 @@ RUN pip install --no-cache-dir -r requirements.txt COPY test-requirements.txt /src/test-requirements.txt RUN pip install --no-cache-dir -r test-requirements.txt -COPY . /src +COPY . . +ARG SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER RUN pip install --no-cache-dir . diff --git a/docker/__init__.py b/docker/__init__.py index e5c1a8f..46beb53 100644 --- a/docker/__init__.py +++ b/docker/__init__.py @@ -4,7 +4,6 @@ from .client import DockerClient, from_env from .context import Context from .context import ContextAPI from .tls import TLSConfig -from .version import version, version_info +from .version import __version__ -__version__ = version __title__ = 'docker' diff --git a/docker/constants.py b/docker/constants.py index d5bfc35..ed341a9 100644 --- a/docker/constants.py +++ b/docker/constants.py @@ -1,5 +1,5 @@ import sys -from .version import version +from .version import __version__ DEFAULT_DOCKER_API_VERSION = '1.41' MINIMUM_DOCKER_API_VERSION = '1.21' @@ -28,7 +28,7 @@ INSECURE_REGISTRY_DEPRECATION_WARNING = \ IS_WINDOWS_PLATFORM = (sys.platform == 'win32') WINDOWS_LONGPATH_PREFIX = '\\\\?\\' -DEFAULT_USER_AGENT = f"docker-sdk-python/{version}" +DEFAULT_USER_AGENT = f"docker-sdk-python/{__version__}" DEFAULT_NUM_POOLS = 25 # The OpenSSH server default value for MaxSessions is 10 which means we can diff --git a/docker/version.py b/docker/version.py index 88ee8b0..44eac8c 100644 --- a/docker/version.py +++ b/docker/version.py @@ -1,2 +1,14 @@ -version = "6.0.0-dev" -version_info = tuple(int(d) for d in version.split("-")[0].split(".")) +try: + from ._version import __version__ +except ImportError: + try: + # importlib.metadata available in Python 3.8+, the fallback (0.0.0) + # is fine because release builds use _version (above) rather than + # this code path, so it only impacts developing w/ 3.7 + from importlib.metadata import version, PackageNotFoundError + try: + __version__ = version('docker') + except PackageNotFoundError: + __version__ = '0.0.0' + except ImportError: + __version__ = '0.0.0' diff --git a/docs/conf.py b/docs/conf.py index 1258a42..dc3b37c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -63,12 +63,11 @@ author = 'Docker Inc' # |version| and |release|, also used in various other places throughout the # built documents. # -with open('../docker/version.py') as vfile: - exec(vfile.read()) -# The full version, including alpha/beta/rc tags. -release = version -# The short X.Y version. -version = f'{version_info[0]}.{version_info[1]}' +# see https://github.com/pypa/setuptools_scm#usage-from-sphinx +from importlib.metadata import version +release = version('docker') +# for example take major/minor +version = '.'.join(release.split('.')[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9554358 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] + +[tool.setuptools_scm] +write_to = 'docker/_version.py' @@ -29,9 +29,6 @@ extras_require = { 'ssh': ['paramiko>=2.4.3'], } -version = None -exec(open('docker/version.py').read()) - with open('./test-requirements.txt') as test_reqs_txt: test_requirements = [line for line in test_reqs_txt] @@ -42,7 +39,9 @@ with codecs.open('./README.md', encoding='utf-8') as readme_md: setup( name="docker", - version=version, + use_scm_version={ + 'write_to': 'docker/_version.py' + }, description="A Python library for the Docker Engine API.", long_description=long_description, long_description_content_type='text/markdown', @@ -54,6 +53,7 @@ setup( 'Tracker': 'https://github.com/docker/docker-py/issues', }, packages=find_packages(exclude=["tests.*", "tests"]), + setup_requires=['setuptools_scm'], install_requires=requirements, tests_require=test_requirements, extras_require=extras_require, diff --git a/tests/Dockerfile b/tests/Dockerfile index e24da47..cf2cd67 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -1,5 +1,5 @@ +# syntax = docker/dockerfile:1.4 ARG PYTHON_VERSION=3.10 - FROM python:${PYTHON_VERSION} ARG APT_MIRROR @@ -29,11 +29,16 @@ RUN curl -sSL -o /opt/docker-credential-pass.tar.gz \ chmod +x /usr/local/bin/docker-credential-pass WORKDIR /src + COPY requirements.txt /src/requirements.txt -RUN pip install -r requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt COPY test-requirements.txt /src/test-requirements.txt -RUN pip install -r test-requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r test-requirements.txt COPY . /src -RUN pip install . +ARG SETUPTOOLS_SCM_PRETEND_VERSION=99.0.0-docker +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -e . |