From 82c8c8908c9b43b11b67ed48505717102379e91d Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Sun, 22 Nov 2020 18:24:27 +0100 Subject: [PATCH 01/21] possible fix for problems with release --- .github/workflows/autorelease-gh-rel.yml | 2 +- autorelease/scripts/release.py | 29 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/autorelease-gh-rel.yml b/.github/workflows/autorelease-gh-rel.yml index 0f135de..f9e294e 100644 --- a/.github/workflows/autorelease-gh-rel.yml +++ b/.github/workflows/autorelease-gh-rel.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.x" + python-version: "3.7" - run: | # TODO: move this to an action source ./.github/workflows/autorelease-default-env.sh cat autorelease-env.sh >> $GITHUB_ENV diff --git a/autorelease/scripts/release.py b/autorelease/scripts/release.py index 35e52a6..b20fcc6 100644 --- a/autorelease/scripts/release.py +++ b/autorelease/scripts/release.py @@ -29,16 +29,7 @@ def github_url_to_owner_repo(url): match = re.match(pattern, url) return match.groups() -def main(): - parser = make_parser() - opts = parser.parse_args() - - logger = make_logger(opts.quiet) - - print(opts) - - repo = git.Repo(opts.repo) - +def get_github_info(repo): upstream = [r for r in repo.remotes if r.name == 'upstream'] origin = [r for r in repo.remotes if r.name == 'origin'] if not upstream: @@ -51,8 +42,26 @@ def main(): upstream = upstream[0] origin = origin[0] + print(repo.remotes) + for remote in repo.remotes: + print(remote.url) + print(upstream.url) + print(origin.url) + (owner, name) = github_url_to_owner_repo(upstream.url) (user, _) = github_url_to_owner_repo(origin.url) + return owner, user, name + +def main(): + parser = make_parser() + opts = parser.parse_args() + + logger = make_logger(opts.quiet) + + print(opts) + + repo = git.Repo(opts.repo) + owner, user, name = get_github_info(repo) if opts.repo_owner is not None: owner = opts.repo_owner From a92c9f22ad2c1579205ff403b49c67134da8e809 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 06:48:49 +0100 Subject: [PATCH 02/21] add temporary test --- .github/workflows/unit-tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e805e56..25878b5 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -38,6 +38,13 @@ jobs: python -m pip install -e . - name: "Versions" run: pip list + - name: "Temporary" + run: python -c " + from autorelease.scripts.release import get_github_info + import git + repo = git.Repo('.') + print(get_github_info(repo)) + " - name: "Tests" env: PR_BRANCH: ${{ github.event.pull_request.base.ref }} From 0381f9781f9ccc6f4a0e7aaa2f3d508979746f21 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 06:52:57 +0100 Subject: [PATCH 03/21] fix indentation --- .github/workflows/unit-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 25878b5..58c77c6 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -40,10 +40,10 @@ jobs: run: pip list - name: "Temporary" run: python -c " - from autorelease.scripts.release import get_github_info - import git - repo = git.Repo('.') - print(get_github_info(repo)) +from autorelease.scripts.release import get_github_info +import git +repo = git.Repo('.') +print(get_github_info(repo)) " - name: "Tests" env: From 3b9ad4687f5411f4edff067a76f6a2446bf950d9 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 06:55:10 +0100 Subject: [PATCH 04/21] ugly as one-liner --- .github/workflows/unit-tests.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 58c77c6..d0eb0a4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -39,12 +39,7 @@ jobs: - name: "Versions" run: pip list - name: "Temporary" - run: python -c " -from autorelease.scripts.release import get_github_info -import git -repo = git.Repo('.') -print(get_github_info(repo)) - " + run: python -c " from autorelease.scripts.release import get_github_info; import git; repo = git.Repo('.'); print(get_github_info(repo)); " - name: "Tests" env: PR_BRANCH: ${{ github.event.pull_request.base.ref }} From c23281e384ed5545d4573870b5354180336e599d Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 06:58:51 +0100 Subject: [PATCH 05/21] that counts as indent? --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index d0eb0a4..4cac025 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -39,7 +39,7 @@ jobs: - name: "Versions" run: pip list - name: "Temporary" - run: python -c " from autorelease.scripts.release import get_github_info; import git; repo = git.Repo('.'); print(get_github_info(repo)); " + run: python -c "from autorelease.scripts.release import get_github_info; import git; repo = git.Repo('.'); print(get_github_info(repo)); " - name: "Tests" env: PR_BRANCH: ${{ github.event.pull_request.base.ref }} From 39d8d15f71ab82a90860046079b260d1da5266b2 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 07:07:17 +0100 Subject: [PATCH 06/21] allow repo URLs without the explicit .git --- autorelease/scripts/release.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/autorelease/scripts/release.py b/autorelease/scripts/release.py index b20fcc6..1d7ea02 100644 --- a/autorelease/scripts/release.py +++ b/autorelease/scripts/release.py @@ -25,9 +25,12 @@ def make_logger(quiet=False): pass def github_url_to_owner_repo(url): - pattern = ".*github.com[\:\/]([^\/]+)\/(.*)\.git" + pattern = ".*github.com[\:\/]([^\/]+)\/(.*)" match = re.match(pattern, url) - return match.groups() + owner, name = match.group() + if name.endswith('.git'): + name = name[:-4] + return owner, name def get_github_info(repo): upstream = [r for r in repo.remotes if r.name == 'upstream'] From 3ccb0e64b2f77df808c0fb267ac92d1be4cc5631 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 07:46:59 +0100 Subject: [PATCH 07/21] tiny typo --- autorelease/scripts/release.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autorelease/scripts/release.py b/autorelease/scripts/release.py index 1d7ea02..e4274c5 100644 --- a/autorelease/scripts/release.py +++ b/autorelease/scripts/release.py @@ -27,7 +27,7 @@ def make_logger(quiet=False): def github_url_to_owner_repo(url): pattern = ".*github.com[\:\/]([^\/]+)\/(.*)" match = re.match(pattern, url) - owner, name = match.group() + owner, name = match.groups() if name.endswith('.git'): name = name[:-4] return owner, name From 8b12a5f062305d34d23cb2eace0cb6119a9fb7e2 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 07:51:17 +0100 Subject: [PATCH 08/21] Remove temporary test --- .github/workflows/unit-tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 4cac025..e805e56 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -38,8 +38,6 @@ jobs: python -m pip install -e . - name: "Versions" run: pip list - - name: "Temporary" - run: python -c "from autorelease.scripts.release import get_github_info; import git; repo = git.Repo('.'); print(get_github_info(repo)); " - name: "Tests" env: PR_BRANCH: ${{ github.event.pull_request.base.ref }} From 6e75e242fed3311026cf9c28893fda7573410093 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 08:43:26 +0100 Subject: [PATCH 09/21] Bump to version 0.2.4.dev0 --- autorelease-travis.yml | 10 +++++----- devtools/conda-recipe/meta.yaml | 2 +- setup.cfg | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/autorelease-travis.yml b/autorelease-travis.yml index 01ffa0a..bbd4d90 100644 --- a/autorelease-travis.yml +++ b/autorelease-travis.yml @@ -1,4 +1,4 @@ -# AUTORELEASE v0.2.3 +# AUTORELEASE v0.2.4.dev0 # for nonrelease, use @master # for release, use v${VERSION}, e.g., v1.0.0 stages: @@ -9,7 +9,7 @@ stages: - deploy pypi import: - - dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.2.3 - - dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.2.3 - - dwhswenson/autorelease:travis_stages/cut_release.yml@v0.2.3 - - dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.2.3 + - dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@master + - dwhswenson/autorelease:travis_stages/test_testpypi.yml@master + - dwhswenson/autorelease:travis_stages/cut_release.yml@master + - dwhswenson/autorelease:travis_stages/deploy_pypi.yml@master diff --git a/devtools/conda-recipe/meta.yaml b/devtools/conda-recipe/meta.yaml index f1110f4..9577447 100644 --- a/devtools/conda-recipe/meta.yaml +++ b/devtools/conda-recipe/meta.yaml @@ -1,7 +1,7 @@ package: name: autorelease # add ".dev0" for unreleased versions - version: "0.2.3" + version: "0.2.4.dev0" source: path: ../../ diff --git a/setup.cfg b/setup.cfg index 12970fa..4a6425c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = autorelease -version = 0.2.3 +version = 0.2.4.dev0 # version should end in .dev0 if this isn't to be released short_description = Tools to keep the release process clean. description = Tools to keep the release process clean. From ad2cc6729623ae4c5b4e555939cb848a820d157c Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 15:43:37 +0100 Subject: [PATCH 10/21] New CLI skeleton; support for vendoring GH actions --- .../autorelease-default-env.sh | 4 ++ .../gh_actions_stages/autorelease-deploy.yml | 31 ++++++++++ .../gh_actions_stages/autorelease-gh-rel.yml | 27 +++++++++ .../gh_actions_stages/autorelease-prep.yml | 56 +++++++++++++++++++ autorelease/scripts/cli.py | 22 ++++++++ autorelease/scripts/vendor.py | 23 ++++++++ setup.cfg | 6 ++ 7 files changed, 169 insertions(+) create mode 100644 autorelease/gh_actions_stages/autorelease-default-env.sh create mode 100644 autorelease/gh_actions_stages/autorelease-deploy.yml create mode 100644 autorelease/gh_actions_stages/autorelease-gh-rel.yml create mode 100644 autorelease/gh_actions_stages/autorelease-prep.yml create mode 100644 autorelease/scripts/cli.py create mode 100644 autorelease/scripts/vendor.py diff --git a/autorelease/gh_actions_stages/autorelease-default-env.sh b/autorelease/gh_actions_stages/autorelease-default-env.sh new file mode 100644 index 0000000..5609e9b --- /dev/null +++ b/autorelease/gh_actions_stages/autorelease-default-env.sh @@ -0,0 +1,4 @@ +INSTALL_AUTORELEASE="python -m pip install autorelease==0.2.3" +DIR=`dirname $0` +source autorelease-env.sh + diff --git a/autorelease/gh_actions_stages/autorelease-deploy.yml b/autorelease/gh_actions_stages/autorelease-deploy.yml new file mode 100644 index 0000000..89aaeac --- /dev/null +++ b/autorelease/gh_actions_stages/autorelease-deploy.yml @@ -0,0 +1,31 @@ +name: Autorelease +on: + release: + types: [published] + +jobs: + deploy_pypi: + runs-on: ubuntu-latest + name: "Deploy to PyPI" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + 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 + name: "Install autorelease" + - run: | + python -m pip install twine wheel + name: "Install release tools" + - run: | + python setup.py sdist bdist_wheel + twine check dist/* + name: "Build and check package" + - uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.pypi_password }} + name: "Deploy to testpypi" + diff --git a/autorelease/gh_actions_stages/autorelease-gh-rel.yml b/autorelease/gh_actions_stages/autorelease-gh-rel.yml new file mode 100644 index 0000000..f9e294e --- /dev/null +++ b/autorelease/gh_actions_stages/autorelease-gh-rel.yml @@ -0,0 +1,27 @@ +name: Autorelease +on: + push: + branches: + - stable + +jobs: + release-gh: + runs-on: ubuntu-latest + name: "Cut release" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + 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 + name: "Install autorelease" + - run: | + VERSION=`python setup.py --version` + PROJECT=`python setup.py --name` + echo $PROJECT $VERSION + autorelease-release --project $PROJECT --version $VERSION --token $AUTORELEASE_TOKEN + env: + AUTORELEASE_TOKEN: ${{ secrets.AUTORELEASE_TOKEN }} diff --git a/autorelease/gh_actions_stages/autorelease-prep.yml b/autorelease/gh_actions_stages/autorelease-prep.yml new file mode 100644 index 0000000..48c82ba --- /dev/null +++ b/autorelease/gh_actions_stages/autorelease-prep.yml @@ -0,0 +1,56 @@ +name: "Autorelease" +on: + pull_request: + branches: + - stable + +defaults: + run: + shell: bash + +jobs: + deploy_testpypi: + runs-on: ubuntu-latest + name: "Deployment test" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + 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 + name: "Install autorelease" + - run: | + python -m pip install twine wheel + name: "Install release tools" + - run: | + bump-dev-version + python setup.py --version + name: "Bump testpypi dev version" + - run: | + python setup.py sdist bdist_wheel + twine check dist/* + name: "Build and check package" + - uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.testpypi_password }} + repository_url: https://test.pypi.org/legacy/ + name: "Deploy to testpypi" + test_testpypi: + runs-on: ubuntu-latest + name: "Test deployed" + needs: deploy_testpypi + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + 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 + name: "Install autorelease" + - run: test-testpypi + diff --git a/autorelease/scripts/cli.py b/autorelease/scripts/cli.py new file mode 100644 index 0000000..624d90b --- /dev/null +++ b/autorelease/scripts/cli.py @@ -0,0 +1,22 @@ +import click + +from autorelease.scripts.vendor import vendor_actions + +@click.group() +def cli(): + pass + + +@click.group() +def vendor(): + pass + +@vendor.command() +def actions(): + print("vendoring actions") + vendor_actions(base_path='.') + +cli.add_command(vendor) + +if __name__ == "__main__": + cli() diff --git a/autorelease/scripts/vendor.py b/autorelease/scripts/vendor.py new file mode 100644 index 0000000..787415d --- /dev/null +++ b/autorelease/scripts/vendor.py @@ -0,0 +1,23 @@ +import pkg_resources +import pathlib +import shutil + +import click + +def vendor(resources, base_path, relative_target_dir): + for resource in resources: + orig_loc = pkg_resources.resource_filename('autorelease', resource) + name = pathlib.Path(orig_loc).name + target_dir = base_path / relative_target_dir + target_dir.mkdir(parents=True, exist_ok=True) + target_loc = base_path / relative_target_dir / name + # print(f"cp {orig_loc} {target_loc}") + shutil.copy(orig_loc, target_loc) + +def vendor_actions(base_path): + resources = ['autorelease-default-env.sh', 'autorelease-prep.yml', + 'autorelease-gh-rel.yml', 'autorelease-deploy.yml'] + resources = ['gh_actions_stages/' + res for res in resources] + target_dir = pathlib.Path('.github/workflows') + vendor(resources, base_path, target_dir) + diff --git a/setup.cfg b/setup.cfg index 4a6425c..8c1c9fc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,11 +35,16 @@ install_requires = future requests python-dateutil + click packages = find: scripts = script_stages/deploy-pypi script_stages/test-testpypi +[options.package_data] +autorelease = + - ../gh_actions_stages/* + [options.entry_points] console_scripts = autorelease-release = autorelease.scripts.release:main @@ -47,6 +52,7 @@ console_scripts = bump-dev-version = autorelease.scripts.bump_dev_version:main pypi-max-version = autorelease.scripts.bump_dev_version:get_max wait-for-testpypi = autorelease.scripts.bump_dev_version:wait_for_max + autorelease = autorelease.scripts.cli:cli [bdist_wheel] universal=1 From 4591b95cf24c896a6abce59f61066c678e4359f8 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 16:33:18 +0100 Subject: [PATCH 11/21] debugging on master --- .github/workflows/unit-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e805e56..bfdf4b6 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -42,10 +42,12 @@ jobs: env: PR_BRANCH: ${{ github.event.pull_request.base.ref }} PUSH_REF: ${{ github.event.push.ref }} + REF: ${{ github.ref }} EVENT: ${{ github.event_name }} #EVENT_INFO: ${{ toJson(github.event) }} # useful debug BRANCH: "${{github.event.pull_request.base.ref}}${{github.event.push.ref}}" run: | + echo "PUSH_REF: $PUSH_REF" echo "EVENT: $EVENT" echo "BRANCH: $BRANCH" python -c "import autorelease" From 4a38369ba5f2d346fdd1c2f9cf1c4c296fe1c044 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 18:14:35 +0100 Subject: [PATCH 12/21] More fixes on master --- .github/workflows/unit-tests.yml | 9 +++++++-- autorelease/check_runners.py | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index bfdf4b6..324ce9a 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -7,6 +7,8 @@ on: push: branches: - master + tags: + - "v*" schedule: - cron: "25 5 * * *" @@ -41,12 +43,15 @@ jobs: - name: "Tests" env: PR_BRANCH: ${{ github.event.pull_request.base.ref }} - PUSH_REF: ${{ github.event.push.ref }} REF: ${{ github.ref }} EVENT: ${{ github.event_name }} #EVENT_INFO: ${{ toJson(github.event) }} # useful debug - BRANCH: "${{github.event.pull_request.base.ref}}${{github.event.push.ref}}" run: | + if [ "$EVENT" = "push" ]; then + BRANCH=$REF + else + BRANCH=$PR_BRANCH + fi echo "PUSH_REF: $PUSH_REF" echo "EVENT: $EVENT" echo "BRANCH: $BRANCH" diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 1b59af4..036fcec 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -91,7 +91,12 @@ def select_tests_from_sysargs(self): parser.add_argument('--allow-patch-skip', action='store_true', default=False) opts = parser.parse_args() - if opts.branch in self.release_branches: + if opts.branch.startswith('refs/heads/'): + branch = opts.branch[11:] + else: + branch = opts.branch + + if branch in self.release_branches: print("TESTING AS RELEASE") allow_equal = (opts.event == 'cron' or opts.branch == self.tag_branch) From 0f21544af85d870b8f299acb029d5b387aebfc08 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Mon, 23 Nov 2020 18:17:10 +0100 Subject: [PATCH 13/21] tags are a push --- .github/workflows/unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 324ce9a..a88fb06 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -7,8 +7,8 @@ on: push: branches: - master - tags: - - "v*" + tags: + - "v*" schedule: - cron: "25 5 * * *" From 897348a9f90a8d381f4344df6a2036f5f8561220 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Tue, 24 Nov 2020 08:04:59 +0100 Subject: [PATCH 14/21] autorelease-env.sh is optional --- autorelease/gh_actions_stages/autorelease-default-env.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autorelease/gh_actions_stages/autorelease-default-env.sh b/autorelease/gh_actions_stages/autorelease-default-env.sh index 5609e9b..74dd461 100644 --- a/autorelease/gh_actions_stages/autorelease-default-env.sh +++ b/autorelease/gh_actions_stages/autorelease-default-env.sh @@ -1,4 +1,5 @@ INSTALL_AUTORELEASE="python -m pip install autorelease==0.2.3" -DIR=`dirname $0` -source autorelease-env.sh +if [ -f autorelease-env.sh ]; then + source autorelease-env.sh +fi From 350d2970e8dfab91234ed0a086bbd177164a96d0 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Tue, 24 Nov 2020 11:31:10 +0100 Subject: [PATCH 15/21] Fix autorelease for tags, too --- .github/workflows/unit-tests.yml | 2 +- autorelease/check_runners.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index a88fb06..96addf4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -47,7 +47,7 @@ jobs: EVENT: ${{ github.event_name }} #EVENT_INFO: ${{ toJson(github.event) }} # useful debug run: | - if [ "$EVENT" = "push" ]; then + if [ "$EVENT" != "pull_request" ]; then BRANCH=$REF else BRANCH=$PR_BRANCH diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 036fcec..1008cc1 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -93,6 +93,8 @@ def select_tests_from_sysargs(self): opts = parser.parse_args() if opts.branch.startswith('refs/heads/'): branch = opts.branch[11:] + elif opts.branch.startswith('refs/tags/'): + branch = opts.branch[10:] else: branch = opts.branch From 4e0500ce0da40543a894eb176c843067875f7d6a Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Tue, 24 Nov 2020 11:36:45 +0100 Subject: [PATCH 16/21] refactor; treat "schedule" same as "cron" --- autorelease/check_runners.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 1008cc1..c3e1804 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -83,6 +83,17 @@ def _reasonable_desired_version_test(self, allow_equal, ) ] + @staticmethod + def _get_branch_name(branch_name): + if branch_name.startswith('refs/heads/'): + branch = branch_name[11:] + elif branch_name.startswith('refs/tags/'): + branch = branch_name[10:] + else: + branch = branch_name + + return branch + def select_tests_from_sysargs(self): # TODO: this can be cleaned up by separating reusable parts parser = argparse.ArgumentParser() @@ -91,17 +102,13 @@ def select_tests_from_sysargs(self): parser.add_argument('--allow-patch-skip', action='store_true', default=False) opts = parser.parse_args() - if opts.branch.startswith('refs/heads/'): - branch = opts.branch[11:] - elif opts.branch.startswith('refs/tags/'): - branch = opts.branch[10:] - else: - branch = opts.branch + branch = self._get_branch_name(opts.branch) if branch in self.release_branches: print("TESTING AS RELEASE") allow_equal = (opts.event == 'cron' - or opts.branch == self.tag_branch) + or opts.event == 'schedule' + or branch == self.tag_branch) tests = (self.tests + self._reasonable_desired_version_test( allow_equal=allow_equal, From 8e3fb11725ca2ac4c3d9a188285c3ed06aec4f67 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Sat, 19 Dec 2020 11:47:53 +0100 Subject: [PATCH 17/21] More improvements to GitHub Actions support (#80) * more changes for better support of github actions * fixes * add allow_patch_skip support * helps to add the option... * Use generic select_tests * that's odd * fix typo * it doesn't actually return the string true --- .github/workflows/unit-tests.yml | 4 +-- autorelease/check_runners.py | 32 +++++++++++++++++++ .../gh_actions_stages/autorelease-deploy.yml | 6 ++-- .../gh_actions_stages/autorelease-gh-rel.yml | 4 ++- .../gh_actions_stages/autorelease-prep.yml | 8 +++-- release_check.py | 2 +- script_stages/test-testpypi | 2 +- 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 96addf4..36c8411 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -52,10 +52,10 @@ jobs: else BRANCH=$PR_BRANCH fi + echo "Generic: $GITHUB_REF" echo "PUSH_REF: $PUSH_REF" echo "EVENT: $EVENT" echo "BRANCH: $BRANCH" python -c "import autorelease" autorelease-release -h - python release_check.py --branch $BRANCH --event $EVENT \ - --allow-patch-skip + python release_check.py diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index c3e1804..194061f 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -1,5 +1,6 @@ from __future__ import print_function import sys +import os import textwrap import argparse import packaging.version as vers @@ -94,6 +95,15 @@ def _get_branch_name(branch_name): return branch + def select_tests(self): + print(os.environ.get("GITHUB_ACTION")) + if os.environ.get("GITHUB_ACTION", None): + tests = self.select_test_from_github_env() + else: + tests = self.select_tests_from_sysargs() + return tests + + def select_tests_from_sysargs(self): # TODO: this can be cleaned up by separating reusable parts parser = argparse.ArgumentParser() @@ -104,6 +114,28 @@ def select_tests_from_sysargs(self): opts = parser.parse_args() branch = self._get_branch_name(opts.branch) + 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() + event = os.environ.get("GITHUB_EVENT", None) + ref = os.environ.get("GITHUB_REF", None) + pr_ref = os.environ.get("GITHUB_BASE_REF", None) + if event == "pull_request" and pr_ref is not None: + branch = pr_ref + elif event != "pull_request": + branch = ref + else: + raise RuntimeError("PR without branch?") + return self.select_tests_from_branch_event(branch, event, + opts.allow_patch_skip) + + + def select_tests_from_branch_event(self, branch, event, allow_patch_skip): if branch in self.release_branches: print("TESTING AS RELEASE") allow_equal = (opts.event == 'cron' diff --git a/autorelease/gh_actions_stages/autorelease-deploy.yml b/autorelease/gh_actions_stages/autorelease-deploy.yml index 89aaeac..9a8f03b 100644 --- a/autorelease/gh_actions_stages/autorelease-deploy.yml +++ b/autorelease/gh_actions_stages/autorelease-deploy.yml @@ -14,7 +14,9 @@ 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 + if [ -f "autorelease-env.sh" ]; then + cat autorelease-env.sh >> $GITHUB_ENV + fi eval $INSTALL_AUTORELEASE name: "Install autorelease" - run: | @@ -27,5 +29,5 @@ jobs: - uses: pypa/gh-action-pypi-publish@master with: password: ${{ secrets.pypi_password }} - name: "Deploy to testpypi" + name: "Deploy to pypi" diff --git a/autorelease/gh_actions_stages/autorelease-gh-rel.yml b/autorelease/gh_actions_stages/autorelease-gh-rel.yml index f9e294e..bb5cd27 100644 --- a/autorelease/gh_actions_stages/autorelease-gh-rel.yml +++ b/autorelease/gh_actions_stages/autorelease-gh-rel.yml @@ -15,7 +15,9 @@ 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 + if [ -f "autorelease-env.sh" ]; then + cat autorelease-env.sh >> $GITHUB_ENV + fi eval $INSTALL_AUTORELEASE name: "Install autorelease" - run: | diff --git a/autorelease/gh_actions_stages/autorelease-prep.yml b/autorelease/gh_actions_stages/autorelease-prep.yml index 48c82ba..4967413 100644 --- a/autorelease/gh_actions_stages/autorelease-prep.yml +++ b/autorelease/gh_actions_stages/autorelease-prep.yml @@ -19,7 +19,9 @@ 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 + if [ -f "autorelease-env.sh" ]; then + cat autorelease-env.sh >> $GITHUB_ENV + fi eval $INSTALL_AUTORELEASE name: "Install autorelease" - run: | @@ -49,7 +51,9 @@ 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 + if [ -f "autorelease-env.sh" ]; then + cat autorelease-env.sh >> $GITHUB_ENV + fi eval $INSTALL_AUTORELEASE name: "Install autorelease" - run: test-testpypi diff --git a/release_check.py b/release_check.py index 12f73af..dfd7d83 100644 --- a/release_check.py +++ b/release_check.py @@ -27,7 +27,7 @@ repo_path='.' ) checker.release_branches = RELEASE_BRANCHES + [RELEASE_TAG] - tests = checker.select_tests_from_sysargs() + tests = checker.select_tests() skip = [] #skip = [checker.git_repo_checks.reasonable_desired_version] diff --git a/script_stages/test-testpypi b/script_stages/test-testpypi index aa3e6c9..7b48618 100644 --- a/script_stages/test-testpypi +++ b/script_stages/test-testpypi @@ -25,7 +25,7 @@ if [ -n "$AUTORELEASE_TEST_TESTPYPI" ]; then else python -m pip install pytest cd ~ - python -c "import $PACKAGE_IMPORT_NAME" + python -c "import $PACKAGE_IMPORT_NAME" || exit 1 py.test --pyargs $PACKAGE_IMPORT_NAME || exit 1 fi From 84d892da6844af0756099e4e69bd06fcaa43bf56 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Sat, 19 Dec 2020 11:56:37 +0100 Subject: [PATCH 18/21] Actually do the release stuff --- autorelease/check_runners.py | 6 +++--- devtools/conda-recipe/meta.yaml | 2 +- setup.cfg | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 194061f..2679620 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -138,13 +138,13 @@ def select_test_from_github_env(self): def select_tests_from_branch_event(self, branch, event, allow_patch_skip): if branch in self.release_branches: print("TESTING AS RELEASE") - allow_equal = (opts.event == 'cron' - or opts.event == 'schedule' + allow_equal = (event == 'cron' + or event == 'schedule' or branch == self.tag_branch) tests = (self.tests + self._reasonable_desired_version_test( allow_equal=allow_equal, - allow_patch_skip=opts.allow_patch_skip) + allow_patch_skip=allow_patch_skip) + self._is_release_tests(expected=True)) else: print("TESTING AS NONRELEASE") diff --git a/devtools/conda-recipe/meta.yaml b/devtools/conda-recipe/meta.yaml index 9577447..9d6b7d7 100644 --- a/devtools/conda-recipe/meta.yaml +++ b/devtools/conda-recipe/meta.yaml @@ -1,7 +1,7 @@ package: name: autorelease # add ".dev0" for unreleased versions - version: "0.2.4.dev0" + version: "0.2.4" source: path: ../../ diff --git a/setup.cfg b/setup.cfg index 8c1c9fc..ea3c613 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = autorelease -version = 0.2.4.dev0 +version = 0.2.4 # version should end in .dev0 if this isn't to be released short_description = Tools to keep the release process clean. description = Tools to keep the release process clean. From 060163883761ecd1d90d46fb928e42b3952b0936 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Sat, 19 Dec 2020 11:59:05 +0100 Subject: [PATCH 19/21] debug --- autorelease/check_runners.py | 1 + 1 file changed, 1 insertion(+) diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 2679620..9a6dae8 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -131,6 +131,7 @@ def select_test_from_github_env(self): branch = ref else: raise RuntimeError("PR without branch?") + print(branch, event) return self.select_tests_from_branch_event(branch, event, opts.allow_patch_skip) From c1ad8a81a069e038c97630e46ca54efb88d28ed1 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Sat, 19 Dec 2020 12:02:38 +0100 Subject: [PATCH 20/21] more debug --- autorelease/check_runners.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 9a6dae8..837addd 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -125,6 +125,8 @@ def select_test_from_github_env(self): event = os.environ.get("GITHUB_EVENT", None) ref = os.environ.get("GITHUB_REF", None) pr_ref = os.environ.get("GITHUB_BASE_REF", None) + print(ref, pr_ref) + print(os.environ.get("GITHUB_HEAD_REF", None)) if event == "pull_request" and pr_ref is not None: branch = pr_ref elif event != "pull_request": From 2c1583b76a87158448bdcccfd9a745cfcee642ba Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Sat, 19 Dec 2020 12:05:47 +0100 Subject: [PATCH 21/21] was I doing events wrong? --- autorelease/check_runners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autorelease/check_runners.py b/autorelease/check_runners.py index 837addd..5de6e6a 100644 --- a/autorelease/check_runners.py +++ b/autorelease/check_runners.py @@ -122,7 +122,7 @@ def select_test_from_github_env(self): parser.add_argument('--allow-patch-skip', action='store_true', default=False) opts = parser.parse_args() - event = os.environ.get("GITHUB_EVENT", None) + event = os.environ.get("GITHUB_EVENT_NAME", None) ref = os.environ.get("GITHUB_REF", None) pr_ref = os.environ.get("GITHUB_BASE_REF", None) print(ref, pr_ref)