jitsu-build-scripts
Advanced tools
Comparing version 0.0.3 to 0.0.4-dev.627.20240201162218
@@ -16,3 +16,3 @@ { | ||
"build": "pnpm compile && webpack", | ||
"exec": "ts-node src/index.ts docker ../ -t rotor --version 0.0.1" | ||
"exec": "ts-node src/index.ts" | ||
}, | ||
@@ -19,0 +19,0 @@ "dependencies": { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.docker = exports.runCommand = void 0; | ||
exports.runCommand = exports.docker = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -13,73 +13,3 @@ const path = tslib_1.__importStar(require("path")); | ||
const git = (0, simple_git_1.default)(); | ||
function formatDate(date) { | ||
const pad = number => number.toString().padStart(2, "0"); | ||
let year = date.getFullYear(); | ||
let month = pad(date.getMonth() + 1); | ||
let day = pad(date.getDate()); | ||
let hour = pad(date.getHours()); | ||
let minute = pad(date.getMinutes()); | ||
let second = pad(date.getSeconds()); | ||
return parseInt(`${year}${month}${day}${hour}${minute}${second}`); | ||
} | ||
async function adjustVersion(baseVersion, str, tagPrefix) { | ||
let version; | ||
if (!baseVersion) { | ||
const gitTags = await git.tags(); | ||
const allSemvers = gitTags.all | ||
.filter(tag => tag.startsWith(tagPrefix + "-") && tag.indexOf("beta") < 0) | ||
.map(tag => tag.slice(tagPrefix.length + 1)) | ||
.map(tag => (tag.startsWith("v") ? tag.slice(1) : tag)) | ||
.map(t => (0, semver_1.parse)(t)) | ||
.filter(Boolean); | ||
version = allSemvers.sort((a, b) => (0, semver_1.compare)(a, b)).pop(); | ||
if (!version) { | ||
throw new Error(`Couldn't guess version from git tags. Please provide --version param`); | ||
} | ||
} | ||
else { | ||
const bs = (0, semver_1.parse)(baseVersion); | ||
if (!bs) { | ||
throw new Error(`Cannot parse --version ${baseVersion} param as semver`); | ||
} | ||
version = bs; | ||
} | ||
if (str === "beta") { | ||
const gitHistory = await git.log(); | ||
const latest = gitHistory.all.length; | ||
const revision = gitHistory.latest.hash.slice(0, 7); | ||
return `${version.major}.${version.minor}.${latest}-${str}.${formatDate(new Date())}.${revision}`; | ||
} | ||
else { | ||
const nextVersion = `${version.major}.${version.minor}.${version.patch + 1}`; | ||
console.log(`Found latest stable release: ' + ${version.version}. Going to use ${nextVersion} as next version`); | ||
return nextVersion; | ||
} | ||
} | ||
function runCommand(command, opts = {}) { | ||
return new Promise((resolve, reject) => { | ||
const fullCommand = `${command}${opts.args && opts.args.length > 0 ? " " + opts.args?.join(" ") : ""}`; | ||
const proc = child_process.exec(fullCommand, { env: process.env, cwd: opts.cwd ? path.resolve(__dirname, opts.cwd) : undefined }, error => { | ||
if (error) { | ||
console.log(`Command \`${fullCommand}\`\n\tfailed with exit code ${error.code}: ${error?.message} || unknown error`); | ||
reject(error); | ||
} | ||
else { | ||
resolve(0); | ||
} | ||
}); | ||
proc.stdout?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stdout" }); | ||
} | ||
}); | ||
proc.stderr?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stderr" }); | ||
} | ||
}); | ||
}); | ||
} | ||
exports.runCommand = runCommand; | ||
async function docker(dir, args) { | ||
console.log("Dir: " + dir); | ||
let version = args.version; | ||
@@ -97,7 +27,7 @@ const dockerTag = args.release || "beta"; | ||
console.info(`💁🏻 Adjusted version for ${dockerTag} release: ` + colors_1.color.bold(colors_1.color.cyan(version))); | ||
const gitTag = `${tagPrefix}-${version}`; | ||
const gitTag = `${tagPrefix}-v${version}`; | ||
if ((await git.tags()).all.includes(gitTag)) { | ||
throw new Error(`Tag ${gitTag} for next version ${version} already exists. Aborting`); | ||
} | ||
const logsDir = args.logs ? path.resolve(__dirname, "../../../", args.logs) : undefined; | ||
const logsDir = args.logs ? path.resolve(__dirname, args.logs) : undefined; | ||
if (logsDir) { | ||
@@ -164,3 +94,3 @@ fs.mkdirSync(logsDir, { recursive: true }); | ||
if (!args.dryRun && args.push && args.pushGitTag) { | ||
console.log(`Pushing git tag ${tagPrefix}-${version}...`); | ||
console.log(`Pushing git tag ${gitTag}...`); | ||
await git.addTag(gitTag); | ||
@@ -171,2 +101,3 @@ try { | ||
catch (e) { | ||
throw new Error(`Failed to push git tag ${gitTag}: ${e.message}`); | ||
} | ||
@@ -176,1 +107,77 @@ } | ||
exports.docker = docker; | ||
function formatDate(date) { | ||
const pad = number => number.toString().padStart(2, "0"); | ||
let year = date.getFullYear(); | ||
let month = pad(date.getMonth() + 1); | ||
let day = pad(date.getDate()); | ||
let hour = pad(date.getHours()); | ||
let minute = pad(date.getMinutes()); | ||
let second = pad(date.getSeconds()); | ||
return parseInt(`${year}${month}${day}${hour}${minute}${second}`); | ||
} | ||
async function adjustVersion(manualVersion, str, tagPrefix) { | ||
let version; | ||
if (!manualVersion) { | ||
const gitTags = await git.tags(); | ||
const allSemvers = gitTags.all | ||
.filter(tag => tag.startsWith(tagPrefix + "-") && tag.indexOf("beta") < 0) | ||
.map(tag => tag.slice(tagPrefix.length + 1)) | ||
.map(tag => (tag.startsWith("v") ? tag.slice(1) : tag)) | ||
.map(t => (0, semver_1.parse)(t)) | ||
.filter(Boolean); | ||
version = allSemvers.sort((a, b) => (0, semver_1.compare)(a, b)).pop(); | ||
if (!version) { | ||
throw new Error(`Couldn't guess version from git tags. Please provide --version param`); | ||
} | ||
} | ||
else { | ||
const bs = (0, semver_1.parse)(manualVersion); | ||
if (!bs) { | ||
throw new Error(`Cannot parse --version ${manualVersion} param as semver`); | ||
} | ||
version = bs; | ||
} | ||
if (str === "beta") { | ||
const gitHistory = await git.log(); | ||
const latest = gitHistory.all.length; | ||
const revision = gitHistory.latest.hash.slice(0, 7); | ||
return `${version.major}.${version.minor}.${latest}-${str}.${formatDate(new Date())}.${revision}`; | ||
} | ||
else { | ||
if (manualVersion) { | ||
const nextVersion = `${version.major}.${version.minor}.${version.patch}`; | ||
console.log(`Going to use ${nextVersion} as next version`); | ||
return nextVersion; | ||
} | ||
else { | ||
const nextVersion = `${version.major}.${version.minor}.${version.patch + 1}`; | ||
console.log(`Found latest stable release: ' + ${version.version}. Going to use ${nextVersion} as next version`); | ||
return nextVersion; | ||
} | ||
} | ||
} | ||
function runCommand(command, opts = {}) { | ||
return new Promise((resolve, reject) => { | ||
const fullCommand = `${command}${opts.args && opts.args.length > 0 ? " " + opts.args?.join(" ") : ""}`; | ||
const proc = child_process.exec(fullCommand, { env: process.env, cwd: opts.cwd ? path.resolve(__dirname, opts.cwd) : undefined }, error => { | ||
if (error) { | ||
console.log(`Command \`${fullCommand}\`\n\tfailed with exit code ${error.code}: ${error?.message} || unknown error`); | ||
reject(error); | ||
} | ||
else { | ||
resolve(0); | ||
} | ||
}); | ||
proc.stdout?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stdout" }); | ||
} | ||
}); | ||
proc.stderr?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stderr" }); | ||
} | ||
}); | ||
}); | ||
} | ||
exports.runCommand = runCommand; |
@@ -14,8 +14,17 @@ "use strict"; | ||
.description("Builds and pushes docker images for Jitsu Next services") | ||
.arguments("[dir]") | ||
.requiredOption("-t, --targets <targets...>", "list of targets to build. Supported values: console, rotor, bulker, ingest, syncctl, sidecar") | ||
.addArgument(new commander_1.Argument("[dir]", "directory of project to build. Must contain all.Dockerfile file")) | ||
.addOption(new commander_1.Option("-t, --targets <targets...>", "list of targets to build").choices([ | ||
"console", | ||
"rotor", | ||
"bulker", | ||
"ingest", | ||
"syncctl", | ||
"sidecar", | ||
])) | ||
.option("-v, --version <semver>", "base version of release in semver format. Required for the first release or version bumps.") | ||
.option("--release <tag>", "docker release tag to use. Supported values: beta, latest", "beta") | ||
.addOption(new commander_1.Option("--release <tag>", "docker release tag to use").default("beta").choices(["beta", "latest"])) | ||
.option("--push", "whether to push images to docker hub or load it locally", false) | ||
.option("--platform <platform>", "docker platform to build for. Supported values: 'linux/amd64', 'linux/arm64', 'linux/amd64,linux/arm64'", "linux/amd64") | ||
.addOption(new commander_1.Option("--platform <platform>", "docker platform to build for") | ||
.default("linux/amd64") | ||
.choices(["linux/amd64", "linux/arm64", "linux/amd64,linux/arm64"])) | ||
.option("--gitTagPrefix <prefix>", "prefix that will be used for git tag before version", "jitsu2") | ||
@@ -22,0 +31,0 @@ .option("--dryRun", "dry run. Just prints commands that will be executed and do not build anything", false) |
{ | ||
"name": "jitsu-build-scripts", | ||
"version": "0.0.3", | ||
"version": "0.0.4-dev.627.20240201162218", | ||
"description": "", | ||
@@ -28,3 +28,3 @@ "author": "Jitsu Dev Team <dev@jitsu.com>", | ||
"webpack": "^5.88.2", | ||
"juava": "0.0.3" | ||
"juava": "0.0.4-dev.627.20240201162218" | ||
}, | ||
@@ -35,4 +35,4 @@ "scripts": { | ||
"build": "pnpm compile && webpack", | ||
"exec": "ts-node src/index.ts docker ../ -t rotor --version 0.0.1" | ||
"exec": "ts-node src/index.ts" | ||
} | ||
} |
@@ -15,88 +15,2 @@ import * as path from "path"; | ||
function formatDate(date: Date): number { | ||
const pad = number => number.toString().padStart(2, "0"); | ||
let year = date.getFullYear(); | ||
let month = pad(date.getMonth() + 1); // getMonth() returns 0-11 | ||
let day = pad(date.getDate()); | ||
let hour = pad(date.getHours()); | ||
let minute = pad(date.getMinutes()); | ||
let second = pad(date.getSeconds()); | ||
return parseInt(`${year}${month}${day}${hour}${minute}${second}`); | ||
} | ||
async function adjustVersion(baseVersion: string | undefined, str: ReleaseStream, tagPrefix: string): Promise<string> { | ||
let version: SemVer | undefined; | ||
if (!baseVersion) { | ||
const gitTags = await git.tags(); | ||
const allSemvers = gitTags.all | ||
.filter(tag => tag.startsWith(tagPrefix + "-") && tag.indexOf("beta") < 0) | ||
.map(tag => tag.slice(tagPrefix.length + 1)) | ||
.map(tag => (tag.startsWith("v") ? tag.slice(1) : tag)) | ||
.map(t => semverParse(t)) | ||
.filter(Boolean) as SemVer[]; | ||
version = allSemvers.sort((a, b) => semverCompare(a, b)).pop(); | ||
if (!version) { | ||
throw new Error(`Couldn't guess version from git tags. Please provide --version param`); | ||
} | ||
} else { | ||
const bs = semverParse(baseVersion); | ||
if (!bs) { | ||
throw new Error(`Cannot parse --version ${baseVersion} param as semver`); | ||
} | ||
version = bs; | ||
} | ||
if (str === "beta") { | ||
const gitHistory = await git.log(); | ||
const latest = gitHistory.all.length; | ||
const revision = gitHistory.latest!.hash.slice(0, 7); | ||
return `${version.major}.${version.minor}.${latest}-${str}.${formatDate(new Date())}.${revision}`; | ||
} else { | ||
const nextVersion = `${version.major}.${version.minor}.${version.patch + 1}`; | ||
console.log(`Found latest stable release: ' + ${version.version}. Going to use ${nextVersion} as next version`); | ||
return nextVersion; | ||
} | ||
} | ||
export function runCommand( | ||
command: string, | ||
opts: { | ||
args?: string[]; | ||
cwd?: string; | ||
outputHandler?: (data: any, opts: { stream: "stderr" | "stdout" }) => void; | ||
} = {} | ||
): Promise<number> { | ||
return new Promise((resolve, reject) => { | ||
const fullCommand = `${command}${opts.args && opts.args.length > 0 ? " " + opts.args?.join(" ") : ""}`; | ||
const proc = child_process.exec( | ||
fullCommand, | ||
{ env: process.env, cwd: opts.cwd ? path.resolve(__dirname, opts.cwd) : undefined }, | ||
error => { | ||
if (error) { | ||
console.log( | ||
`Command \`${fullCommand}\`\n\tfailed with exit code ${error.code}: ${error?.message} || unknown error` | ||
); | ||
reject(error); | ||
} else { | ||
resolve(0); | ||
} | ||
} | ||
); | ||
proc.stdout?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stdout" }); | ||
} | ||
}); | ||
proc.stderr?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stderr" }); | ||
} | ||
}); | ||
}); | ||
} | ||
export type DockerArgs = { | ||
@@ -115,3 +29,2 @@ targets: Target[]; | ||
export async function docker(dir: string | undefined, args: DockerArgs): Promise<void> { | ||
console.log("Dir: " + dir); | ||
let version = args.version; | ||
@@ -129,9 +42,10 @@ const dockerTag: ReleaseStream = args.release || "beta"; | ||
); | ||
version = await adjustVersion(version, dockerTag, tagPrefix); | ||
console.info(`💁🏻 Adjusted version for ${dockerTag} release: ` + color.bold(color.cyan(version))); | ||
const gitTag = `${tagPrefix}-${version}`; | ||
const gitTag = `${tagPrefix}-v${version}`; | ||
if ((await git.tags()).all.includes(gitTag)) { | ||
throw new Error(`Tag ${gitTag} for next version ${version} already exists. Aborting`); | ||
} | ||
const logsDir = args.logs ? path.resolve(__dirname, "../../../", args.logs) : undefined; | ||
const logsDir = args.logs ? path.resolve(__dirname, args.logs) : undefined; | ||
if (logsDir) { | ||
@@ -207,10 +121,106 @@ fs.mkdirSync(logsDir, { recursive: true }); | ||
if (!args.dryRun && args.push && args.pushGitTag) { | ||
console.log(`Pushing git tag ${tagPrefix}-${version}...`); | ||
console.log(`Pushing git tag ${gitTag}...`); | ||
await git.addTag(gitTag); | ||
try { | ||
await git.pushTags(); | ||
} catch (e) { | ||
//so far ignore, it happens when there's a conflict in tags | ||
} catch (e: any) { | ||
throw new Error(`Failed to push git tag ${gitTag}: ${e.message}`); | ||
} | ||
} | ||
} | ||
function formatDate(date: Date): number { | ||
const pad = number => number.toString().padStart(2, "0"); | ||
let year = date.getFullYear(); | ||
let month = pad(date.getMonth() + 1); // getMonth() returns 0-11 | ||
let day = pad(date.getDate()); | ||
let hour = pad(date.getHours()); | ||
let minute = pad(date.getMinutes()); | ||
let second = pad(date.getSeconds()); | ||
return parseInt(`${year}${month}${day}${hour}${minute}${second}`); | ||
} | ||
async function adjustVersion( | ||
manualVersion: string | undefined, | ||
str: ReleaseStream, | ||
tagPrefix: string | ||
): Promise<string> { | ||
let version: SemVer | undefined; | ||
if (!manualVersion) { | ||
const gitTags = await git.tags(); | ||
const allSemvers = gitTags.all | ||
.filter(tag => tag.startsWith(tagPrefix + "-") && tag.indexOf("beta") < 0) | ||
.map(tag => tag.slice(tagPrefix.length + 1)) | ||
.map(tag => (tag.startsWith("v") ? tag.slice(1) : tag)) | ||
.map(t => semverParse(t)) | ||
.filter(Boolean) as SemVer[]; | ||
version = allSemvers.sort((a, b) => semverCompare(a, b)).pop(); | ||
if (!version) { | ||
throw new Error(`Couldn't guess version from git tags. Please provide --version param`); | ||
} | ||
} else { | ||
const bs = semverParse(manualVersion); | ||
if (!bs) { | ||
throw new Error(`Cannot parse --version ${manualVersion} param as semver`); | ||
} | ||
version = bs; | ||
} | ||
if (str === "beta") { | ||
const gitHistory = await git.log(); | ||
const latest = gitHistory.all.length; | ||
const revision = gitHistory.latest!.hash.slice(0, 7); | ||
return `${version.major}.${version.minor}.${latest}-${str}.${formatDate(new Date())}.${revision}`; | ||
} else { | ||
if (manualVersion) { | ||
const nextVersion = `${version.major}.${version.minor}.${version.patch}`; | ||
console.log(`Going to use ${nextVersion} as next version`); | ||
return nextVersion; | ||
} else { | ||
const nextVersion = `${version.major}.${version.minor}.${version.patch + 1}`; | ||
console.log(`Found latest stable release: ' + ${version.version}. Going to use ${nextVersion} as next version`); | ||
return nextVersion; | ||
} | ||
} | ||
} | ||
export function runCommand( | ||
command: string, | ||
opts: { | ||
args?: string[]; | ||
cwd?: string; | ||
outputHandler?: (data: any, opts: { stream: "stderr" | "stdout" }) => void; | ||
} = {} | ||
): Promise<number> { | ||
return new Promise((resolve, reject) => { | ||
const fullCommand = `${command}${opts.args && opts.args.length > 0 ? " " + opts.args?.join(" ") : ""}`; | ||
const proc = child_process.exec( | ||
fullCommand, | ||
{ env: process.env, cwd: opts.cwd ? path.resolve(__dirname, opts.cwd) : undefined }, | ||
error => { | ||
if (error) { | ||
console.log( | ||
`Command \`${fullCommand}\`\n\tfailed with exit code ${error.code}: ${error?.message} || unknown error` | ||
); | ||
reject(error); | ||
} else { | ||
resolve(0); | ||
} | ||
} | ||
); | ||
proc.stdout?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stdout" }); | ||
} | ||
}); | ||
proc.stderr?.on("data", data => { | ||
if (data && opts.outputHandler) { | ||
opts.outputHandler(data, { stream: "stderr" }); | ||
} | ||
}); | ||
}); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Command } from "commander"; | ||
import { Command, Option, Argument } from "commander"; | ||
import { docker } from "./commands/docker"; | ||
@@ -16,6 +16,12 @@ import pkg from "../package.json"; | ||
.description("Builds and pushes docker images for Jitsu Next services") | ||
.arguments("[dir]") | ||
.requiredOption( | ||
"-t, --targets <targets...>", | ||
"list of targets to build. Supported values: console, rotor, bulker, ingest, syncctl, sidecar" | ||
.addArgument(new Argument("[dir]", "directory of project to build. Must contain all.Dockerfile file")) | ||
.addOption( | ||
new Option("-t, --targets <targets...>", "list of targets to build").choices([ | ||
"console", | ||
"rotor", | ||
"bulker", | ||
"ingest", | ||
"syncctl", | ||
"sidecar", | ||
]) | ||
) | ||
@@ -26,8 +32,8 @@ .option( | ||
) | ||
.option("--release <tag>", "docker release tag to use. Supported values: beta, latest", "beta") | ||
.addOption(new Option("--release <tag>", "docker release tag to use").default("beta").choices(["beta", "latest"])) | ||
.option("--push", "whether to push images to docker hub or load it locally", false) | ||
.option( | ||
"--platform <platform>", | ||
"docker platform to build for. Supported values: 'linux/amd64', 'linux/arm64', 'linux/amd64,linux/arm64'", | ||
"linux/amd64" | ||
.addOption( | ||
new Option("--platform <platform>", "docker platform to build for") | ||
.default("linux/amd64") | ||
.choices(["linux/amd64", "linux/arm64", "linux/amd64,linux/arm64"]) | ||
) | ||
@@ -34,0 +40,0 @@ .option("--gitTagPrefix <prefix>", "prefix that will be used for git tag before version", "jitsu2") |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
906764
12401