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 task to generate release body #233

Merged
merged 8 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ conan-cache/
.clangd
compile_commands.json

# Faabric config file
faabric.ini

# Ansible
*.retry

Expand Down
1 change: 0 additions & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[changelog]
# changelog header
header = """
# Faabric's Changelog\n
Here is what has changed since last release:

"""
Expand Down
45 changes: 35 additions & 10 deletions docs/source/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ docker-compose stop
./dist-test/run.sh
```

## Releasing
## Creating a new tag

Create a new branch, then find and replace the current version with the relevant
bumped version. It should appear in:
Expand Down Expand Up @@ -161,17 +161,10 @@ history, you may re-tag the code again:
inv git.tag --force
```

Lastly, to publish a release, you can generate the change log for the release
body by running:

```bash
inv git.release_body
```

### Building images manually

Containers are built with Github Actions, so you should only need to build them
yourself when diagnosing issues.
Containers are built with Github Actions, when a new tag is pushed, so you
should only need to build them yourself when diagnosing issues.

To build the main container, run:

Expand All @@ -188,3 +181,35 @@ inv container.push
inv container.build --push
```

## Publishing a release

To publish a release in Github, make sure you are in the main branch, and have
just tagged the code (see previous section).

Then, you can create a release on [Github](https://github.com/faasm/faabric/releases)
and publish it from the command line. If it is the first time you are creating
a release you will have to configure a Github access token (see below).

First, generate a draft release:

```bash
inv git.release_create
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work, I have a feeling Invoke will replace all underscores with hyphens.

Copy link
Collaborator Author

@csegarragonz csegarragonz Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me locally (source ./bin/workon.sh && inv -l I see underscores). The same does not happen in faasm.

We use different invoke versions (1.6.0 and 1.5.0 respectively) but I can't see anything about such changes in their changelog.

```

Then, after verifying that the release looks fine, you may publish it:

```bash
inv git.release_publish
```

### Configuring a Github access token

Follow the instructions on [how to create a personal access token](
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
Then, create a config file for faabric in the main directory named
`faabric.ini` with the following contents:

```toml
[Github]
access_token = <paste your personal access token>
```
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ flake8==4.0.1
invoke==1.6.0
myst-parser==0.16.1
numpy==1.21.5
PyGithub==1.55
redis==4.1.0
sphinx-rtd-theme==1.0.0
80 changes: 62 additions & 18 deletions tasks/git.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from github import Github
from invoke import task
from tasks.util.env import get_version, PROJ_ROOT
from tasks.util.env import get_faabric_config, get_version, PROJ_ROOT
from subprocess import run, PIPE, STDOUT
import json


def get_tag_name(version):
return "v{}".format(version)


@task
def tag(ctx, force=False):
"""
Creates git tag from the current tree
"""
git_tag = "v{}".format(get_version())
git_tag = get_tag_name(get_version())
run(
"git tag {} {}".format("--force" if force else "", git_tag),
shell=True,
Expand All @@ -31,20 +35,32 @@ def is_git_submodule():
return result.stdout.decode("utf-8") != ""


def get_latest_release_tag():
gh_url = "https://api.github.com/repos/faasm/faabric/releases/latest"
def get_github_instance():
conf = get_faabric_config()

curl_cmd = "curl --silent {}".format(gh_url)
print(curl_cmd)
result = run(curl_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
if not conf.has_section("Github") or not conf.has_option(
"Github", "access_token"
):
print("Must set up Github config with access token")

tag = json.loads(result.stdout.decode("utf-8"))["tag_name"]
token = conf["Github"]["access_token"]
g = Github(token)
return g

return tag

def get_repo():
g = get_github_instance()
return g.get_repo("faasm/faabric")

@task
def release_body(ctx, file_path="/tmp/release_body.md"):

def get_release():
r = get_repo()
rels = r.get_releases()

return rels[0]


def get_release_body():
"""
Generate body for release with detailed changelog
"""
Expand All @@ -55,7 +71,7 @@ def release_body(ctx, file_path="/tmp/release_body.md"):
"orhunp/git-cliff:latest",
"--config ./faabric/cliff.toml",
"--repository ./faabric",
"{}..v{}".format(get_latest_release_tag(), get_version()),
"{}..v{}".format(get_release().tag_name, get_version()),
]
else:
docker_cmd = [
Expand All @@ -64,15 +80,43 @@ def release_body(ctx, file_path="/tmp/release_body.md"):
"orhunp/git-cliff:latest",
"--config cliff.toml",
"--repository .",
"{}..v{}".format(get_latest_release_tag(), get_version()),
"{}..v{}".format(get_release().tag_name, get_version()),
]

cmd = " ".join(docker_cmd)
print("Generating release body...")
print(cmd)
result = run(cmd, shell=True, stdout=PIPE, stderr=PIPE)

with open(file_path, "w") as f:
f.write(result.stdout.decode("utf-8"))
return result.stdout.decode("utf-8")


print("Stored release body in temporary file:")
print("vim {}".format(file_path))
@task
def release_create(ctx):
"""
Create a draft release on Github
"""
# Work out the tag
faabric_ver = get_version()
tag_name = get_tag_name(faabric_ver)

# Create a release in github from this tag
r = get_repo()
r.create_git_release(
tag_name,
"Faabric {}".format(faabric_ver),
get_release_body(),
draft=True,
)

print("You may now review the draft release in:")
print("https://github.com/faasm/faabric/releases")


@task
def release_publish(ctx):
"""
Publish the draft release
"""
rel = get_release()
rel.update_release(rel.title, rel.raw_data["body"], draft=False)
18 changes: 17 additions & 1 deletion tasks/util/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from os import environ
from os.path import dirname, realpath, join, expanduser
from os.path import dirname, exists, realpath, join, expanduser
import configparser

HOME_DIR = expanduser("~")
PROJ_ROOT = dirname(dirname(dirname(realpath(__file__))))
Expand All @@ -11,6 +12,8 @@

FAABRIC_INSTALL_PREFIX = join(_FAABRIC_BUILD_DIR, "install")

FAABRIC_CONFIG_FILE = join(PROJ_ROOT, "faabric.ini")


def get_version():
ver_file = join(PROJ_ROOT, "VERSION")
Expand All @@ -20,3 +23,16 @@ def get_version():

version = version.strip()
return version


def get_faabric_config():
config = configparser.ConfigParser()
if not exists(FAABRIC_CONFIG_FILE):
print("Creating config file at {}".format(FAABRIC_CONFIG_FILE))

with open(FAABRIC_CONFIG_FILE, "w") as fh:
config.write(fh)
else:
config.read(FAABRIC_CONFIG_FILE)

return config