Skip to content

Commit

Permalink
ci: add workflow for releases (#3018)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
milas authored Jul 30, 2022
1 parent 828d06f commit cd2c35a
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ max_line_length = 80

[*.md]
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_size = 2
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Python package

on: [push, pull_request]

env:
DOCKER_BUILDKIT: '1'

jobs:
flake8:
runs-on: ubuntu-latest
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ html/*
_build/
README.rst

# setuptools_scm
_version.py

env/
venv/
.idea/
*.iml
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ ARG PYTHON_VERSION=3.10

FROM python:${PYTHON_VERSION}

RUN mkdir /src
WORKDIR /src

COPY requirements.txt /src/requirements.txt
Expand All @@ -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 .
3 changes: 1 addition & 2 deletions docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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'
4 changes: 2 additions & 2 deletions docker/constants.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -28,7 +28,7 @@
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
Expand Down
16 changes: 14 additions & 2 deletions docker/version.py
Original file line number Diff line number Diff line change
@@ -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'
11 changes: 5 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@
# |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.
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]

[tool.setuptools_scm]
write_to = 'docker/_version.py'
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
'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]

Expand All @@ -42,7 +39,9 @@

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',
Expand All @@ -54,6 +53,7 @@
'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,
Expand Down
13 changes: 9 additions & 4 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax = docker/dockerfile:1.4
ARG PYTHON_VERSION=3.10

FROM python:${PYTHON_VERSION}

ARG APT_MIRROR
Expand Down Expand Up @@ -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 .

0 comments on commit cd2c35a

Please sign in to comment.