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

Create GitHub "releases"? #2328

Closed
hugovk opened this issue Aug 14, 2020 · 7 comments
Closed

Create GitHub "releases"? #2328

hugovk opened this issue Aug 14, 2020 · 7 comments

Comments

@hugovk
Copy link
Contributor

hugovk commented Aug 14, 2020

Tags show up at https://github.com/pypa/setuptools/releases

When tagging and releasing, would it be possible to also publish a GitHub release of that tag?

This enables users to watch "Releases only" for this repo, and get notifications on new release via the GH UI.

How to do it:

  1. https://github.com/pypa/setuptools/releases/new
  2. Select tag in "Tag version" box (e.g. v40.0.0)
  3. Click "Publish release"

There's no need to add a title or body text.

Example:

This can be automated using GitHub Actions:

Thanks!

@jaraco
Copy link
Member

jaraco commented Aug 16, 2020

I'd like to have this feature. Is there a way that it can be made to work without adding any steps to the developer's workflow? That is, the current release workflow is to run tox -e finalize, which tags a commit. If the tests pass for that commit, a release is cut through CI through tox -e release. I'd like the process of creating a GitHub release to happen at the same time as the upload is made to PyPI (i.e. during the release), probably just after.

Preferably this behavior should be implemented at jaraco/skeleton and then ported over here.

Would you be willing to work out the implementation?

@jaraco
Copy link
Member

jaraco commented Aug 16, 2020

Extra credit if the release notes can be extracted from the changelog so they're actually published.

@hugovk
Copy link
Contributor Author

hugovk commented Aug 17, 2020

Yep, I can have a look!

Here's the simplest, using GitHub Actions:

It runs when a tag is pushed, for example in my fork:

Pros:

  • runs automatically in the repo when tags pushed
  • no need for any extra tokens or tools
  • no extra steps for the developer

Cons:

  • This doesn't quite fit the required flow: it creates the release as part of tox -e finalize (tag pushed), not tox -e release (after tests pass and developer decides to release)

To do it as part of tox -e release, I think the best thing to do is call the GitHub API. This'll need the developer to create a GH token and (probably) store it an an env var.

First question, would that be an acceptable requirement? (I see tox -e release uses TWINE_PASSWORD and TIDELIFT_TOKEN, so I'd guess so.)

There's a bunch of CLI tools that already exist for creating releases, or it should be pretty straightforward to call the API via requests or curl.

@hugovk
Copy link
Contributor Author

hugovk commented Aug 17, 2020

Well that's pretty easy:

#!/usr/bin/env python3
import json
import os
import sys
from urllib.request import Request, urlopen

repo = sys.argv[1]
tag = sys.argv[2]

token = os.environ["GITHUB_TOKEN"]

url_template = "https://{}.github.com/repos/" + repo + "/releases"

json.loads(
    urlopen(
        Request(
            url_template.format("api"),
            json.dumps({"tag_name": tag, "name": tag}).encode(),
            headers={
                "Accept": "application/vnd.github.v3+json",
                "Authorization": "token " + token,
            },
        )
    )
    .read()
    .decode()
)
python create-release.py "hugovk/setuptools" v49.6.0.5

-> https://github.com/hugovk/setuptools/releases/tag/v49.6.0.5

Re: https://docs.github.com/en/rest/reference/repos#releases

@hugovk
Copy link
Contributor Author

hugovk commented Aug 20, 2020

Please see PR #2338.

@jaraco
Copy link
Member

jaraco commented Sep 2, 2020

I've seen the proposed fix isn't working, because the mapping from Github-token to GITHUB_TOKEN wasn't present :(.

@jaraco jaraco reopened this Sep 2, 2020
@jaraco jaraco closed this as completed in 8eb9efa Sep 2, 2020
@hugovk
Copy link
Contributor Author

hugovk commented Sep 3, 2020

I got the notification for https://github.com/pypa/setuptools/releases/tag/v50.1.0, 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 a pull request may close this issue.

2 participants