This improves the Build CI/CD System and the Release Commit Workflows. The CD system now builds and zips the pack in parallel, increasing the speed twofold. The CI system now does not produce double zips, but remains the same speed, thanks to parallel processing. The CI system now also changes server.properties and random patches config files for the build, and the buildscript has been edited for that. Since the CI system replaces the nightly task, the nightly workflow has been deleted. The makeArtifactNames task is now used, and has been changed to remove usage of deprecated features. The release commit workflows now supports updating files without version input, and the version is grabbed from versions.txt.' The code for the release commit workflows has also been greatly cleaned up. The changes made to the random patches template files have also been updated. The changes made incorrectly to the issue templates in #487 have also been fixed. The README badges have also been changed. The issue badge has been replaced by a nightly builds badge. Finally, this changes the forge download process to try again if the response is null, resulting in a decrease, to almost none, test build pack and build pack failures. [INTERNAL] [IGNORE] checks = { compareNot = "1.7-alpha-1" } [IGNORE]
145 lines
4.2 KiB
TypeScript
145 lines
4.2 KiB
TypeScript
import fs from "fs";
|
|
import gulp from "gulp";
|
|
import upath from "upath";
|
|
import buildConfig from "../../buildConfig";
|
|
import { modDestDirectory, modpackManifest, overridesFolder, sharedDestDirectory, tempDirectory } from "../../globals";
|
|
import del from "del";
|
|
import { FileDef } from "../../types/fileDef";
|
|
import Bluebird from "bluebird";
|
|
import { downloadFileDef, downloadOrRetrieveFileDef, isEnvVariableSet, relative } from "../../util/util";
|
|
|
|
async function sharedCleanUp() {
|
|
await del(upath.join(sharedDestDirectory, "*"), { force: true });
|
|
await del(upath.join(tempDirectory, "*"), { force: true });
|
|
}
|
|
|
|
/**
|
|
* Checks and creates all necessary directories so we can build everything safely.
|
|
*/
|
|
async function createSharedDirs() {
|
|
if (!fs.existsSync(sharedDestDirectory)) {
|
|
await fs.promises.mkdir(sharedDestDirectory, { recursive: true });
|
|
}
|
|
|
|
if (!fs.existsSync(tempDirectory)) {
|
|
await fs.promises.mkdir(tempDirectory, { recursive: true });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Copies modpack overrides.
|
|
*/
|
|
async function copyOverrides() {
|
|
return new Promise((resolve) => {
|
|
gulp
|
|
.src(upath.join(buildConfig.buildSourceDirectory, overridesFolder, "**/*"))
|
|
.pipe(gulp.dest(upath.join(sharedDestDirectory, overridesFolder)))
|
|
.on("end", resolve);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Fetch external dependencies and remove the field from the manifest file.
|
|
*/
|
|
async function fetchExternalDependencies() {
|
|
const dependencies = modpackManifest.externalDependencies;
|
|
if (dependencies) {
|
|
const destDirectory = upath.join(modDestDirectory, "mods");
|
|
|
|
if (!fs.existsSync(destDirectory)) {
|
|
await fs.promises.mkdir(destDirectory, { recursive: true });
|
|
}
|
|
|
|
// Map dependencies to FileDefs.
|
|
const depDefs: FileDef[] = dependencies.map((dep) => {
|
|
return {
|
|
url: dep.url,
|
|
hashes: [
|
|
{
|
|
hashes: [dep.sha],
|
|
id: "sha1",
|
|
},
|
|
],
|
|
};
|
|
});
|
|
|
|
delete modpackManifest.externalDependencies;
|
|
|
|
return Bluebird.map(
|
|
depDefs,
|
|
async (depDef) => {
|
|
const dest = upath.join(destDirectory, upath.basename(depDef.url));
|
|
const cachePath = (await downloadOrRetrieveFileDef(depDef)).cachePath;
|
|
|
|
const rel = relative(dest, cachePath);
|
|
|
|
await fs.promises.symlink(rel, dest);
|
|
},
|
|
{ concurrency: buildConfig.downloaderConcurrency },
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Either fetches the Changelog File, or makes one.
|
|
*/
|
|
async function fetchOrMakeChangelog() {
|
|
if (isEnvVariableSet("CHANGELOG_URL") && isEnvVariableSet("CHANGELOG_CF_URL")) {
|
|
log("Using Changelog Files from URL.");
|
|
await downloadChangelogs(process.env.CHANGELOG_URL, process.env.CHANGELOG_CF_URL);
|
|
return;
|
|
}
|
|
if (isEnvVariableSet("CHANGELOG_BRANCH")) {
|
|
log("Using Changelog Files from Branch.");
|
|
const url = "https://raw.githubusercontent.com/Nomi-CEu/Nomi-CEu/{{ branch }}/{{ filename }}";
|
|
await downloadChangelogs(
|
|
mustache.render(url, { branch: process.env.CHANGELOG_BRANCH, filename: "CHANGELOG.md" }),
|
|
mustache.render(url, { branch: process.env.CHANGELOG_BRNACH, filename: "CHANGELOG_CF.md" }),
|
|
);
|
|
return;
|
|
}
|
|
log("Creating Changelog Files.");
|
|
await createBuildChangelog();
|
|
}
|
|
|
|
async function downloadChangelogs(changelogURL: string, changelogCFURL: string) {
|
|
const changelog = await downloadFileDef({ url: changelogURL });
|
|
const changelogCF = await downloadFileDef({ url: changelogCFURL });
|
|
|
|
await writeToChangelog(changelog, "CHANGELOG.md", changelogURL);
|
|
await writeToChangelog(changelogCF, "CHANGELOG_CF.md", changelogCFURL);
|
|
}
|
|
|
|
async function writeToChangelog(buffer: Buffer, changelogFile: string, url: string) {
|
|
let handle: fs.promises.FileHandle;
|
|
try {
|
|
handle = await fs.promises.open(upath.join(buildConfig.buildDestinationDirectory, changelogFile), "w");
|
|
|
|
await handle.write(buffer);
|
|
await handle.close();
|
|
} catch (err) {
|
|
if (handle && (await handle.stat()).isFile()) {
|
|
log(`Couldn't download changelog from URL ${url}, cleaning up...`);
|
|
|
|
await handle.close();
|
|
}
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
import transformVersion from "./transformVersion";
|
|
import { createBuildChangelog } from "../changelog/createChangelog";
|
|
import mustache from "mustache";
|
|
import log from "fancy-log";
|
|
import { updateFilesBuild } from "../misc/transformFiles";
|
|
|
|
export default gulp.series(
|
|
sharedCleanUp,
|
|
createSharedDirs,
|
|
updateFilesBuild,
|
|
copyOverrides,
|
|
fetchOrMakeChangelog,
|
|
fetchExternalDependencies,
|
|
transformVersion,
|
|
);
|