Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jsnjack/hugo-changelog-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYauhen Shulitski <jsnjack@gmail.com>2018-10-17 00:43:03 +0300
committerYauhen Shulitski <jsnjack@gmail.com>2018-10-17 00:43:03 +0300
commit4c9e7b40126f7dc5c1a37ad00179562d5dba030b (patch)
treed369204a227922cc8a026c1243974e739486a96b
parentcd60e217045b06b044124a5544e7cfd0a53b145e (diff)
Add flow to readme
-rwxr-xr-x.githooks/post-merge11
-rw-r--r--Makefile18
-rw-r--r--README.md40
-rw-r--r--release.py121
4 files changed, 186 insertions, 4 deletions
diff --git a/.githooks/post-merge b/.githooks/post-merge
new file mode 100755
index 0000000..9f6041e
--- /dev/null
+++ b/.githooks/post-merge
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+STABLE_BRANCH=master
+CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
+if [ "$CURRENT_BRANCH" = "$STABLE_BRANCH" ]
+then
+ if [ `ls -l site/changelog/content/experimental | wc -l` -gt 1 ]
+ then
+ echo -e "\033[0;31mThere are experimental changes. Consider creating a release in develop branch\033[0m"
+ fi
+fi
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4fecf2a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+change: init_githooks
+ cd site/changelog && hugo new experimental/`shuf -i 10000-60000 -n 1`.md
+
+release_create:
+ python release.py
+
+release: release_create
+ git push
+ git push --tags
+
+generate_changelog:
+ cd site/changelog && hugo
+
+serve_changelog:
+ cd site/changelog && hugo server --bind 0.0.0.0 --baseURL=http://localhost/changelog/
+
+init_githooks:
+ @git config core.hooksPath .githooks
diff --git a/README.md b/README.md
index 5ea097a..765153e 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,48 @@
Hugo Changelog Theme
=====
-A [Hugo](https://gohugo.io/) theme to display changelog
+A [Hugo](https://gohugo.io/) theme to display a changelog
# Features
- Build with [Spectre.css](https://picturepan2.github.io/spectre/) (All unused components are disabled)
- Pagination
- Mobile friendly
-# Conventions
- - Create non-released entries in `experimental` folder. All of them are displayed in the top of the first page
- - Create released entries in `released` folders. Entries are sorted by Weight. Weight is displayed as version
+# Workflow
+
+## Conventions
+ - Create non-released entries in `experimental/` folder. All of them are displayed in the top of the first page
+ - Create released entries in `released/` folders. Entries are sorted by Weight. Weight is displayed as version
+ - Your hugo changelog website is located in `site/changelog/` folder
+ - You are using `master` branch as the stable branch and `develop` branch as a working branch (needed for the post-merge webhook only)
+
+## Scripts
+ - `Makefile` - list of useful commands
+ - `release.py` - moves changes from the `experimental/` folder to the `released/` folder, assigns version number and generates release-commit
+ - `.githooks/post-merge` - verifies that `experimental/` folder is empty during the merge from the working branch to the stable branch
+
+## Description
+ 1. When a pull request is ready, a developer creates a changelog entry:
+ ```bash
+ make change
+ ```
+ The command creates a *.md file with random name (ensures that there will be no merge conflicts) in `site/changelog/content/experimental/` folder
+
+ 2. The developer updates created file with changes. Changes are going to be rendered in the `experimental` section of the template
+
+ 3. Preview the site with the command:
+ ```bash
+ make serve_changelog
+ ```
+
+ 4. When the working branch is ready to be merged in the stable branch, the developer runs:
+ ```bash
+ make release
+ ```
+ The command will move all *.md files from the `experimental/` folder to the `released/` folder, assign the release version and generate the commit with related changes
+
+ 5. The developer merges working branch in to the stable branch
+
# Shortcodes
- `{{% tag fixed %}}` - create a specific tag before entry text. Available tag types are: added, changed, fixed, deprecated, removed, security
diff --git a/release.py b/release.py
new file mode 100644
index 0000000..edd7090
--- /dev/null
+++ b/release.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python2
+from __future__ import unicode_literals
+
+import datetime
+import os
+import subprocess
+from contextlib import contextmanager
+
+import frontmatter
+
+PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
+CHANGELOG_SITE_DIR = os.path.join(PROJECT_DIR, "site/changelog/")
+CONTENT_DIR = os.path.join(CHANGELOG_SITE_DIR, "content/")
+RELEASED_DIR = os.path.join(CONTENT_DIR, "released/")
+EXPERIMENTAL_DIR = os.path.join(CONTENT_DIR, "experimental/")
+
+INTRO_SAMPLE = "<!-- Available tags are: added, changed, deprecated, removed, fixed, security -->"
+
+
+@contextmanager
+def project_dir():
+ owd = os.getcwd()
+ try:
+ os.chdir(PROJECT_DIR)
+ yield PROJECT_DIR
+ finally:
+ os.chdir(owd)
+
+
+def main():
+ changes = ""
+ for item in os.listdir(EXPERIMENTAL_DIR):
+ if item.endswith(".md"):
+ changes = changes + process_change(os.path.join(EXPERIMENTAL_DIR, item))
+ elif item == ".gitignore":
+ pass
+ else:
+ print("Unexpected file: %s" % item)
+ if changes:
+ version = release(changes)
+ commit_release(version)
+ else:
+ print("No changes")
+
+
+def process_change(path):
+ """
+ Returns all changes from the file
+ """
+ print("Processing %s..." % path)
+ with open(path, "rb") as md_file:
+ data = frontmatter.load(md_file)
+ os.remove(path)
+ print("Removed: %s" % path)
+ return data.content.replace(INTRO_SAMPLE, "")
+
+
+def release(changes):
+ """
+ Release version - move from experimental/ to released/
+ """
+ print("Releasing changes...")
+ version = get_current_version() + 1
+ print("Assigning version %s" % version)
+ data = frontmatter.loads(changes)
+ data["weight"] = version
+ data["title"] = datetime.datetime.now().strftime("%Y-%m-%d")
+ data["draft"] = False
+ data["date"] = datetime.datetime.now() # 2018-10-02T09:29:50Z
+ released_file_path = os.path.join(RELEASED_DIR, "%s.md" % data["weight"])
+ with open(released_file_path, "wb") as released_file:
+ frontmatter.dump(data, released_file)
+ print("Created: %s" % released_file_path)
+ return version
+
+
+def commit_release(version):
+ """
+ Autogenerates commit and tag
+ """
+ with project_dir():
+ subprocess.call(["git", "add", CONTENT_DIR])
+ subprocess.call(["git", "commit", "-m", "Generated by release script"])
+ subprocess.call(["git", "fetch", "--tags"])
+ subprocess.call(["git", "tag", "-d", "v%s" % version])
+ subprocess.call(["git", "tag", "v%s" % version])
+
+
+def get_current_version():
+ """
+ Get current version from files in released/ folder
+ """
+ version = 0
+ files = os.listdir(RELEASED_DIR)
+ files.sort(reverse=True, key=natural_sort)
+ for item in files:
+ if item.endswith(".md"):
+ version = int(item[:-3])
+ break
+ return version
+
+
+def print_release_version():
+ """
+ Returns release version
+ """
+ version = get_current_version()
+ is_experimental = len([x for x in os.listdir(EXPERIMENTAL_DIR) if x.endswith(".md")]) > 0
+ print("v%s%s" % (version, "+" if is_experimental else ""))
+
+
+def natural_sort(el):
+ try:
+ v = int(el[:-3])
+ except ValueError:
+ v = 0
+ return v
+
+
+if __name__ == "__main__":
+ main()