Skip to content

Commit

Permalink
Build pre-releases from 'pre-release' branch, and set version suffix …
Browse files Browse the repository at this point in the history
…in CI config
  • Loading branch information
JWCook committed Apr 29, 2021
1 parent c70dfde commit ec6d2fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/build.yml
Expand Up @@ -2,7 +2,7 @@ name: Build

on:
push:
branches: [master, dev]
branches: [master, dev, pre-release]
tags: ['v*']
pull_request:
branches: [master, dev]
Expand Down Expand Up @@ -102,21 +102,26 @@ jobs:
- name: Run cyclomatic complexity check
run: radon cc --show-complexity --average --order SCORE requests_cache

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

- name: Set pre-release version number
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "PRE_RELEASE_SUFFIX=.dev${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
- name: Install dependencies
run: pip install -U ".[build]"
- name: Build wheel
run: python setup.py sdist bdist_wheel
run: |
python setup.py --version
python setup.py sdist bdist_wheel
- name: Deploy to pypi
env:
TWINE_USERNAME: __token__
Expand Down
16 changes: 1 addition & 15 deletions requests_cache/__init__.py
Expand Up @@ -3,6 +3,7 @@
from os import getenv

__version__ = '0.7.0'
__version__ += getenv('PRE_RELEASE_SUFFIX', '')

logger = getLogger(__name__)

Expand All @@ -23,18 +24,3 @@
# Ignore ImportErrors, if setup.py is invoked outside a virtualenv
except ImportError as e:
logger.warning(e)


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}'
logger.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 ec6d2fb

Please sign in to comment.