From 7f29a02f0ef549e8175724756880291ec0e30dee Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Thu, 27 Jun 2024 14:37:46 +0200 Subject: [PATCH] fix: migration --- src/commands/binary/utils.ts | 26 ++++++++++++++++---------- src/commands/docker/builder.ts | 25 +++++++++++++++---------- src/util.ts | 4 ++-- src/utils/builds.ts | 6 +++--- src/utils/config.ts | 8 ++++---- src/utils/docker.ts | 10 +++++----- 6 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/commands/binary/utils.ts b/src/commands/binary/utils.ts index e65c5f813..7b8754910 100644 --- a/src/commands/binary/utils.ts +++ b/src/commands/binary/utils.ts @@ -1,9 +1,15 @@ import { getInput } from '@actions/core'; -import is from '@sindresorhus/is'; +import { + isNonEmptyArray, + isNonEmptyString, + isObject, + isString, +} from '@sindresorhus/is'; import { getDefaultVersioning } from 'renovate/dist/modules/datasource/common'; import { getArch, getArg, getDistro, isDryRun, readJson } from '../../util'; import { readDockerConfig } from '../../utils/config'; import { + DockerArch, DockerPlatform, dockerBuildx, dockerRun, @@ -16,15 +22,15 @@ export async function getConfig(): Promise { const cfg = await readJson(configFile); - if (!is.object(cfg)) { + if (!isObject(cfg)) { throw new Error('missing-config'); } - if (!is.string(cfg.image)) { + if (!isString(cfg.image)) { cfg.image = getInput('image', { required: true }); } - if (!is.string(cfg.buildArg)) { + if (!isString(cfg.buildArg)) { cfg.buildArg = cfg.image.toUpperCase() + '_VERSION'; } @@ -48,13 +54,13 @@ export async function createBuilderImage( const args = ['build', '--load', '-t', 'builder']; const distro = getDistro(); const arch = getArch(); - if (is.nonEmptyString(distro)) { + if (isNonEmptyString(distro)) { args.push('--build-arg', `DISTRO=${distro}`); } - if (is.nonEmptyString(arch)) { - args.push('--platform', DockerPlatform[arch]); + if (isNonEmptyString(arch)) { + args.push('--platform', DockerPlatform[arch as DockerArch]); } - if (is.nonEmptyArray(buildArgs)) { + if (isNonEmptyArray(buildArgs)) { args.push(...buildArgs.map((b) => `--build-arg=${b}`)); } await dockerBuildx(...args, ws); @@ -63,8 +69,8 @@ export async function createBuilderImage( export async function runBuilder(ws: string, version: string): Promise { const args = ['--name', 'builder', '--volume', `${ws}/.cache:/cache`]; const arch = getArch(); - if (is.nonEmptyString(arch)) { - args.push('--platform', DockerPlatform[arch]); + if (isNonEmptyString(arch)) { + args.push('--platform', DockerPlatform[arch as DockerArch]); } await dockerRun(...args, 'builder', version); } diff --git a/src/commands/docker/builder.ts b/src/commands/docker/builder.ts index ce7fa2c70..2358ce525 100644 --- a/src/commands/docker/builder.ts +++ b/src/commands/docker/builder.ts @@ -1,5 +1,10 @@ import { getInput, setFailed } from '@actions/core'; -import is from '@sindresorhus/is'; +import { + isNonEmptyString, + isNumber, + isObject, + isString, +} from '@sindresorhus/is'; import chalk from 'chalk'; import { getDefaultVersioning } from 'renovate/dist/modules/datasource/common'; import { get as getVersioning } from 'renovate/dist/modules/versioning'; @@ -14,7 +19,7 @@ import log from '../../utils/logger'; import type { ConfigFile, DockerBuilderConfig } from '../../utils/types'; function createTag(tagSuffix: string | undefined, version: string): string { - return is.nonEmptyString(tagSuffix) && tagSuffix !== 'latest' + return isNonEmptyString(tagSuffix) && tagSuffix !== 'latest' ? `${version}-${tagSuffix}` : version; } @@ -51,14 +56,14 @@ async function buildAndPush( const major = ver.getMajor(version); const isStable = ver.isStable(version); - if (isStable && is.number(major) && `${major}` !== version) { + if (isStable && isNumber(major) && `${major}` !== version) { versionsMap.set(`${major}`, version); } if ( isStable && - is.number(major) && - is.number(minor) && + isNumber(major) && + isNumber(minor) && `${major}.${minor}` !== version ) { versionsMap.set(`${major}.${minor}`, version); @@ -93,7 +98,7 @@ async function buildAndPush( const cacheToTags: string[] = []; const tags: string[] = []; - if (is.number(major)) { + if (isNumber(major)) { const nTag = createTag(tagSuffix, `${major}`); cacheFromTags.push(nTag); if (versionsMap.get(`${major}`) === version) { @@ -103,7 +108,7 @@ async function buildAndPush( } } } - if (is.number(major) && is.number(minor)) { + if (isNumber(major) && isNumber(minor)) { const nTag = createTag(tagSuffix, `${major}.${minor}`); cacheFromTags.push(nTag); if (versionsMap.get(`${major}.${minor}`) === version) { @@ -198,16 +203,16 @@ export async function run(): Promise { const cfg = await readJson(configFile); - if (!is.object(cfg)) { + if (!isObject(cfg)) { throw new Error('missing-config'); } // TODO: validation - if (!is.string(cfg.image)) { + if (!isString(cfg.image)) { cfg.image = getInput('image', { required: true }); } - if (!is.string(cfg.buildArg)) { + if (!isString(cfg.buildArg)) { cfg.buildArg = cfg.image.toUpperCase() + '_VERSION'; } diff --git a/src/util.ts b/src/util.ts index 0d13aad09..83ecdfcdf 100644 --- a/src/util.ts +++ b/src/util.ts @@ -4,7 +4,7 @@ import { endGroup, getInput, startGroup } from '@actions/core'; import { exec as _exec } from '@actions/exec'; import type { ExecOptions as _ExecOptions } from '@actions/exec/lib/interfaces'; import { which } from '@actions/io'; -import is from '@sindresorhus/is'; +import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is'; import findUp from 'find-up'; import type { DockerArch } from './utils/docker/common'; import { ExecError, ExecResult } from './utils/types'; @@ -130,7 +130,7 @@ export function getArg( /* c8 ignore stop */ const val = getInput(name, opts); return opts?.multi - ? val.split(MultiArgsSplitRe).filter(is.nonEmptyStringAndNotWhitespace) + ? val.split(MultiArgsSplitRe).filter(isNonEmptyStringAndNotWhitespace) : val; } diff --git a/src/utils/builds.ts b/src/utils/builds.ts index 3e646be43..1d4c5dd60 100644 --- a/src/utils/builds.ts +++ b/src/utils/builds.ts @@ -1,4 +1,4 @@ -import is from '@sindresorhus/is'; +import { isNumber, isString } from '@sindresorhus/is'; import { ReleaseResult, getPkgReleases, @@ -96,7 +96,7 @@ export async function getBuildList({ allVersions = allVersions.filter((v) => ver.isStable(v)); } - if (is.string(allowedVersions)) { + if (isString(allowedVersions)) { const isAllowedPred = getRegexPredicate(allowedVersions); if (isAllowedPred) { allVersions = allVersions.filter((version) => isAllowedPred(version)); @@ -142,7 +142,7 @@ export async function getBuildList({ const lastVersion = allVersions.at(-1)!; log('Most recent version is', lastVersion); - if (is.number(maxVersions) && maxVersions > 0) { + if (isNumber(maxVersions) && maxVersions > 0) { log(`Building last ${maxVersions} version only`); allVersions = allVersions.slice(-maxVersions); } diff --git a/src/utils/config.ts b/src/utils/config.ts index f5a4dff0d..dd620dd3a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -1,4 +1,4 @@ -import is from '@sindresorhus/is'; +import { isNonEmptyString, isString } from '@sindresorhus/is'; import escapeStringRegexp from 'escape-string-regexp'; import { getArch, getDistro, readFile } from '../util'; import { BinaryBuilderConfig, ConfigFile, sumType } from './types'; @@ -17,7 +17,7 @@ function checkArgs( groups: Record, ): void { for (const key of keys) { - if (!is.string(cfg[key]) && is.nonEmptyString(groups[key])) { + if (!isString(cfg[key]) && isNonEmptyString(groups[key])) { cfg[key] = groups[key] as never; } } @@ -46,10 +46,10 @@ export function getBinaryName( const arch = getArch(); const ext = sum ? `.${sumType}` : ''; let image = `${cfg.image}-${version}`; - if (is.nonEmptyString(distro)) { + if (isNonEmptyString(distro)) { image += `-${distro}`; } - if (is.nonEmptyString(arch)) { + if (isNonEmptyString(arch)) { image += `-${arch}`; } return `${image}.tar.xz${ext}`; diff --git a/src/utils/docker.ts b/src/utils/docker.ts index 51ae10e4f..487e671c2 100644 --- a/src/utils/docker.ts +++ b/src/utils/docker.ts @@ -1,5 +1,5 @@ import { setTimeout } from 'node:timers/promises'; -import is from '@sindresorhus/is'; +import { isNonEmptyArray, isString } from '@sindresorhus/is'; import chalk from 'chalk'; import { dockerBuildx } from './docker/common'; import log from './logger'; @@ -46,7 +46,7 @@ export async function build({ }: BuildOptions): Promise { const args = ['build']; - if (is.nonEmptyArray(buildArgs)) { + if (isNonEmptyArray(buildArgs)) { args.push(...buildArgs.map((b) => `--build-arg=${b}`)); } @@ -61,14 +61,14 @@ export async function build({ } } - if (is.string(cache)) { + if (isString(cache)) { const cachePrefix = cache.split('/')[0]?.match(/[.:]/) ? '' : `${imagePrefix}/`; const cacheImage = `${cachePrefix}${cache}:${image.replace(/\//g, '-')}`; args.push(`--cache-from=${cacheImage}-${tag}`); - if (is.nonEmptyArray(cacheFromTags)) { + if (isNonEmptyArray(cacheFromTags)) { for (const ctag of cacheFromTags) { args.push(`--cache-from=${cacheImage}-${ctag}`); } @@ -78,7 +78,7 @@ export async function build({ args.push( `--cache-to=type=registry,ref=${cacheImage}-${tag},mode=max,ignore-error=true`, ); - if (is.nonEmptyArray(cacheToTags)) { + if (isNonEmptyArray(cacheToTags)) { for (const ctag of cacheToTags) { args.push( `--cache-to=type=registry,ref=${cacheImage}-${ctag},mode=max,ignore-error=true`,