mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
feat: use version service for docs archive switcher (#30675)
This commit is contained in:
parent
199723261c
commit
0344c61e4c
5 changed files with 6 additions and 399 deletions
|
|
@ -1,23 +1,10 @@
|
|||
import semver from 'semver';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
resolveArchivedVersions,
|
||||
ArchivedVersion,
|
||||
getMobileBuild,
|
||||
getNewVersion,
|
||||
ReleaseError,
|
||||
} from './release';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getMobileBuild, getNewVersion, ReleaseError } from './release';
|
||||
|
||||
const mobileBuild = (version: string) =>
|
||||
getMobileBuild(semver.parse(version) as semver.SemVer);
|
||||
|
||||
const archived = (label: string): ArchivedVersion => ({
|
||||
label,
|
||||
url: `https://docs.${label}.archive.immich.app`,
|
||||
});
|
||||
|
||||
const labels = (versions: ArchivedVersion[]) => versions.map((v) => v.label);
|
||||
|
||||
describe(getNewVersion.name, () => {
|
||||
describe('transitions', () => {
|
||||
const valid = [
|
||||
|
|
@ -82,67 +69,6 @@ describe(getNewVersion.name, () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe(resolveArchivedVersions.name, () => {
|
||||
beforeEach(() => {
|
||||
// silence the "Removed ..." progress logging
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it('should prepend the new version to the front', () => {
|
||||
const result = resolveArchivedVersions([archived('v2.9.0')], '3.0.0');
|
||||
|
||||
expect(result[0]).toEqual({
|
||||
label: 'v3.0.0',
|
||||
url: 'https://docs.v3.0.0.archive.immich.app',
|
||||
});
|
||||
expect(labels(result)).toEqual(['v3.0.0', 'v2.9.0']);
|
||||
});
|
||||
|
||||
it('should handle an empty list', () => {
|
||||
expect(labels(resolveArchivedVersions([], '3.0.0'))).toEqual(['v3.0.0']);
|
||||
});
|
||||
|
||||
it('should drop older patch releases of the new version minor', () => {
|
||||
const versions = ['v3.0.4', 'v3.0.3', 'v3.0.2'].map(archived);
|
||||
|
||||
expect(labels(resolveArchivedVersions(versions, '3.0.5'))).toEqual([
|
||||
'v3.0.5',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should keep the latest patch of each older minor', () => {
|
||||
const versions = ['v3.1.2', 'v3.1.1', 'v3.0.9', 'v2.0.0'].map(archived);
|
||||
|
||||
expect(labels(resolveArchivedVersions(versions, '3.2.0'))).toEqual([
|
||||
'v3.2.0',
|
||||
'v3.1.2',
|
||||
'v3.0.9',
|
||||
'v2.0.0',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should keep an older minor when bumping a patch', () => {
|
||||
const versions = ['v3.0.4', 'v3.0.3', 'v2.9.1', 'v2.9.0', 'v1.5.0'].map(
|
||||
archived,
|
||||
);
|
||||
|
||||
expect(labels(resolveArchivedVersions(versions, '3.0.5'))).toEqual([
|
||||
'v3.0.5',
|
||||
'v2.9.1',
|
||||
'v1.5.0',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should replace a prerelease with its release', () => {
|
||||
const versions = ['v3.0.0-rc.2', 'v3.0.0-rc.1', 'v2.9.0'].map(archived);
|
||||
|
||||
expect(labels(resolveArchivedVersions(versions, '3.0.0'))).toEqual([
|
||||
'v3.0.0',
|
||||
'v2.9.0',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe(getMobileBuild.name, () => {
|
||||
it('should encode the version', () => {
|
||||
expect(mobileBuild('3.1.0')).toBe(3_010_099);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ const Files = {
|
|||
Docs: {
|
||||
Env: join(root, 'docs/docs/install/environment-variables.md'),
|
||||
Upgrading: join(root, 'docs/docs/install/upgrading.md'),
|
||||
ArchivedVersions: join(root, 'docs/static/archived-versions.json'),
|
||||
},
|
||||
Mobile: {
|
||||
Pubspec: join(root, 'mobile/pubspec.yaml'),
|
||||
|
|
@ -92,13 +91,6 @@ export const handleRelease = ({ type }: ReleaseOptions) => {
|
|||
pump(Files.Docs.Upgrading, /:v\d+/, `:${major}`);
|
||||
}
|
||||
|
||||
// update archived versions list
|
||||
const archivedFile = new JsonFile<ArchivedVersion[]>(
|
||||
Files.Docs.ArchivedVersions,
|
||||
);
|
||||
const versions = archivedFile.read();
|
||||
archivedFile.write(resolveArchivedVersions(versions, newVersionRaw));
|
||||
|
||||
if (process.env.GITHUB_ENV) {
|
||||
// make available for following steps
|
||||
appendFileSync(
|
||||
|
|
@ -222,50 +214,6 @@ const pump = (path: string, pattern: RegExp, replacement: string) => {
|
|||
file.write(update);
|
||||
};
|
||||
|
||||
export interface ArchivedVersion {
|
||||
label: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export const resolveArchivedVersions = (
|
||||
versions: ArchivedVersion[],
|
||||
nextVersion: string,
|
||||
): ArchivedVersion[] => {
|
||||
const newVersion: ArchivedVersion = {
|
||||
label: `v${nextVersion}`,
|
||||
url: `https://docs.v${nextVersion}.archive.immich.app`,
|
||||
};
|
||||
|
||||
let result = versions;
|
||||
let lastVersion = asVersion(newVersion);
|
||||
for (const item of versions) {
|
||||
const version = asVersion(item);
|
||||
// only keep the latest patch version for each minor release
|
||||
if (
|
||||
lastVersion.major === version.major &&
|
||||
lastVersion.minor === version.minor &&
|
||||
lastVersion.patch >= version.patch
|
||||
) {
|
||||
result = result.filter((item) => item.label !== version.label);
|
||||
console.log(
|
||||
`Removed ${version.label} (replaced with ${lastVersion.label})`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
lastVersion = version;
|
||||
}
|
||||
|
||||
return [newVersion, ...result];
|
||||
};
|
||||
|
||||
const asVersion = (item: ArchivedVersion) => {
|
||||
const { label, url } = item;
|
||||
const [version] = label.substring(1).split('-');
|
||||
const [major, minor, patch] = version.split('.').map(Number);
|
||||
return { major, minor, patch, label, url };
|
||||
};
|
||||
|
||||
const isPrerelease = (version: SemVer) => version.prerelease.length > 0;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue