Skip to content

Commit

Permalink
Set up automatic pre-release builds from dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Apr 17, 2021
1 parent dae614e commit ff5a9c3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -96,16 +96,16 @@ jobs:
- name: Run cyclomatic complexity check
run: radon cc --show-complexity --average --order SCORE requests_cache

# Deploy stable builds on tags only
# Deploy pre-release builds from dev branch, and stable builds on tags only
release:
needs: [test, analyze]
if: startsWith(github.ref, 'refs/tags/v')
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev'
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: ${{ env.LATEST_PY_VERSION }}

- name: Install dependencies
run: pip install -U ".[build]"
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -145,3 +145,12 @@ Release steps:
- Push a new tag, e.g.: `git tag v0.1 && git push origin --tags`
- This will trigger a deployment. Verify that this completes successfully and that the new version
can be installed from pypi with `pip install`

## Pre-Releases
Pre-release builds are convenient for letting testers try out in-development changes. Versions with
the suffix `.dev` (among others) can be deployed to PyPI and installed by users with `pip install --pre`,
and are otherwise ignored by `pip install`. See python packaging docs on
[pre-release versioning](https://packaging.python.org/guides/distributing-packages-using-setuptools/#pre-release-versioning)
for more details.

A pre-release build for requests-cache will automatically be published for **any commits to the dev branch.**
3 changes: 3 additions & 0 deletions pyproject.toml
Expand Up @@ -11,6 +11,9 @@ directory = 'test-reports'
[tool.coverage.run]
branch = true
source = ['requests_cache']
omit = [
'requests_cache/__init__.py',
]

[tool.isort]
profile = "black"
Expand Down
20 changes: 19 additions & 1 deletion requests_cache/__init__.py
@@ -1,5 +1,8 @@
# flake8: noqa: E402,F401
__version__ = '0.6.2'
from logging import getLogger
from os import getenv

__version__ = '0.6.3'

try:
from .response import AnyResponse, CachedHTTPResponse, CachedResponse, ExpirationTime
Expand All @@ -17,3 +20,18 @@
# Quietly ignore ImportError, if setup.py is invoked outside a virtualenv
except ImportError:
pass


def get_prerelease_version(version: str) -> str:
"""If we're running in a GitHub Action job on the dev branch, get a prerelease semantic version
using the current build number. For example: ``1.0.0 -> 1.0.0-dev.123``
"""
if getenv('GITHUB_REF') == 'refs/heads/dev':
build_number = getenv('GITHUB_RUN_NUMBER', '0')
version = f'{version}.dev{build_number}'
getLogger(__name__).info(f'Using pre-release version: {version}')
return version


# This won't modify the version outside of a GitHub Action
__version__ = get_prerelease_version(__version__)

0 comments on commit ff5a9c3

Please sign in to comment.