Home

Awesome

Build Status PyPI version Build Status

Release Bot

Automate releases on Github and PyPi.

This repository is no longer maintained, for replacement see PyPI publish GitHub Action and Packit

Description

This is a bot that helps maintainers deliver their software to users. It is meant to watch github repositories for release pull requests. The PR must be named in one of the following formats:

Release-bot now works with SemVer only. Once the PR is merged, bot will create a new Github release and a PyPi release respectively. Changelog will be pulled from root of the repository and must be named CHANGELOG.md. Changelog for the new version must begin with version heading, i.e # 0.1.0. Everything between this heading and the heading for previous version will be pulled into the changelog.

Alternatively, you can let the bot do the boring work, update __version__ variable and fill changelog with commit messages from git log. You can trigger this action by creating an issue and name it the same as you would do for a release PR, e.g. 0.1.0 release, new major release, new minor release, new patch release. All you have to do after that is merge the PR that the bot will make.

The bot works with pypa/setuptools_scm plugin. If you're using it, you don't need to care about __version__ at all. You can be also sure that the bot will make the PyPI release correctly — before it releases the software, it checks out the tag in the git repo.

A release-conf.yaml file is required. See Configuration section for details.

Once a Github release is complete, bot will upload this release to PyPI. Note that you have to setup your login details (see Requirements).

Try it locally

Install

$ pip install release-bot

Other possible installations are through Arch User Repository or install on repo as Github Application.

First interaction with release bot may be automated releases on Github. Let's do it.

Configure the release bot

Release bot can be configured in two ways, using release-bot init or manually

Configuration using release-bot init

Clone the upstream repository where new releases will be published and from the root dir of the repository run the following command:

release-bot init

Enter the required details when asked by the bot. All of the default choices provided by the init should be enough for the current trial. You will also need to generate a Github personal access token. Recommended permissions for access token are: repo, delete_repo, user.

You can later on modify all the config files. For possible advanced setup check the documentation for an upstream repository and gitchangelog.

After the init is completed commit all of the changes and push it to the upstream repo.

Manual Configuration

1. Create upstream repository or use existing one

This is meant to be upstream repository where new releases will be published.

Within upstream repository create release-conf.yaml file which contains info on how to release the specific project. Copy and edit release-conf.yaml.

At the end of release-conf.yaml add this line of code:

# whether to allow bot to make PRs based on issues
trigger_on_issue: true

Then copy .gitchangelog.rc and markdown.tpl (which are the config files for the gitchangelog) to the root dir of the upstream repository. For possible advanced setup check the documentation for an upstream repository and gitchangelog.

2. Create conf.yaml

Create configuration file conf.yaml. You can use one from this repository. You will need to generate a Github personal access token. Recommended permissions for access token are: repo, delete_repo, user.

At the end of conf.yaml add this line of code:

# Name of the account that the github_token belongs to
# Only needed for triggering the bot on an issue.
github_username: <your_github_username>
gitchangelog: true

Note: This file should not be stored in upstream repository as it contains sensitive data.

For possible advanced setup check the documentation for a private repository. Also, see requirements in case you want include PyPi releases.

Run the release-bot

At this point, release-bot is installed. At least four configuration files are set release-conf.yaml, conf.yaml, .gitchangelog.rc, markdown.tpl (optionally .pypirc).

Launch bot by a command: $ release-bot -c <path_to_conf.yaml> --debug You can scroll down and see debug information of running bot.

Make a new release

Since now, feel free to create releases automatically just by creating issues.

Documentation

Configuration

There are two yaml configuration files:

  1. conf.yaml -- a config for the bot itself with some sensitive data (recommended to store in private repo)
  2. release-conf.yaml -- stored in upstream repository and contains info on how to release the specific project.

There are two more files required if you use gitchangelog to genereate change logs:

  1. .gitchangelog.rc -- a config file used by the gitchangelog to specify the regex for converting commits and the output engine
  2. markdown.tpl -- a template file used by pystache to genereate markdown

Private repository

You need to setup a git repository, where you'll store the conf.yaml and .pypirc files. If this is not a local repository, make sure it's private so you prevent any private info leaking out. If the path to conf.yaml is not passed to bot with -c/--configuration, bot will try to find it in current working directory.

Here are the conf.yaml configuration options:

OptionDescriptionRequired
repository_nameName of your Github repositoryYes
repository_ownerOwner of the repositoryYes
github_tokenGithub personal access tokenYes
github_usernameName of the account that the github_token belongs to. Only needed for triggering the bot on an issue.No
github_app_installation_idInstallation ID (a number) of the Github app.No
github_app_idID (a number) of the Github app.No
github_app_cert_pathPath to a certificate which Github provides as an auth mechanism for Github apps.No
refresh_intervalTime in seconds between checks on repository. If not provided, run only once and exit.No
clone_urlURL used to clone your Github repository. By default, https variant is used.No
gitchangelogWhether to use gitchangelog to generate change logs. False by default.No

Sample config named conf.yaml can be found in this repository.

Regarding github_token, it's usually a good idea to create a Github account for the bot (and use its Github API token) so you can keep track of what changes were made by bot and what are your own.

You can also create a Github app and use it as an authentication mechanism for the bot. For that you need to specify the three config values prefixed with github_app.

Note: If the Upstream repository is a Private Github repository, it is required to specify the SSH URL of the repository as the clone_url option in conf.yaml. This will allow the bot to authenticate using SSH, when fetching from the Upstream repository.

Upstream repository

You also have to have a release-conf.yaml file in the root of your upstream project repository. Here are possible options:

OptionMeaningRequired
changelogList of changelog entries. If empty, changelog defaults to $version releaseNo
author_nameAuthor name for changelog. If not set, author of the merge commit is usedNo
author_emailAuthor email for changelog. If not set, author of the merge commit is usedNo
pypiWhether to release on pypi. True by defaultNo
pypi_projectName of your PyPI repositoryNo
trigger_on_issueWhether to allow bot to make PRs based on issues. True by default.No
labelsList of labels that bot will put on issues and PRsNo

Sample config named release-conf-example.yaml can be found in this repository.

GitChangeLog

For using the gitchangelog you must add the line gitchanelog: true to the conf.yaml, and add the files .gitchangelog.rc and markdown.tpl in the root of your upstream project repository. Sample config files: .gitchangelog.rc and template.tpl.

.gitchangelog.rc sample is heavily commented and should be enough to make modification but for specific details you can refer to the original repository. The default template markdown.tpl is configured to create Markdown divided into sections (New, Changes, Fix, Others) based on the commits. The data sent to the output engine pystache by the gitchangelog is in the following format. You can use it to create a custom template, please refer mustache.

Requirements

Are specified in setup.cfg. You have to setup your PyPI login details in $HOME/.pypirc as described in PyPI documentation.

Github Application

Release-bot as Github Application is currently in testing and will be available soon in Github market. Github application will speed-up configuration process.

Arch User Repository

For Arch or Arch based Linux distributions, you can install the bot from the AUR Package. You can use your favourite AUR Helper to install the package. For instance:

$ aurman -S release-bot

You can also install it by using the PKGBUILD from the AUR repository. To build the package, download the PKGBUILD and exectute:

$ makepkg -cs #c flag cleans the extra remaining source and compiled files. s flag installs the dependencies if you don't have it.

To install the package execute,

$ sudo pacman -U release-bot-...tar.xz

Contributing

If you are interested in making contribution to release-bot project, please read Contribution guide for more information.

Logo design

Created by Marián Mrva - @surfer19