From cdd8980adbbfc1f36e3921590097d94e45eefb69 Mon Sep 17 00:00:00 2001 From: Sean Dockray Date: Sun, 6 Sep 2020 23:58:59 +1000 Subject: [PATCH] Allow previewing git branches in post receive python script; also local vs prod config --- config/_default/config-local.toml | 27 ++++++++++++++++++++++++ config/_default/config.toml | 1 + custom_syadmin/git_hooks_post-receive.py | 20 ++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 config/_default/config-local.toml diff --git a/config/_default/config-local.toml b/config/_default/config-local.toml new file mode 100644 index 0000000..4caff5a --- /dev/null +++ b/config/_default/config-local.toml @@ -0,0 +1,27 @@ +baseURL = "http://localhost:8000" +languageCode = "en-us" +title = "Pirate Care" +theme = "sandpoints" +relativeurls = true +disableKinds = ["RSS", "sitemap"] + +[params] + description = "Network of activists, researchers and practitioners against the criminalisation of solidarity & for a common care infrastructure." + images = ["/images/piratecaqre.png"] + title = "Pirate Care Syllabus" + giturl = "http://localhost:3000/gitea/pirate-care-syllabus" + home = "syllabus" + +[outputFormats] + [outputFormats.js] + isPlainText = true + mediaType = "application/javascript" + +[outputs] + list = ["html", "js"] + +[markup] + [markup.tableOfContents] + endLevel=4 + ordered = true + startLevel = 1 diff --git a/config/_default/config.toml b/config/_default/config.toml index a0738b6..cd8b442 100644 --- a/config/_default/config.toml +++ b/config/_default/config.toml @@ -9,6 +9,7 @@ disableKinds = ["RSS", "sitemap"] description = "Network of activists, researchers and practitioners against the criminalisation of solidarity & for a common care infrastructure." images = ["/images/piratecaqre.png"] title = "Pirate Care Syllabus" + giturl = "https://git.memoryoftheworld.org/PirateCare/Syllabus" home = "syllabus" [outputFormats] diff --git a/custom_syadmin/git_hooks_post-receive.py b/custom_syadmin/git_hooks_post-receive.py index 28fcef9..50502da 100644 --- a/custom_syadmin/git_hooks_post-receive.py +++ b/custom_syadmin/git_hooks_post-receive.py @@ -9,7 +9,7 @@ python "D:\dev\websites\sandpoints-dev\custom_syadmin\git_hooks_post-receive.py" --git_repo "D:\dev\websites\pirate-care-syllabus\gitea\gitea-repositories\gitea\pirate-care-syllabus.git" \ --website "D:\dev\websites\testing-ground\sandpoints" \ --website_preview "D:\dev\websites\testing-ground\sandpoints\_preview" \ ---hugo_preview_url https://syllabus.pirate.care/_preview/ \ +--hugo_preview_url http://localhost:8000/_preview/ \ --library "D:\dev\websites\pirate-care-syllabus\_library" \ --tmp_dir "D:\tmp\tmp" --oldrev $oldrev \ @@ -20,6 +20,10 @@ To test this script from the command line without relying on a commit hook being python "D:\dev\websites\sandpoints-dev\custom_syadmin\git_hooks_post-receive.py" --ref refs/heads/master --git_repo "D:\dev\websites\pirate-care-syllabus\gitea\gitea-repositories\gitea\pirate-care-syllabus.git" --website D:\\dev\\websites\\testing-ground\\sandpoints --website_preview D:\\dev\\websites\\testing-ground\\sandpoints\\_preview --tmp_dir D:\\tmp\\tmp --git_url "http://localhost:3000/gitea/pirate-care-syllabus" --base_url "http://localhost:8000" +Just a mental note to read refs from the post-receive hook like this: + +oldrev,newrev,refname = sys.stdin.readline().strip().split(’ ‘) + """ import os import argparse @@ -48,6 +52,7 @@ vars = { 'hugo_path': 'hugo', 'tmp_dir': '/tmp', 'force': False, + 'branch': None, } # logging time @@ -98,10 +103,14 @@ def clobber(filepath, data, append=False): f.write(data) -def build_site(dest, tmp, hugo_environment='gitea'): +def build_site(dest, tmp, branch=None, hugo_environment='gitea'): """ builds the website to "dest" using "tmp" as an intermediate location """ global GIT_PATH, GIT_REPO, HUGO_PATH - cmd([GIT_PATH, 'clone', '.', tmp], cwd=GIT_REPO) + if branch: + print("Cloning branch: ", branch) + cmd([GIT_PATH, 'clone', '--single-branch', '--branch', branch, '.', tmp], cwd=GIT_REPO) + else: + cmd([GIT_PATH, 'clone', '.', tmp], cwd=GIT_REPO) rmrf(dest) try: os.makedirs(dest, exist_ok=True) @@ -156,7 +165,10 @@ if not published: if r == "!publish!": build_site(WEBSITE, TMP_WEBSITE) published = True +# Let the world know if there hasn't been a publish +if not published: + print("The site wasn't build because there was no publish trigger, nor was it forced.") # create preview version -build_site(WEBSITE_PREVIEW, TMP_WEBSITE_PREVIEW, hugo_environment='preview') +build_site(WEBSITE_PREVIEW, TMP_WEBSITE_PREVIEW, branch=BRANCH, hugo_environment='preview') # @TODO: link the library \ No newline at end of file