Skip to content

Commit

Permalink
Merge pull request #93 from dwhswenson/release-0.3.0
Browse files Browse the repository at this point in the history
Release 0.3.0
  • Loading branch information
dwhswenson authored Jan 30, 2021
2 parents 7e2630a + e048806 commit 0be82e9
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .autorelease/install-autorelease
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python -m pip install -e .
5 changes: 5 additions & 0 deletions .autorelease/test-testpypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Using custom test-testpypi"
cd ~
python -c "import autorelease"
7 changes: 4 additions & 3 deletions .github/workflows/autorelease-default-env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
INSTALL_AUTORELEASE="python -m pip install autorelease==0.2.3"
DIR=`dirname $0`
source autorelease-env.sh
INSTALL_AUTORELEASE="python -m pip install autorelease==0.3.0"
if [ -f autorelease-env.sh ]; then
source autorelease-env.sh
fi

12 changes: 9 additions & 3 deletions .github/workflows/autorelease-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ jobs:
python-version: "3.x"
- run: | # TODO: move this to an action
source ./.github/workflows/autorelease-default-env.sh
cat autorelease-env.sh >> $GITHUB_ENV
eval $INSTALL_AUTORELEASE
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: |
python -m pip install twine wheel
Expand All @@ -27,5 +33,5 @@ jobs:
- uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
name: "Deploy to testpypi"
name: "Deploy to pypi"

10 changes: 8 additions & 2 deletions .github/workflows/autorelease-gh-rel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ jobs:
python-version: "3.7"
- run: | # TODO: move this to an action
source ./.github/workflows/autorelease-default-env.sh
cat autorelease-env.sh >> $GITHUB_ENV
eval $INSTALL_AUTORELEASE
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: |
VERSION=`python setup.py --version`
Expand Down
32 changes: 26 additions & 6 deletions .github/workflows/autorelease-prep.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# File vencdored from Autorelease; specific version information should be in
# the INSTALL_AUTORELEASE variable in autorelease-default-env.sh
name: "Autorelease"
on:
pull_request:
Expand All @@ -19,8 +21,14 @@ jobs:
python-version: "3.x"
- run: | # TODO: move this to an action
source ./.github/workflows/autorelease-default-env.sh
cat autorelease-env.sh >> $GITHUB_ENV
eval $INSTALL_AUTORELEASE
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: |
python -m pip install twine wheel
Expand Down Expand Up @@ -49,8 +57,20 @@ jobs:
python-version: "3.x"
- run: | # TODO: move this to an action
source ./.github/workflows/autorelease-default-env.sh
cat autorelease-env.sh >> $GITHUB_ENV
eval $INSTALL_AUTORELEASE
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: test-testpypi

- name: "Install testpypi version"
run: install-testpypi
- name: "Test testpypi version"
run: |
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
test-testpypi
10 changes: 5 additions & 5 deletions autorelease-travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AUTORELEASE v0.2.6
# AUTORELEASE v0.3.0
# for nonrelease, use @master
# for release, use v${VERSION}, e.g., v1.0.0
stages:
Expand All @@ -9,7 +9,7 @@ stages:
- deploy pypi

import:
- dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.2.6
- dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.2.6
- dwhswenson/autorelease:travis_stages/cut_release.yml@v0.2.6
- dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.2.6
- dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.3.0
- dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.3.0
- dwhswenson/autorelease:travis_stages/cut_release.yml@v0.3.0
- dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.3.0
17 changes: 11 additions & 6 deletions autorelease/check_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def __init__(self, versions, setup, repo_path='.', output=None):
self.git_repo_checks = autorelease.GitReleaseChecks(
repo_path=repo_path
)
self.desired_version = vers.Version(versions['setup.py'])
version_0 = list(versions.values())[0]
self.desired_version = vers.Version(version_0)
super(DefaultCheckRunner, self).__init__(output=output)
self.consistency_test = (
self.version_checks.consistency, [],
Expand Down Expand Up @@ -119,11 +120,7 @@ def select_tests_from_sysargs(self):
return self.select_tests_from_branch_event(branch, opts.event,
opts.allow_patch_skip)

def select_test_from_github_env(self):
parser = argparse.ArgumentParser()
parser.add_argument('--allow-patch-skip', action='store_true',
default=False)
opts = parser.parse_args()
def get_branch_event_from_github_env(self):
event = os.environ.get("GITHUB_EVENT_NAME", None)
ref = os.environ.get("GITHUB_REF", None)
pr_ref = os.environ.get("GITHUB_BASE_REF", None)
Expand All @@ -136,6 +133,14 @@ def select_test_from_github_env(self):
else:
raise RuntimeError("PR without branch?")
branch = self._get_branch_name(branch)
return branch, event

def select_test_from_github_env(self):
parser = argparse.ArgumentParser()
parser.add_argument('--allow-patch-skip', action='store_true',
default=False)
opts = parser.parse_args()
branch, event = self.get_branch_event_from_github_env()
print(branch, event)
return self.select_tests_from_branch_event(branch, event,
opts.allow_patch_skip)
Expand Down
2 changes: 1 addition & 1 deletion autorelease/gh_actions_stages/autorelease-default-env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INSTALL_AUTORELEASE="python -m pip install autorelease==0.2.6"
INSTALL_AUTORELEASE="python -m pip install autorelease==0.3.0"
if [ -f autorelease-env.sh ]; then
source autorelease-env.sh
fi
Expand Down
6 changes: 5 additions & 1 deletion autorelease/gh_actions_stages/autorelease-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ jobs:
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
eval $INSTALL_AUTORELEASE
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: |
python -m pip install twine wheel
Expand Down
6 changes: 5 additions & 1 deletion autorelease/gh_actions_stages/autorelease-gh-rel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ jobs:
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
eval $INSTALL_AUTORELEASE
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: |
VERSION=`python setup.py --version`
Expand Down
24 changes: 20 additions & 4 deletions autorelease/gh_actions_stages/autorelease-prep.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# File vencdored from Autorelease; specific version information should be in
# the INSTALL_AUTORELEASE variable in autorelease-default-env.sh
name: "Autorelease"
on:
pull_request:
Expand All @@ -22,7 +24,11 @@ jobs:
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
eval $INSTALL_AUTORELEASE
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: |
python -m pip install twine wheel
Expand Down Expand Up @@ -54,7 +60,17 @@ jobs:
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
eval $INSTALL_AUTORELEASE
if [ -f "./.autorelease/install-autorelease" ]; then
source ./.autorelease/install-autorelease
else
eval $INSTALL_AUTORELEASE
fi
name: "Install autorelease"
- run: test-testpypi

- name: "Install testpypi version"
run: install-testpypi
- name: "Test testpypi version"
run: |
if [ -f "autorelease-env.sh" ]; then
cat autorelease-env.sh >> $GITHUB_ENV
fi
test-testpypi
42 changes: 42 additions & 0 deletions autorelease/scripts/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import yaml

from packaging.version import Version

from autorelease.version_checks import parse_versions
from autorelease.utils import import_setup
from autorelease import DefaultCheckRunner

def checker_from_yaml_dict(release_check):
repo_path = release_check.get('repo_path', '.')
release_branches = release_check.get('release-branches', [])
release_tag_format = release_check.get('release-tag', "v{BASE_VERSION}")
versions = parse_versions(release_check['versions'])
base_version = Version(list(versions.values())[0]).base_version
release_tag = release_tag_format.format(BASE_VERSION=base_version)
setup = import_setup(directory=repo_path)

checker = DefaultCheckRunner(
versions=versions,
setup=setup,
repo_path=repo_path
)
checker.release_branches = release_branches + [release_tag]
return checker


def run_checks(yml, branch=None, event=None, allow_patch_skip=False):
dct = yaml.load(yml, Loader=yaml.FullLoader)
release_check = dct['release-check']
checker = checker_from_yaml_dict(release_check)
if branch is None and event is None:
branch, event = checker.get_branch_event_from_github_env()

tests = checker.select_tests_from_branch_event(branch, event,
allow_patch_skip)
checker.run_as_test(tests)


if __name__ == "__main__":
with open("autorelease.yml", 'r') as f:
run_checks(f)

7 changes: 7 additions & 0 deletions autorelease/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import click

from autorelease.scripts.vendor import vendor_actions
from autorelease.scripts.check import run_checks

@click.group()
def cli():
pass

@cli.command()
@click.option('--conf', type=click.File('r'), default='autorelease.yml')
@click.option('--branch', default=None)
@click.option('--event', default=None)
def check(conf, branch, event):
run_checks(conf, branch, event)

@click.group()
def vendor():
Expand Down
25 changes: 25 additions & 0 deletions autorelease/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import yaml
import re
import os
import sys

def conda_recipe_version(recipe_file):
with open(recipe_file) as f:
Expand All @@ -10,3 +12,26 @@ def github_url_to_owner_repo(url):
pattern = ".*github.com[\:\/]([^\/]+)\/(.*)\.git"
match = re.match(pattern, url)
return match.groups()


def import_setup(directory='.'):
"""Return the imported setup.py from the given directory"""
if sys.version_info > (3, ):
return _import_setup_py3(directory)
else:
return _import_setup_py2(directory)


def _import_setup_py2(directory):
import imp
return imp.load_source('setup', os.path.join(directory, 'setup.py'))


def _import_setup_py3(directory):
import importlib.util
spec = importlib.util.spec_from_file_location(
'setup', os.path.join(directory, 'setup.py')
)
setup = importlib.util.module_from_spec(spec)
spec.loader.exec_module(setup)
return setup
25 changes: 25 additions & 0 deletions autorelease/version_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
import re
import packaging.version as vers

from autorelease.version import get_setup_version # reuse the vendored
from autorelease.utils import conda_recipe_version

version_getters = {
'setup-cfg': lambda path: get_setup_version(None, path),
'conda': conda_recipe_version,
}

default_args = {
'setup-cfg': ['.']
}

def parse_versions(versions_list):
versions = {}
for version_type in versions_list:
if isinstance(version_type, dict):
version_type, arg = list(version_type.items())[0]
args = [arg]
else:
args = default_args.get(version_type, [])

versions[version_type] = version_getters[version_type](*args)
return versions


class VersionReleaseChecks(object):
def __init__(self, versions, strictness='strict'):
self.versions = versions
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package:
name: autorelease
# add ".dev0" for unreleased versions
version: "0.2.6"
version: "0.3.0"

source:
path: ../../
Expand Down
21 changes: 21 additions & 0 deletions script_stages/install-testpypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ -z "$DRY" ]; then
wait-for-testpypi
fi

export PROJECT=`python setup.py --name`
export VERSION=`pypi-max-version $PROJECT`
echo "Installing ${PROJECT}==${VERSION} (allowing pre-releases)"
if [ -z "$DRY" ]; then
python -m pip install --pre --force-reinstall \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple ${PROJECT}==${VERSION}
fi

if [ -z "$PACKAGE_IMPORT_NAME" ]; then
export PACKAGE_IMPORT_NAME=$PROJECT
fi
echo "PROJECT: $PROJECT"
echo "PACKAGE_IMPORT_NAME: $PACKAGE_IMPORT_NAME"
echo "AUTORELEASE_TEST_TESTPYPI: $AUTORELEASE_TEST_TESTPYPI"
Loading

0 comments on commit 0be82e9

Please sign in to comment.