Skip to content

Commit

Permalink
fix: use max version instead of latest for package update check
Browse files Browse the repository at this point in the history
Signed-off-by: Jakob Steiner <jakob.steiner@glasskube.eu>
  • Loading branch information
kosmoz committed Jun 5, 2024
1 parent 0c81622 commit 1a9ec07
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/commands/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {getLatestRelease} from '../../datasources/github-release/index.js';
import {
copyUnmanagedFiles,
createNewManifestVersion,
getLatestManifest,
getLatestVersion,
getMaxVersion,
getMaxVersionManifest,
updateHelmManifest,
} from '../../manifest.js';
import {ManifestUrl} from '../../models/manifest-url.js';
Expand Down Expand Up @@ -42,10 +42,10 @@ export default class Package extends Command {
public async run(): Promise<void> {

Check warning on line 42 in src/commands/package/index.ts

View workflow job for this annotation

GitHub Actions / build

Async method 'run' has a complexity of 23. Maximum allowed is 20
const {flags} = await this.parse(Package);
const packagePaths = this.paths.package(flags.name);
const packageManifest = await getLatestManifest(packagePaths);
const packageManifest = await getMaxVersionManifest(packagePaths);

let newPackageManifestAvailable = false;
const currentAppVersion = await getLatestVersion(packagePaths);
const currentAppVersion = await getMaxVersion(packagePaths);
let newAppVersion = currentAppVersion;

if (packageManifest.helm) {
Expand Down
27 changes: 22 additions & 5 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {SemVer} from 'semver';
import * as YAML from 'yaml';

import {getPackageVersions} from './package.js';
import {PackagePaths, PackageVersionPaths} from './paths.js';
import {ManifestYaml, PackagePaths, PackageVersionPaths} from './paths.js';
import {ArtifactHubPackage, PackageManifest} from './types/types.js';
import {createDir, getFilesIn, parseYaml, read, write} from './utils/io.js';

Expand Down Expand Up @@ -59,15 +59,32 @@ export async function updateLatestVersion(paths: PackagePaths): Promise<boolean>
return false;
}

export async function getLatestVersion(paths: PackagePaths) {
export async function getLatestVersion(paths: PackagePaths): Promise<SemVer> {
const packageVersions = await getPackageVersions(paths);
return new SemVer(packageVersions.latestVersion);
}

export async function getMaxVersion(paths: PackagePaths): Promise<SemVer> {
const versions = (await getPackageVersions(paths)).versions.map(it => new SemVer(it.version));
versions.sort((a, b) => a.compare(b));
const maxVersion = versions.at(-1);
if (maxVersion) {
return maxVersion;
}

throw new Error('versions must not be empty');
}

export async function getManifest(paths: ManifestYaml) {
return parseYaml<PackageManifest>(await read(paths.packageYaml()));
}

export async function getLatestManifest(paths: PackagePaths) {
const latestVersion = await getLatestVersion(paths);
const stringContent = await read(paths.version(latestVersion.raw).packageYaml());
return parseYaml<PackageManifest>(stringContent);
return getManifest(paths.version((await getLatestVersion(paths)).raw));
}

export async function getMaxVersionManifest(paths: PackagePaths) {
return getManifest(paths.version((await getMaxVersion(paths)).raw));
}

export function updateHelmManifest(packageData: PackageManifest, artifactHubData: ArtifactHubPackage) {
Expand Down
4 changes: 2 additions & 2 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'node:path';
type StringSupplier = () => string;
type DirName = {readonly dirName: StringSupplier};
type IndexYaml = {readonly indexYaml: StringSupplier};
type VersionsYaml = {readonly versionsYaml: StringSupplier};
type ManifestYaml = {readonly packageYaml: StringSupplier};
export type VersionsYaml = {readonly versionsYaml: StringSupplier};
export type ManifestYaml = {readonly packageYaml: StringSupplier};
export type PackageVersionPaths = DirName & ManifestYaml;
type WithPackageVersion = {readonly version: (version: string) => PackageVersionPaths};
export type PackagePaths = DirName & ManifestYaml & VersionsYaml & WithPackageVersion;
Expand Down

0 comments on commit 1a9ec07

Please sign in to comment.