Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to create a release on GitHub Actions from a tag #2338

Closed
wants to merge 1 commit into from

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Aug 20, 2020

Summary of changes

Add a script to create a release on GitHub Actions from a tag.

Usage:

$ python tools/create_release.py --help
usage: create_release.py [-h] [repo] [tag]

Create a release on GitHub Actions from a tag.

positional arguments:
  repo        Repo to release to (default: pypa/setuptools)
  tag         Tag to release (default: v49.7.0)

optional arguments:
  -h, --help  show this help message and exit

Calls finalize.get_version and prepends v to get the default tag.

Needs a GITHUB_TOKEN environment variable.

Example in my fork with explicit args:

$ git tag v49.6.0.8
$ git push origin v49.6.0.8
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/hugovk/setuptools
 * [new tag]           v49.6.0.8 -> v49.6.0.8
$ python tools/create_release.py hugovk/setuptools v49.6.0.8
Creating release v49.6.0.8 at hugovk/setuptools
Released to https://github.com/hugovk/setuptools/releases/tag/v49.6.0.8

API docs: https://docs.github.com/en/rest/reference/repos#create-a-release

I'd need some guidance if this is to go in https://github.com/jaraco/skeleton first.

A body parameter can be used to add release notes, I'd suggest this be added in a follow-up once the general flow is working.

Closes #2328.

Pull Request Checklist

  • [n/a] Changes have tests
  • [n/a] News fragment added in changelog.d. See documentation for details

@jaraco
Copy link
Member

jaraco commented Aug 30, 2020

So I decided to take inspiration from this PR and put together a routine in a library to do the work in jaraco/jaraco.develop@178c073

But when I ran it on a recent release of keyring, I got a 403 Forbidden.

keyring master $ pip-run setuptools git+https://github.com/jaraco/jaraco.develop@178c073 -- -m jaraco.develop.create-github-release
Collecting git+https://github.com/jaraco/jaraco.develop@178c073
  Cloning https://github.com/jaraco/jaraco.develop (to revision 178c073) to /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-req-build-09edlulu
  WARNING: Did not find branch or tag '178c073', assuming revision or ref.
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting setuptools
  Using cached setuptools-49.6.0-py3-none-any.whl (803 kB)
Collecting requests-toolbelt
  Using cached requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
Collecting jaraco.ui
  Using cached jaraco.ui-2.0.1-py2.py3-none-any.whl (7.5 kB)
Collecting keyring
  Using cached keyring-21.4.0-py3-none-any.whl (31 kB)
Collecting autocommand
  Using cached autocommand-2.2.1-py3-none-any.whl (22 kB)
Collecting requests<3.0.0,>=2.0.1
  Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB)
Collecting jaraco.text
  Using cached jaraco.text-3.2.0-py2.py3-none-any.whl (8.1 kB)
Collecting six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting jaraco.classes
  Using cached jaraco.classes-3.1.0-py2.py3-none-any.whl (5.7 kB)
Collecting chardet<4,>=3.0.2
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Using cached urllib3-1.25.10-py2.py3-none-any.whl (127 kB)
Collecting jaraco.functools
  Using cached jaraco.functools-3.0.1-py3-none-any.whl (6.7 kB)
Collecting more-itertools
  Using cached more_itertools-8.5.0-py3-none-any.whl (44 kB)
Building wheels for collected packages: jaraco.develop
  Building wheel for jaraco.develop (PEP 517) ... done
  Created wheel for jaraco.develop: filename=jaraco.develop-7.0.1.dev2+g178c073-py3-none-any.whl size=7484 sha256=58d218b7deafe0d3cba959f7f5b0f944e487530a472a8541288261335cf9a450
  Stored in directory: /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-ephem-wheel-cache-97mleq6e/wheels/14/84/4d/941b19c6c41939bb21ae0e7dc4b2998c281c1c32f83e6287db
Successfully built jaraco.develop
Installing collected packages: setuptools, chardet, certifi, idna, urllib3, requests, requests-toolbelt, six, more-itertools, jaraco.functools, jaraco.text, jaraco.classes, jaraco.ui, keyring, autocommand, jaraco.develop
Successfully installed autocommand-2.2.1 certifi-2020.6.20 chardet-3.0.4 idna-2.10 jaraco.classes-3.1.0 jaraco.develop-7.0.1.dev2+g178c073 jaraco.functools-3.0.1 jaraco.text-3.2.0 jaraco.ui-2.0.1 keyring-21.4.0 more-itertools-8.5.0 requests-2.24.0 requests-toolbelt-0.9.1 setuptools-49.6.0 six-1.15.0 urllib3-1.25.10
WARNING: The wheel package is not available.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-run-eawuq_zh/jaraco/develop/create-github-release.py", line 24, in <module>
    def run():
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-run-eawuq_zh/autocommand/autocommand.py", line 66, in autocommand_decorator
    func = automain(module)(func)
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-run-eawuq_zh/autocommand/automain.py", line 55, in automain_decorator
    sys.exit(main(*args, **kwargs))
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-run-eawuq_zh/autocommand/autoparse.py", line 301, in autoparse_wrapper
    return func(*parsed_args.args, **parsed_args.kwargs)
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-run-eawuq_zh/jaraco/develop/create-github-release.py", line 38, in run
    session.post(releases, json=dict(tag_name=tag, name=tag)).raise_for_status()
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-run-eawuq_zh/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.github.com/repos/jaraco/keyring/releases

So I went to keyring and see that releases are generated automatically from tags:

image

I double-checked that the token I'm using has all repo permissions (though I don't see any settings relevant to releases).

image

@jaraco
Copy link
Member

jaraco commented Aug 30, 2020

Aha, after emitting the error message in jaraco/jaraco.develop@85b9c5e, it became clear that the request was being rejected for a missing User-Agent header, so I've fixed that (in the same commit).

Now the command runs without error.

And the releases page now looks different:

image

But that still doesn't explain why keyring is getting tags automatically reflected as releases but Setuptools isn't.

@jaraco
Copy link
Member

jaraco commented Aug 30, 2020

Thanks for drafting this PR. I was able to adapt the technique into a re-usable solution in jaraco/skeleton#23 which I hand-cherry-picked in 17cb9d6. Future releases should get Github releases. Let me know if you find otherwise.

@jaraco jaraco closed this Aug 30, 2020
@hugovk hugovk deleted the create_release branch August 30, 2020 19:27
@hugovk
Copy link
Contributor Author

hugovk commented Aug 30, 2020

Good stuff, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create GitHub "releases"?
2 participants