Skip to content

Commit

Permalink
Update release generation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Mar 1, 2021
1 parent 0233671 commit 4fbe499
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,23 @@ jobs:
run: |
echo "release_version=$(git describe --abbrev=0 | sed s/v//)" >> $GITHUB_ENV
- name: "Set up Python 3.9"
- name: "Set up Python"
if: env.release_version != '' && success()
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: "Cache pip"
uses: actions/cache@v2.1.4
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: "Install requirements"
if: env.release_version != '' && success()
run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Use [black](https://github.com/ambv/black) to make sure the code follows the sty

## Test your code modification

This custom component is based on [blueprint template](https://github.com/Limych/ha-blueprint).
This custom component is based on [integration blueprint template](https://github.com/Limych/ha-blueprint).

It comes with development environment in a container, easy to launch
if you use Visual Studio Code. With this container you will have a stand alone
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Platform | Description

![example][exampleimg]

## Known Limitations and Issues

- Some example limitation.

## Installation

Expand Down
31 changes: 20 additions & 11 deletions bin/gen_releasenotes
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
"""Helper script to generate release notes."""
import argparse
from datetime import datetime
import logging
import os
import re
import subprocess
from datetime import datetime
from typing import List

from github import Github, GithubException, Repository, Tag
Expand All @@ -19,7 +19,7 @@ logging.basicConfig(level=logging.CRITICAL)

_LOGGER = logging.getLogger(__name__)

VERSION = "1.1.5"
VERSION = "1.1.7"

ROOT = os.path.dirname(os.path.abspath(f"{__file__}/.."))

Expand Down Expand Up @@ -56,6 +56,8 @@ def get_release_tags(repo: Repository) -> List[Tag.Tag]:
"""Get list of all release tags from repository."""
reg = re.compile(
r"^v?[0-9]+\.[0-9]+(?:\.[0-9]+)?"
r"(?:[._-]?[A-Za-z]*[._-]?[0-9]*)?"
r"(?:[._-]?dev[0-9]*)?"
r"(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+)?$"
)
tags = list(filter(lambda tag: re.match(reg, tag.name), list(repo.get_tags())))
Expand All @@ -69,15 +71,20 @@ def get_period(repo: Repository, release: str = None) -> List[datetime]:
data = [datetime.now()]
dateformat = "%a, %d %b %Y %H:%M:%S GMT"
found = release is None
last = False
is_prerelease = Version(release).is_prerelease
for tag in get_release_tags(repo):
last = False
commit = repo.get_commit(tag.commit.sha)
timestamp = datetime.strptime(commit.last_modified, dateformat)
_LOGGER.debug("Process tag %s => timestamp %s", tag.name, timestamp)
data.append(timestamp)
if found:
if found and is_prerelease == Version(tag.name).is_prerelease:
break
if release is not None and release == tag.name:
found = True
found = last = True
if found and last:
data.append(datetime.fromtimestamp(0))
return list(reversed(data[-2:]))


Expand Down Expand Up @@ -209,20 +216,22 @@ def main():
else:
print("Not enough changes for a release.")
else:
version = arguments.release.replace("refs/tags/", "")
_LOGGER.debug("Release tag: %s", version)
tag = arguments.release.replace("refs/tags/", "")
_LOGGER.debug("Release tag: %s", tag)
version = Version(tag)
msg = BODY.format(
repo=arguments.repo,
version=version,
changes=gen_changes(repo, version),
version=str(version),
changes=gen_changes(repo, tag),
)
if arguments.dry_run:
print("Is prerelease:", version.is_prerelease)
print("Generated release notes:\n" + msg)
else:
release = repo.get_release(version)
release = repo.get_release(tag)
release.update_release(
name=version,
prerelease=release.prerelease,
name=tag,
prerelease=version.is_prerelease,
draft=release.draft,
message=msg,
)
Expand Down
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% if prerelease %}
### NB!: This is a Beta version!
{% endif %}

[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
[![License][license-shield]][license]
Expand Down

0 comments on commit 4fbe499

Please sign in to comment.