From 1704d76eb89a887724b9f6315d03bcddc7a538f4 Mon Sep 17 00:00:00 2001 From: Pablo Rodriguez Mira <36644554+PabloRMira@users.noreply.github.com> Date: Mon, 25 Jan 2021 00:31:41 +0100 Subject: [PATCH] [MNT] Simplify package by removing release module (#142) * [simplify] add gh release config and update gitignore * [simplify] remove release module as this is now handled by easyrelease --- .gh-release-config.yaml | 11 + .gitignore | 4 + docs/_data/sidebars/home_sidebar.yml | 3 - docs/release.html | 360 --------------------------- docs/sidebar.json | 3 +- nbs/04_release.ipynb | 262 ------------------- sql_formatter/_nbdev.py | 15 +- sql_formatter/release.py | 112 --------- 8 files changed, 18 insertions(+), 752 deletions(-) create mode 100644 .gh-release-config.yaml delete mode 100644 docs/release.html delete mode 100644 nbs/04_release.ipynb delete mode 100644 sql_formatter/release.py diff --git a/.gh-release-config.yaml b/.gh-release-config.yaml new file mode 100644 index 0000000..0b64d39 --- /dev/null +++ b/.gh-release-config.yaml @@ -0,0 +1,11 @@ +gh_categories: + - title: "### :tada: Bugfixes:" + keyword: "[FIX]" + - title: "### :rocket: New features:" + keyword: "[FEA]" + - title: "### :bulb: Documentation:" + keyword: "[DOC]" + - title: "### :hammer_and_wrench: Refactoring / Maintenance:" + keyword: "[MNT]" + - title: "### :bomb: Breaking changes:" + keyword: "[BRK]" diff --git a/.gitignore b/.gitignore index 5b06dd1..1a8e977 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,7 @@ checklink/cookies.txt # GitHub token token + +.gh-credentials +conda-recipe/* +conda-bld/* \ No newline at end of file diff --git a/docs/_data/sidebars/home_sidebar.yml b/docs/_data/sidebars/home_sidebar.yml index 83c35d8..1e9a634 100644 --- a/docs/_data/sidebars/home_sidebar.yml +++ b/docs/_data/sidebars/home_sidebar.yml @@ -21,9 +21,6 @@ entries: - output: web,pdf title: validation url: validation.html - - output: web,pdf - title: release - url: release.html output: web title: sql_formatter output: web diff --git a/docs/release.html b/docs/release.html deleted file mode 100644 index a529ab7..0000000 --- a/docs/release.html +++ /dev/null @@ -1,360 +0,0 @@ ---- - -title: release - - -keywords: fastai -sidebar: home_sidebar - -summary: "Functions to manage releases and changelog programmatically" -description: "Functions to manage releases and changelog programmatically" -nb_path: "nbs/04_release.ipynb" ---- - - -
- - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

get_last_tag[source]

get_last_tag()

-
-

Get latest git tag

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

get_commits[source]

get_commits(from_tag=None, to='HEAD')

-
-

Get commits from_tag to to

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

get_release_version[source]

get_release_version()

-
-

Get release version from settings.ini

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

add_pull_request_link(msg)

-
-

Add pull request link to commit message s if reference is found, e.g. #100

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

changelog_report[source]

changelog_report(report_title, from_tag=None, to='HEAD')

-
-

Changelog report from_tag to commit to using report_title

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

release_report[source]

release_report()

-
-

Create release report out of commit messages

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

get_token[source]

get_token()

-
- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

make_git_release[source]

make_git_release()

-
-

Make a release as a git tag and publish to GitHub

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

get_tags[source]

get_tags()

-
-

Get git tags as a list

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - - {% raw %} - -
- -
-
- -
- - -
-

make_changelog[source]

make_changelog()

-
-

Make changelog out of releases / git tags

- -
- -
- -
-
- -
- {% endraw %} - - {% raw %} - -
- -
- {% endraw %} - -
- - diff --git a/docs/sidebar.json b/docs/sidebar.json index 6754cb4..c0b4234 100644 --- a/docs/sidebar.json +++ b/docs/sidebar.json @@ -4,7 +4,6 @@ "core": "core.html", "format_file": "format_file.html", "utils": "utils.html", - "validation": "validation.html", - "release": "release.html" + "validation": "validation.html" } } \ No newline at end of file diff --git a/nbs/04_release.ipynb b/nbs/04_release.ipynb deleted file mode 100644 index c6df5f3..0000000 --- a/nbs/04_release.ipynb +++ /dev/null @@ -1,262 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#hide\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "%config Completer.use_jedi = False # workaround for buggy jedi" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# default_exp release" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# release\n", - "\n", - "> Functions to manage releases and changelog programmatically" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#hide\n", - "from nbdev.showdoc import *" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "import os\n", - "import re\n", - "import subprocess\n", - "from fastcore.script import call_parse\n", - "from configparser import ConfigParser\n", - "from pathlib import Path" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def get_last_tag():\n", - " \"Get latest git tag\"\n", - " return subprocess.run([\"git\", \"describe\", \"--tags\", \"--abbrev=0\"], \n", - " capture_output=True).stdout.decode(\"utf\").strip()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def get_commits(from_tag=None, to=\"HEAD\"):\n", - " \"Get commits `from_tag` to `to`\"\n", - " last_tag = from_tag if from_tag is not None else get_last_tag()\n", - " commit_msgs = subprocess.run([\"git\", \"log\", f\"{last_tag}..{to}\", \"--pretty=%s\"],\n", - " capture_output=True).stdout.decode(\"utf\").strip()\n", - " return commit_msgs.split(\"\\n\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def get_release_version():\n", - " \"Get release version from settings.ini\"\n", - " project_path = str(Path(__file__).parent.parent)\n", - " config = ConfigParser(delimiters=['='])\n", - " config.read(os.path.join(project_path, 'settings.ini'))\n", - " cfg = config['DEFAULT']\n", - " return cfg[\"version\"]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def add_pull_request_link(msg):\n", - " \"Add pull request link to commit message `s` if reference is found, e.g. #100\"\n", - " msg_with_link = re.sub(\"(#)(\\d+)\", r\"[\\1\\2](https://github.com/PabloRMira/sql_formatter/pull/\\2)\", msg)\n", - " return msg_with_link" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def changelog_report(report_title, from_tag=None, to=\"HEAD\"):\n", - " \"Changelog report `from_tag` to commit `to` using `report_title`\"\n", - " commit_msgs = get_commits(from_tag, to)\n", - " bugfixes = [f\"* {msg}\" for msg in commit_msgs if re.search(\"\\[FIX\\]\", msg)]\n", - " bugfixes = [add_pull_request_link(msg) for msg in bugfixes]\n", - " docs = [f\"* {msg}\" for msg in commit_msgs if re.search(\"\\[DOC\\]\", msg)]\n", - " docs = [add_pull_request_link(msg) for msg in docs]\n", - " new_features = [f\"* {msg}\" for msg in commit_msgs if re.search(\"\\[FEA\\]\", msg)]\n", - " new_features = [add_pull_request_link(msg) for msg in new_features]\n", - " maintenance = [f\"* {msg}\" for msg in commit_msgs if re.search(\"\\[MNT\\]\", msg)]\n", - " maintenance = [add_pull_request_link(msg) for msg in maintenance]\n", - " report_bugfixes = \"### Bugfixes:\\n{}\".format(\"\\n\".join(bugfixes)) if len(bugfixes) > 0 else \"\"\n", - " report_docs = \"### Documentation:\\n{}\".format(\"\\n\".join(docs)) if len(docs) > 0 else \"\"\n", - " report_features = \"### New features:\\n{}\".format(\"\\n\".join(new_features)) if len(new_features) > 0 else \"\"\n", - " report_maintenance = \"### Refactoring / Maintenance:\\n{}\".format(\"\\n\".join(maintenance)) if len(maintenance) > 0 else \"\"\n", - " report_list = [report_title, report_features, report_bugfixes, report_docs, report_maintenance]\n", - " report_list = [rep for rep in report_list if rep != \"\"]\n", - " report = \"\\n\\n\".join(report_list)\n", - " return report" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def release_report():\n", - " \"Create release report out of commit messages\"\n", - " release_version = get_release_version()\n", - " return changelog_report(report_title=\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def get_token():\n", - " project_path = str(Path(__file__).parent.parent)\n", - " with open(os.path.join(project_path, \"token\"), \"r\") as f:\n", - " token = f.read().strip()\n", - " return token" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "@call_parse\n", - "def make_git_release():\n", - " \"Make a release as a git tag and publish to GitHub\"\n", - " # get token\n", - " token = get_token()\n", - " # get release version\n", - " release_version = get_release_version()\n", - " # get release report\n", - " report = release_report()\n", - " # authentificate with GitHub\n", - " subprocess.run([\"gh\", \"auth\", \"login\", \"--with-token\", token])\n", - " # create release on GitHub\n", - " subprocess.run([\"gh\", \"release\", \"create\", release_version, \n", - " \"-n\", report, \"-t\", f\"Release version {release_version}\"])\n", - " # download new tag from GitHub\n", - " subprocess.run([\"git\", \"fetch\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "def get_tags():\n", - " \"Get git tags as a list\"\n", - " return subprocess.run([\"git\", \"tag\", \"-l\"], capture_output=True).stdout.decode(\"utf\").strip().split(\"\\n\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#export\n", - "@call_parse\n", - "def make_changelog():\n", - " \"Make changelog out of releases / git tags\"\n", - " project_path = str(Path(__file__).parent.parent) \n", - " tags = get_tags()\n", - " changelog_title = \"# Release notes\"\n", - " reports = []\n", - " for from_tag, to in zip(tags[:-1], tags[1:]):\n", - " reports.append(changelog_report(report_title=f\"## {to}\", from_tag=from_tag, to=to))\n", - " changelog = changelog_title + \"\\n\\n\" + \"\\n\\n\".join(reports[::-1])\n", - " with open(os.path.join(project_path, \"CHANGELOG.md\"), \"w\") as f:\n", - " f.write(changelog)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Converted 00_core.ipynb.\n", - "Converted 01_format_file.ipynb.\n", - "Converted 02_utils.ipynb.\n", - "Converted 03_validation.ipynb.\n", - "Converted 04_release.ipynb.\n", - "Converted index.ipynb.\n" - ] - } - ], - "source": [ - "#hide\n", - "from nbdev.export import notebook2script\n", - "notebook2script()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [conda env:sql-formatter-dev] *", - "language": "python", - "name": "conda-env-sql-formatter-dev-py" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/sql_formatter/_nbdev.py b/sql_formatter/_nbdev.py index d55a5b2..e23028f 100644 --- a/sql_formatter/_nbdev.py +++ b/sql_formatter/_nbdev.py @@ -53,23 +53,12 @@ "assign_comment": "02_utils.ipynb", "validate_semicolon": "03_validation.ipynb", "validate_balanced_parenthesis": "03_validation.ipynb", - "validate_case_when": "03_validation.ipynb", - "get_last_tag": "04_release.ipynb", - "get_commits": "04_release.ipynb", - "get_release_version": "04_release.ipynb", - "add_pull_request_link": "04_release.ipynb", - "changelog_report": "04_release.ipynb", - "release_report": "04_release.ipynb", - "get_token": "04_release.ipynb", - "make_git_release": "04_release.ipynb", - "get_tags": "04_release.ipynb", - "make_changelog": "04_release.ipynb"} + "validate_case_when": "03_validation.ipynb"} modules = ["core.py", "format_file.py", "utils.py", - "validation.py", - "release.py"] + "validation.py"] doc_url = "https://PabloRMira.github.io/sql_formatter/" diff --git a/sql_formatter/release.py b/sql_formatter/release.py deleted file mode 100644 index 7697e9b..0000000 --- a/sql_formatter/release.py +++ /dev/null @@ -1,112 +0,0 @@ -# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/04_release.ipynb (unless otherwise specified). - -__all__ = ['get_last_tag', 'get_commits', 'get_release_version', 'add_pull_request_link', 'changelog_report', - 'release_report', 'get_token', 'make_git_release', 'get_tags', 'make_changelog'] - -# Cell -import os -import re -import subprocess -from fastcore.script import call_parse -from configparser import ConfigParser -from pathlib import Path - -# Cell -def get_last_tag(): - "Get latest git tag" - return subprocess.run(["git", "describe", "--tags", "--abbrev=0"], - capture_output=True).stdout.decode("utf").strip() - -# Cell -def get_commits(from_tag=None, to="HEAD"): - "Get commits `from_tag` to `to`" - last_tag = from_tag if from_tag is not None else get_last_tag() - commit_msgs = subprocess.run(["git", "log", f"{last_tag}..{to}", "--pretty=%s"], - capture_output=True).stdout.decode("utf").strip() - return commit_msgs.split("\n") - -# Cell -def get_release_version(): - "Get release version from settings.ini" - project_path = str(Path(__file__).parent.parent) - config = ConfigParser(delimiters=['=']) - config.read(os.path.join(project_path, 'settings.ini')) - cfg = config['DEFAULT'] - return cfg["version"] - -# Cell -def add_pull_request_link(msg): - "Add pull request link to commit message `s` if reference is found, e.g. #100" - msg_with_link = re.sub("(#)(\d+)", r"[\1\2](https://github.com/PabloRMira/sql_formatter/pull/\2)", msg) - return msg_with_link - -# Cell -def changelog_report(report_title, from_tag=None, to="HEAD"): - "Changelog report `from_tag` to commit `to` using `report_title`" - commit_msgs = get_commits(from_tag, to) - bugfixes = [f"* {msg}" for msg in commit_msgs if re.search("\[FIX\]", msg)] - bugfixes = [add_pull_request_link(msg) for msg in bugfixes] - docs = [f"* {msg}" for msg in commit_msgs if re.search("\[DOC\]", msg)] - docs = [add_pull_request_link(msg) for msg in docs] - new_features = [f"* {msg}" for msg in commit_msgs if re.search("\[FEA\]", msg)] - new_features = [add_pull_request_link(msg) for msg in new_features] - maintenance = [f"* {msg}" for msg in commit_msgs if re.search("\[MNT\]", msg)] - maintenance = [add_pull_request_link(msg) for msg in maintenance] - report_bugfixes = "### Bugfixes:\n{}".format("\n".join(bugfixes)) if len(bugfixes) > 0 else "" - report_docs = "### Documentation:\n{}".format("\n".join(docs)) if len(docs) > 0 else "" - report_features = "### New features:\n{}".format("\n".join(new_features)) if len(new_features) > 0 else "" - report_maintenance = "### Refactoring / Maintenance:\n{}".format("\n".join(maintenance)) if len(maintenance) > 0 else "" - report_list = [report_title, report_features, report_bugfixes, report_docs, report_maintenance] - report_list = [rep for rep in report_list if rep != ""] - report = "\n\n".join(report_list) - return report - -# Cell -def release_report(): - "Create release report out of commit messages" - release_version = get_release_version() - return changelog_report(report_title="") - -# Cell -def get_token(): - project_path = str(Path(__file__).parent.parent) - with open(os.path.join(project_path, "token"), "r") as f: - token = f.read().strip() - return token - -# Cell -@call_parse -def make_git_release(): - "Make a release as a git tag and publish to GitHub" - # get token - token = get_token() - # get release version - release_version = get_release_version() - # get release report - report = release_report() - # authentificate with GitHub - subprocess.run(["gh", "auth", "login", "--with-token", token]) - # create release on GitHub - subprocess.run(["gh", "release", "create", release_version, - "-n", report, "-t", f"Release version {release_version}"]) - # download new tag from GitHub - subprocess.run(["git", "fetch"]) - -# Cell -def get_tags(): - "Get git tags as a list" - return subprocess.run(["git", "tag", "-l"], capture_output=True).stdout.decode("utf").strip().split("\n") - -# Cell -@call_parse -def make_changelog(): - "Make changelog out of releases / git tags" - project_path = str(Path(__file__).parent.parent) - tags = get_tags() - changelog_title = "# Release notes" - reports = [] - for from_tag, to in zip(tags[:-1], tags[1:]): - reports.append(changelog_report(report_title=f"## {to}", from_tag=from_tag, to=to)) - changelog = changelog_title + "\n\n" + "\n\n".join(reports[::-1]) - with open(os.path.join(project_path, "CHANGELOG.md"), "w") as f: - f.write(changelog) \ No newline at end of file