From c104e7d7ff27ce05541788deea7e8d71778eb1a1 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 01:10:26 +0100
Subject: [PATCH 01/13] add resource group to deploy job

---
 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bc2e0930..18f8791f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -65,3 +65,4 @@ deploy:
         url: https://vtt.f3l.de/
     only:
         - master
+    resource_group: production

From 33a11e16ac5471d152ed43ca68f4abeaef9dfbaf Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:08:24 +0100
Subject: [PATCH 02/13] add proper gulp task to update version

---
 gulpfile.js  | 118 ++++++---------------------------------------------
 package.json |   2 +-
 2 files changed, 14 insertions(+), 106 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index dc62e8b7..295dc429 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -2,14 +2,11 @@ const gulp = require("gulp");
 const fs = require("fs-extra");
 const path = require("path");
 const chalk = require("chalk");
-const archiver = require("archiver");
 const stringify = require("json-stringify-pretty-compact");
 const typescript = require("typescript");
 
 const ts = require("gulp-typescript");
-const less = require("gulp-less");
 const sass = require("gulp-sass");
-const git = require("gulp-git");
 
 const argv = require("yargs").argv;
 
@@ -127,13 +124,6 @@ function buildTS() {
     return gulp.src("src/**/*.ts").pipe(tsConfig()).pipe(gulp.dest("dist"));
 }
 
-/**
- * Build Less
- */
-function buildLess() {
-    return gulp.src("src/*.less").pipe(less()).pipe(gulp.dest("dist"));
-}
-
 /**
  * Build SASS
  */
@@ -163,7 +153,6 @@ async function copyFiles() {
  */
 function buildWatch() {
     gulp.watch("src/**/*.ts", { ignoreInitial: false }, buildTS);
-    gulp.watch("src/**/*.less", { ignoreInitial: false }, buildLess);
     gulp.watch("src/**/*.scss", { ignoreInitial: false }, buildSASS);
     gulp.watch(["src/fonts", "src/lang", "src/templates", "src/*.json"], { ignoreInitial: false }, copyFiles);
 }
@@ -194,8 +183,8 @@ async function clean() {
         );
     }
 
-    // If the project uses Less or SASS
-    if (fs.existsSync(path.join("src", `${name}.less`)) || fs.existsSync(path.join("src", `${name}.scss`))) {
+    // If the project uses SASS
+    if (fs.existsSync(path.join("src", `${name}.scss`))) {
         files.push("fonts", `${name}.css`);
     }
 
@@ -268,69 +257,14 @@ async function linkUserData() {
 /*		PACKAGE		 */
 /*********************/
 
-/**
- * Package build
- */
-async function packageBuild() {
-    const manifest = getManifest();
-
-    return new Promise((resolve, reject) => {
-        try {
-            // Remove the package dir without doing anything else
-            if (argv.clean || argv.c) {
-                console.log(chalk.yellow("Removing all packaged files"));
-                fs.removeSync("package");
-                return;
-            }
-
-            // Ensure there is a directory to hold all the packaged versions
-            fs.ensureDirSync("package");
-
-            // Initialize the zip file
-            const zipName = `${manifest.file.name}-v${manifest.file.version}.zip`;
-            const zipFile = fs.createWriteStream(path.join("package", zipName));
-            const zip = archiver("zip", { zlib: { level: 9 } });
-
-            zipFile.on("close", () => {
-                console.log(chalk.green(zip.pointer() + " total bytes"));
-                console.log(chalk.green(`Zip file ${zipName} has been written`));
-                return resolve();
-            });
-
-            zip.on("error", (err) => {
-                throw err;
-            });
-
-            zip.pipe(zipFile);
-
-            // Add the directory with the final code
-            zip.directory("dist/", manifest.file.name);
-
-            zip.finalize();
-        } catch (err) {
-            return reject(err);
-        }
-    });
-}
-
-/*********************/
-/*		PACKAGE		 */
-/*********************/
-
 /**
  * Update version and URLs in the manifest JSON
  */
 function updateManifest(cb) {
     const packageJson = fs.readJSONSync("package.json");
-    const config = getConfig(),
-        manifest = getManifest(),
-        rawURL = config.rawURL,
-        repoURL = config.repository,
-        manifestRoot = manifest.root;
+    const manifest = getManifest();
 
-    if (!config) cb(Error(chalk.red("foundryconfig.json not found")));
     if (!manifest) cb(Error(chalk.red("Manifest JSON not found")));
-    if (!rawURL || !repoURL) cb(Error(chalk.red("Repository URLs not configured in foundryconfig.json")));
 
     try {
         const version = argv.update || argv.u;
@@ -374,20 +308,18 @@ function updateManifest(cb) {
         packageJson.version = targetVersion;
         manifest.file.version = targetVersion;
 
-        /* Update URLs */
+        /* Update URL */
+        const result = `https://git.f3l.de/dungeonslayers/ds4/-/jobs/artifacts/${targetVersion}/download?job=build`;
 
-        const result = `${rawURL}/v${manifest.file.version}/package/${manifest.file.name}-v${manifest.file.version}.zip`;
-
-        manifest.file.url = repoURL;
-        manifest.file.manifest = `${rawURL}/master/${manifestRoot}/${manifest.name}`;
         manifest.file.download = result;
 
-        const prettyProjectJson = stringify(manifest.file, {
-            maxLength: 35,
-            indent: "\t",
-        });
+        const prettyProjectJson =
+            stringify(manifest.file, {
+                maxLength: 40,
+                indent: 4,
+            }) + "\n";
 
-        fs.writeJSONSync("package.json", packageJson, { spaces: "\t" });
+        fs.writeJSONSync("package.json", packageJson, { spaces: 4 });
         fs.writeFileSync(path.join(manifest.root, manifest.name), prettyProjectJson, "utf8");
 
         return cb();
@@ -396,34 +328,10 @@ function updateManifest(cb) {
     }
 }
 
-function gitAdd() {
-    return gulp.src("package").pipe(git.add({ args: "--no-all" }));
-}
-
-function gitCommit() {
-    return gulp.src("./*").pipe(
-        git.commit(`v${getManifest().file.version}`, {
-            args: "-a",
-            disableAppendPaths: true,
-        }),
-    );
-}
-
-function gitTag() {
-    const manifest = getManifest();
-    return git.tag(`v${manifest.file.version}`, `Updated to ${manifest.file.version}`, (err) => {
-        if (err) throw err;
-    });
-}
-
-const execGit = gulp.series(gitAdd, gitCommit, gitTag);
-
-const execBuild = gulp.parallel(buildTS, buildLess, buildSASS, copyFiles);
+const execBuild = gulp.parallel(buildTS, buildSASS, copyFiles);
 
 exports.build = gulp.series(clean, execBuild);
 exports.watch = buildWatch;
 exports.clean = clean;
 exports.link = linkUserData;
-exports.package = packageBuild;
-exports.update = updateManifest;
-exports.publish = gulp.series(clean, updateManifest, execBuild, packageBuild, execGit);
+exports.updateManifest = updateManifest;
diff --git a/package.json b/package.json
index 9ebc7bd8..99a5f5d8 100644
--- a/package.json
+++ b/package.json
@@ -27,12 +27,12 @@
         }
     ],
     "scripts": {
-        "package": "gulp package",
         "build": "gulp build",
         "build:watch": "gulp watch",
         "link": "gulp link",
         "clean": "gulp clean && gulp link --clean",
         "update": "npm install --save-dev git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#f3l-fixes",
+        "updateManifest": "gulp updateManifest",
         "lint": "eslint 'src/**/*.ts' --cache",
         "lint:fix": "eslint 'src/**/*.ts' --cache --fix",
         "test": "ts-node ./node_modules/jasmine/bin/jasmine",

From 26ee1213a93790a0bb5d2d72b192c959f3810393 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:20:23 +0100
Subject: [PATCH 03/13] add release-patch job

---
 .gitlab-ci.yml | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 18f8791f..5891a5d8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,6 +5,7 @@ stages:
     - test
     - build
     - deploy
+    - release
 
 cache: &global_cache
     key:
@@ -66,3 +67,33 @@ deploy:
     only:
         - master
     resource_group: production
+
+release-patch:
+    stage: release
+    before_script:
+        - apt update
+        - apt install jq
+    variables:
+        RELEASE_TYPE: patch
+    cache:
+        <<: *global_cache
+    script: |
+        REPOSITORY_URL=$(echo "${CI_REPOSITORY_URL}" | sed -e "s|gitlab-ci-token:.*@|${RELEASE_TOKEN}:${RELEASE_TOKEN_SECRET}@|g")
+        git remote set-url origin $REPOSITORY_URL
+        git config user.name $GITLAB_USER_LOGIN
+        git config user.email $GITLAB_USER_EMAIL
+        git branch -D ci-processing || true
+        git checkout -b ci-processing
+        npm run updateManifest --update=${RELEASE_TYPE}
+        npm install
+        RELEASE_VERSION=$(jq -r '.version' < package.json)
+        git add package.json package-lock.json src/system.json
+        git commit -m "release version ${VERSION}"
+        git tag -f latest
+        git tag ${RELEASE_VERSION}
+        # git push origin ci-processing:${CI_BUILD_REF_NAME}
+        # git push latest -f
+        # git push ${RELEASE_VERSION}
+    # only:
+    #     - master
+    when: manual

From 0400db29640daa7fd79961277c981cd775e46ee5 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:23:56 +0100
Subject: [PATCH 04/13] fix jq installation

---
 .gitlab-ci.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5891a5d8..bd4b04f7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -72,7 +72,7 @@ release-patch:
     stage: release
     before_script:
         - apt update
-        - apt install jq
+        - apt install --yes jq
     variables:
         RELEASE_TYPE: patch
     cache:
@@ -92,8 +92,8 @@ release-patch:
         git tag -f latest
         git tag ${RELEASE_VERSION}
         # git push origin ci-processing:${CI_BUILD_REF_NAME}
-        # git push latest -f
-        # git push ${RELEASE_VERSION}
+        # git push origin latest -f
+        # git push origin ${RELEASE_VERSION}
     # only:
     #     - master
     when: manual

From 75e21fcf5f8f202104cacaf77ce3f4fead9b53c1 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:25:57 +0100
Subject: [PATCH 05/13] fix npm run updateManifest

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bd4b04f7..a418d36c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -84,7 +84,7 @@ release-patch:
         git config user.email $GITLAB_USER_EMAIL
         git branch -D ci-processing || true
         git checkout -b ci-processing
-        npm run updateManifest --update=${RELEASE_TYPE}
+        npm run updateManifest -- --update=${RELEASE_TYPE}
         npm install
         RELEASE_VERSION=$(jq -r '.version' < package.json)
         git add package.json package-lock.json src/system.json

From 9303dcf1f2bf94a581f78445c4b94ba40ce00909 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:29:30 +0100
Subject: [PATCH 06/13] show git diff

---
 .gitlab-ci.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a418d36c..41075096 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -88,9 +88,10 @@ release-patch:
         npm install
         RELEASE_VERSION=$(jq -r '.version' < package.json)
         git add package.json package-lock.json src/system.json
+        git diff
         git commit -m "release version ${VERSION}"
         git tag -f latest
-        git tag ${RELEASE_VERSION}
+        git tag -f ${RELEASE_VERSION}
         # git push origin ci-processing:${CI_BUILD_REF_NAME}
         # git push origin latest -f
         # git push origin ${RELEASE_VERSION}

From f5d52825e8cc1ac8a2eae7389cb1f806eefbd9ee Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:34:30 +0100
Subject: [PATCH 07/13] actually show diff

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 41075096..ad898eb5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -88,7 +88,7 @@ release-patch:
         npm install
         RELEASE_VERSION=$(jq -r '.version' < package.json)
         git add package.json package-lock.json src/system.json
-        git diff
+        git --no-pager diff
         git commit -m "release version ${VERSION}"
         git tag -f latest
         git tag -f ${RELEASE_VERSION}

From e99906a18a6200cf5bddf9b47db25fc38fca0f1c Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:40:52 +0100
Subject: [PATCH 08/13] update package-lock.json in gulp task

---
 .gitlab-ci.yml | 1 -
 gulpfile.js    | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ad898eb5..1b13b711 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -85,7 +85,6 @@ release-patch:
         git branch -D ci-processing || true
         git checkout -b ci-processing
         npm run updateManifest -- --update=${RELEASE_TYPE}
-        npm install
         RELEASE_VERSION=$(jq -r '.version' < package.json)
         git add package.json package-lock.json src/system.json
         git --no-pager diff
diff --git a/gulpfile.js b/gulpfile.js
index 295dc429..1cf31998 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -262,6 +262,7 @@ async function linkUserData() {
  */
 function updateManifest(cb) {
     const packageJson = fs.readJSONSync("package.json");
+    const packageLockJson = fs.readJSONSync("package-lock.json");
     const manifest = getManifest();
 
     if (!manifest) cb(Error(chalk.red("Manifest JSON not found")));
@@ -306,6 +307,7 @@ function updateManifest(cb) {
         console.log(`Updating version number to '${targetVersion}'`);
 
         packageJson.version = targetVersion;
+        packageLockJson.version = targetVersion;
         manifest.file.version = targetVersion;
 
         /* Update URL */
@@ -320,6 +322,7 @@ function updateManifest(cb) {
             }) + "\n";
 
         fs.writeJSONSync("package.json", packageJson, { spaces: 4 });
+        fs.writeJSONSync("package-lock.json", packageLockJson, { spaces: 4 });
         fs.writeFileSync(path.join(manifest.root, manifest.name), prettyProjectJson, "utf8");
 
         return cb();

From 8301fb17fb8dc8160bfcad464a1c53d73f1df961 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:47:20 +0100
Subject: [PATCH 09/13] add minor and major release jobs

---
 .gitlab-ci.yml | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1b13b711..0cd248e5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -68,13 +68,11 @@ deploy:
         - master
     resource_group: production
 
-release-patch:
+.release-template: &release-template
     stage: release
     before_script:
         - apt update
         - apt install --yes jq
-    variables:
-        RELEASE_TYPE: patch
     cache:
         <<: *global_cache
     script: |
@@ -88,7 +86,7 @@ release-patch:
         RELEASE_VERSION=$(jq -r '.version' < package.json)
         git add package.json package-lock.json src/system.json
         git --no-pager diff
-        git commit -m "release version ${VERSION}"
+        git commit -m "release version ${RELEASE_VERSION}"
         git tag -f latest
         git tag -f ${RELEASE_VERSION}
         # git push origin ci-processing:${CI_BUILD_REF_NAME}
@@ -97,3 +95,18 @@ release-patch:
     # only:
     #     - master
     when: manual
+
+release-patch:
+    variables:
+        RELEASE_TYPE: patch
+    <<: *release-template
+
+release-minor:
+    variables:
+        RELEASE_TYPE: patch
+    <<: *release-template
+
+release-major:
+    variables:
+        RELEASE_TYPE: patch
+    <<: *release-template

From e2d198134ed67c35216b77749062ac338f5171eb Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:49:05 +0100
Subject: [PATCH 10/13] enable push

---
 .gitlab-ci.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0cd248e5..8288d410 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -89,9 +89,9 @@ deploy:
         git commit -m "release version ${RELEASE_VERSION}"
         git tag -f latest
         git tag -f ${RELEASE_VERSION}
-        # git push origin ci-processing:${CI_BUILD_REF_NAME}
-        # git push origin latest -f
-        # git push origin ${RELEASE_VERSION}
+        git push origin ci-processing:${CI_BUILD_REF_NAME}
+        git push origin latest -f
+        git push origin ${RELEASE_VERSION}
     # only:
     #     - master
     when: manual

From e735ecee09b2555240359732773cbdbbf355e82f Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 18:55:53 +0100
Subject: [PATCH 11/13] actually release minor/major version when attemtpting
 to do so

---
 .gitlab-ci.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8288d410..cdf38666 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -103,10 +103,10 @@ release-patch:
 
 release-minor:
     variables:
-        RELEASE_TYPE: patch
+        RELEASE_TYPE: minor
     <<: *release-template
 
 release-major:
     variables:
-        RELEASE_TYPE: patch
+        RELEASE_TYPE: major
     <<: *release-template

From 8856c30165ed6e5126f57d54a84ccf8fe6644b85 Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 19:01:22 +0100
Subject: [PATCH 12/13] move technical stuff to before_script

---
 .gitlab-ci.yml  | 12 ++++++------
 src/system.json |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cdf38666..0d85bab0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -73,15 +73,15 @@ deploy:
     before_script:
         - apt update
         - apt install --yes jq
+        - REPOSITORY_URL=$(echo "${CI_REPOSITORY_URL}" | sed -e "s|gitlab-ci-token:.*@|${RELEASE_TOKEN}:${RELEASE_TOKEN_SECRET}@|g")
+        - git remote set-url origin $REPOSITORY_URL
+        - git config user.name $GITLAB_USER_LOGIN
+        - git config user.email $GITLAB_USER_EMAIL
+        - git branch -D ci-processing || true
+        - git checkout -b ci-processing
     cache:
         <<: *global_cache
     script: |
-        REPOSITORY_URL=$(echo "${CI_REPOSITORY_URL}" | sed -e "s|gitlab-ci-token:.*@|${RELEASE_TOKEN}:${RELEASE_TOKEN_SECRET}@|g")
-        git remote set-url origin $REPOSITORY_URL
-        git config user.name $GITLAB_USER_LOGIN
-        git config user.email $GITLAB_USER_EMAIL
-        git branch -D ci-processing || true
-        git checkout -b ci-processing
         npm run updateManifest -- --update=${RELEASE_TYPE}
         RELEASE_VERSION=$(jq -r '.version' < package.json)
         git add package.json package-lock.json src/system.json
diff --git a/src/system.json b/src/system.json
index a64a1a8c..e9653678 100644
--- a/src/system.json
+++ b/src/system.json
@@ -22,7 +22,7 @@
     "gridUnits": "m",
     "primaryTokenAttribute": "combatValues.hitPoints",
     "url": "https://git.f3l.de/dungeonslayers/ds4",
-    "manifest": "https://git.f3l.de/dungeonslayers/ds4/-/raw/master/src/system.json?inline=false",
+    "manifest": "https://git.f3l.de/dungeonslayers/ds4/-/raw/latest/src/system.json?inline=false",
     "download": "https://git.f3l.de/dungeonslayers/ds4/-/jobs/artifacts/0.1.0/download?job=build",
     "license": "MIT"
 }

From fe4acd2d9df4e6633b353d5310c911544f99473d Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Sat, 9 Jan 2021 19:06:26 +0100
Subject: [PATCH 13/13] only do releases on master

---
 .gitlab-ci.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0d85bab0..784d4db6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -92,8 +92,8 @@ deploy:
         git push origin ci-processing:${CI_BUILD_REF_NAME}
         git push origin latest -f
         git push origin ${RELEASE_VERSION}
-    # only:
-    #     - master
+    only:
+        - master
     when: manual
 
 release-patch: