From 7d3d4e6e1ba6b8c3b8bc7e4e34d3c838d3153e37 Mon Sep 17 00:00:00 2001
From: Philipp Stadler <a51820432@unet.univie.ac.at>
Date: Sat, 13 Jul 2024 11:36:22 +0200
Subject: [PATCH] chore: more announcement customization

---
 build/announce/announce.ts | 34 +++++++++++++++++-----------------
 build/announce/run.ts      | 13 +++++++++++--
 make/announce.mk           |  8 ++++----
 make/apkgs.mk              |  1 -
 make/defs.mk               | 11 +++++++++++
 make/release.mk            |  3 ---
 6 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/build/announce/announce.ts b/build/announce/announce.ts
index 70a4744..ee5649e 100644
--- a/build/announce/announce.ts
+++ b/build/announce/announce.ts
@@ -7,18 +7,19 @@ interface AnnounceOpts {
   out: string
   releaseDir: string
   apkgFilenames: string[]
+  /** Pack title, e.g. Tapir Sciences */
+  title: string
+  /** Full repository name on Gitlab, e.g. kartenaale/sinologie-anki-pack */
+  repo: string
 }
 
 export async function announce (opts: AnnounceOpts): Promise<void> {
   const version = getReleaseVersion(opts.releaseDir)
   const announcement = [
-    `# Sinologie Anki Pack ${version} ist released! 🎉`,
-    `## Details zum Release:\n${linkToReleaseDetails(version)}`,
-    `## Download komplettes Pack als ZIP:\n${
-      allArtifactsZipDownload()
-    }`,
+    `# ${opts.title} ${version} ist released! 🎉`,
+    `## Details zum Release:\n${linkToReleaseDetails(opts.repo, version)}`,
     '## Download einzelne APKGs:',
-    ...(await linksToApkgs(opts.releaseDir, opts.apkgFilenames))
+    ...(await linksToApkgs(opts.repo, opts.releaseDir, opts.apkgFilenames))
   ].join('\n\n')
   await writeFile(opts.out, announcement, { encoding: 'utf-8' })
 }
@@ -31,15 +32,18 @@ function getReleaseVersion (dir: string): string {
   return dir.substring(dashIdx + 1)
 }
 
-function linkToReleaseDetails (version: string): string {
+function linkToReleaseDetails (repo: string, version: string): string {
   return (
-    `https://gitlab.phaidra.org/kartenaale/sinologie-anki-pack/-/releases/${
+    `https://gitlab.phaidra.org/${
+      repo
+    }/-/releases/${
       version
     }`
   )
 }
 
 async function linksToApkgs (
+  repo: string,
   releaseDir: string,
   apkgFilenames: string[]
 ): Promise<string[]> {
@@ -52,26 +56,22 @@ async function linksToApkgs (
     return `### ${
       basename(path, '.apkg').replace(/-/g, ' ').replace('fuer', 'für')
     }\n${
-        rawArtifactDownload(path)
+        rawArtifactDownload(repo, path)
       }`
   })
 }
 
-function rawArtifactDownload (path: string): string {
+function rawArtifactDownload (repo: string, path: string): string {
   if (path === '') {
     throw new Error('path required')
   }
-  return `https://gitlab.phaidra.org/kartenaale/sinologie-anki-pack/-/jobs/${
+  return `https://gitlab.phaidra.org/${
+    repo
+  }/-/jobs/${
     getCiJobId()
   }/artifacts/raw/${encodeURIComponent(path)}`
 }
 
-function allArtifactsZipDownload (): string {
-  return `https://gitlab.phaidra.org/kartenaale/sinologie-anki-pack/-/jobs/${
-    getCiJobId()
-  }/artifacts/download`
-}
-
 function getCiJobId (): string {
   return process.env.CI_JOB_ID ?? 'job-id-unavailable'
 }
diff --git a/build/announce/run.ts b/build/announce/run.ts
index 98cb5c5..3c0c329 100644
--- a/build/announce/run.ts
+++ b/build/announce/run.ts
@@ -2,12 +2,19 @@ import { exit } from 'process'
 import { announce } from './announce'
 import { parseArgs } from 'util'
 
-const { values: { out, releaseDir, apkg } } = parseArgs({
+const { values: { out, title, repo, releaseDir, apkg } } = parseArgs({
   options: {
     out: {
       type: 'string',
       short: 'o'
     },
+    title: {
+      type: 'string'
+    },
+    repo: {
+      type: 'string',
+      short: 'r'
+    },
     releaseDir: {
       type: 'string',
       short: 'p'
@@ -20,6 +27,8 @@ const { values: { out, releaseDir, apkg } } = parseArgs({
 })
 
 if (out === undefined ||
+    title === undefined ||
+    repo === undefined ||
     releaseDir === undefined ||
     apkg === undefined ||
     apkg.length === 0) {
@@ -27,7 +36,7 @@ if (out === undefined ||
   throw new Error(`error: missing arguments, exiting.\nargs:${given}`)
 }
 
-void announce({ out, releaseDir, apkgFilenames: apkg }).then(
+void announce({ out, title, repo, releaseDir, apkgFilenames: apkg }).then(
   undefined,
   e => {
     console.error(e)
diff --git a/make/announce.mk b/make/announce.mk
index 309ae69..fe3cfe5 100644
--- a/make/announce.mk
+++ b/make/announce.mk
@@ -8,8 +8,8 @@ announce: $(ANNOUNCEMENT_FILE)
 $(ANNOUNCEMENT_FILE): $(ANNOUNCE) $(PYTHON_NEEDED) build/export_apkgs.py
 	$(ANNOUNCE) \
 		--out $@ \
-		--releaseDir $(RELEASE_DIR) \
+		--title '$(PACK_TITLE)' \
+		--repo $(GITLAB_REPO) \
+		--releaseDir $(DOWNLOAD_PREFIX)$(RELEASE_DIR) \
 		$(addprefix --apkg , \
-			$(patsubst %,'%', \
-				$(shell PIPENV_VENV_IN_PROJECT=1 pipenv run \
-					build/export_apkgs.py --dry-run -c content -t no)))
+			$(patsubst %,'%',$(APKGS)))
diff --git a/make/apkgs.mk b/make/apkgs.mk
index 12179ef..4992229 100644
--- a/make/apkgs.mk
+++ b/make/apkgs.mk
@@ -1,4 +1,3 @@
-CONTENT_DIR ?= content
 APKG_TEST_DIR := test/build
 APKG_TEST_OK_FLAG := $(BUILD_PREFIX).apkg-test-ok
 APKG_TEST_FILES := $(shell find $(APKG_TEST_DIR) -name '*.py' -o -name '*.yaml' -o -name '*.html' -o -name '*.csv')
diff --git a/make/defs.mk b/make/defs.mk
index 52efe7f..fe0c93c 100644
--- a/make/defs.mk
+++ b/make/defs.mk
@@ -11,3 +11,14 @@ BUILD_PREFIX := $(and $(filter-out . ./,$(BUILD_PREFIX)),$(BUILD_PREFIX)/)
 # some build subprocesses need this, e.g. the JS proxy for parcel needs to
 # know where to load the chardata from
 export BUILD_PREFIX
+
+# directory with apkg data and specs, can be overridden
+CONTENT_DIR ?= content
+
+# name of the repository on gitlab for download links
+GITLAB_REPO ?= kartenaale/sinologie-anki-pack
+
+PACK_TITLE ?= Sinologie Anki Pack
+# part before the npm version in the release directory name
+RELEASE_DIR_STEM ?= sinologie-anki-pack
+VERSION ?= $(shell grep '"version":' package.json -m 1 | cut -d '"' -f 4)
\ No newline at end of file
diff --git a/make/release.mk b/make/release.mk
index daed84d..3fe25cd 100644
--- a/make/release.mk
+++ b/make/release.mk
@@ -1,6 +1,3 @@
-# part before the npm version in the release directory name
-RELEASE_DIR_STEM ?= sinologie-anki-pack
-VERSION ?= $(shell grep '"version":' package.json -m 1 | cut -d '"' -f 4)
 RELEASE_DIR := $(BUILD_PREFIX)$(RELEASE_DIR_STEM)-$(VERSION)
 RELEASE_ZIP := $(RELEASE_DIR).zip
 
-- 
GitLab