[FEATURE] /* Description: */ Also moves all nodejs stuff into `tools` package. Also adds a basic `CONTRIBUTING.md` file. Superseeds https://github.com/Nomi-CEu/Nomi-CEu/pull/431, which was closed as the branch needed to be renamed, due to the last two items on this list. TODO: - [x] Make it only run on master repo. - [x] Remove qb-lang-revamp branch from the events - [x] Allow workflow to run on all branches starting with test_buildscript? /* Commits: */ * Buildscript Changes * Make Contributing Docs a .md file * updateqb.yml v1 * Test QB change * Add lang file to commit file list * Another Test Change * Test with only lang path, + `./` at beginning of path * Test QB change * updateqb.yml v3 * Test QB Change * Add some debug settings * Remove debug, branch input. Switch to auto-commit action * Make activate: branches prefix `test_buildscript`, commit author GHA bot * Add branch prefix note into CONTRIBUTING.md * Make workflow only run if on master repo
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import fs from "fs";
|
|
import upath from "path";
|
|
import mustache from "mustache";
|
|
import { modpackManifest, overridesFolder, sharedDestDirectory } from "../../../globals";
|
|
|
|
const randomPatchesConfigFile = "config/randompatches.cfg";
|
|
|
|
/**
|
|
* Transform the version field of manifest.json.
|
|
*/
|
|
export default async function transformManifestVersion(): Promise<void> {
|
|
let versionTitle;
|
|
|
|
// We're building a tag.
|
|
if (process.env.GITHUB_TAG) {
|
|
const flavorTitle = process.env.BUILD_FLAVOR_TITLE;
|
|
const tag = process.env.GITHUB_TAG.replace(/^v/, "");
|
|
|
|
versionTitle = [modpackManifest.name, tag, flavorTitle].filter(Boolean).join(" - ");
|
|
|
|
modpackManifest.version = tag;
|
|
}
|
|
// If we're building a release candidate, transform it appropriately.
|
|
else if (process.env.RC_VERSION) {
|
|
const rcVer = process.env.RC_VERSION;
|
|
const flavorTitle = process.env.BUILD_FLAVOR_TITLE;
|
|
const tag = rcVer.replace(/^v/, "");
|
|
|
|
versionTitle = [modpackManifest.name, [tag, "Release Candidate"].join(" "), flavorTitle]
|
|
.filter(Boolean)
|
|
.join(" - ");
|
|
|
|
modpackManifest.version = rcVer;
|
|
// modpackManifest.version = [rcVer, "rc"].join("-"); // No need for rc at end of name
|
|
}
|
|
// If SHA is provided and the build isn't tagged, append both the branch and short SHA.
|
|
else if (process.env.GITHUB_SHA && process.env.GITHUB_REF && process.env.GITHUB_REF.startsWith("refs/heads/")) {
|
|
const shortCommit = process.env.GITHUB_SHA.substr(0, 7);
|
|
const branch = /refs\/heads\/(.+)/.exec(process.env.GITHUB_REF)?.[1];
|
|
if (!branch) {
|
|
throw new Error(`Invalid git ref: ${process.env.GITHUB_REF}`);
|
|
}
|
|
|
|
versionTitle = `${modpackManifest.name} (${branch} branch, ${shortCommit})`;
|
|
|
|
modpackManifest.version = `${branch}-${shortCommit}`;
|
|
} else {
|
|
versionTitle = `${modpackManifest.name} (manual build)`;
|
|
|
|
modpackManifest.version = "manual-build";
|
|
}
|
|
|
|
modpackManifest.name = versionTitle;
|
|
|
|
const randomPatchesConfigFilePath = upath.join(sharedDestDirectory, overridesFolder, randomPatchesConfigFile);
|
|
const randomPatchesFile = (await fs.promises.readFile(randomPatchesConfigFilePath)).toString();
|
|
|
|
return fs.promises.writeFile(
|
|
randomPatchesConfigFilePath,
|
|
mustache.render(randomPatchesFile, {
|
|
title: versionTitle,
|
|
}),
|
|
);
|
|
}
|