Skip to content

Commit 5b293a1

Browse files
committed
fix: add validation of api-processor version for previous and current package versions when building changelog
1 parent 5c6cb18 commit 5b293a1

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

src/builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { version as apiProcessorVersion } from '../package.json'
1718
import {
1819
BuildConfig,
1920
BuildConfigBase,
@@ -650,6 +651,7 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
650651
version: this.config.version,
651652
revision: 0,
652653
operationTypes: this.operationsTypes,
654+
apiProcessorVersion: apiProcessorVersion,
653655
}
654656
}
655657

src/components/compare/compare.operations.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
removeObjectDuplicates,
4141
} from '../../utils'
4242
import { asyncDebugPerformance, DebugPerformanceContext, syncDebugPerformance } from '../../utils/logs'
43+
import { validateApiProcessorVersion } from '../../validators'
4344

4445
export async function compareVersionsOperations(
4546
prev: VersionParams,
@@ -52,9 +53,13 @@ export async function compareVersionsOperations(
5253

5354
const { versionResolver } = ctx
5455

55-
// resolve all version with operation hashes
56-
const prevVersionData = prev && (await versionResolver(...prev) ?? { version: prev?.[0], packageId: prev?.[1] })
57-
const currVersionData = curr && (await versionResolver(...curr) ?? { version: curr?.[0], packageId: curr?.[1] })
56+
// resolve both versions
57+
const prevVersionData = prev && await versionResolver(...prev)
58+
const currVersionData = curr && await versionResolver(...curr)
59+
60+
// validate api-processor version compatibility
61+
validateApiProcessorVersion(prevVersionData, 'Can\'t build the changelog if previous version was built using an outdated api-processor.')
62+
validateApiProcessorVersion(currVersionData, 'Can\'t build the changelog if current version was built using an outdated api-processor.')
5863

5964
// compare operations of each type
6065
for (const apiType of getUniqueApiTypesFromVersions(prevVersionData, currVersionData)) {

src/types/external/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type ResolvedVersion = {
2828
previousVersionPackageId?: string
2929
operationTypes?: OperationTypes[]
3030
version: string
31+
apiProcessorVersion: string
3132

3233
// other params (not used in builder logic)
3334
[key: string]: unknown

src/validators.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { BuildConfig } from './types'
17+
import { BuildConfig, VersionCache } from './types'
1818
import { assert } from './utils'
1919
import { BUILD_TYPE } from './consts'
20+
import { version as apiProcessorVersion } from '../package.json'
2021

2122
export function validateConfig(config: BuildConfig): void {
2223
assert(config.packageId, 'builder config: packageId required')
@@ -28,3 +29,15 @@ export function validateConfig(config: BuildConfig): void {
2829
throw new Error('Incorrect config. Got no files and refs')
2930
}
3031
}
32+
33+
export function validateApiProcessorVersion(resolvedVersion: VersionCache | null, errorPrefix?: string): void {
34+
35+
if (!resolvedVersion?.apiProcessorVersion) {
36+
return
37+
}
38+
39+
if (resolvedVersion.apiProcessorVersion !== apiProcessorVersion) {
40+
errorPrefix = errorPrefix ? `${errorPrefix} ` : ''
41+
throw new Error(`${errorPrefix}Expected api-processor version: ${apiProcessorVersion}, got ${resolvedVersion.apiProcessorVersion} for package ${resolvedVersion.packageId} version ${resolvedVersion.version}`)
42+
}
43+
}

test/helpers/registry/apihub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class ApihubRegistry implements IRegistry {
164164
const encodedPackageKey = encodeURIComponent(packageId)
165165
const encodedVersionKey = encodeURIComponent(versionId)
166166

167-
const { data } = await this.axios.get(`/api/v2/packages/${encodedPackageKey}/versions/${encodedVersionKey}?includeOperations=${includeOperations}`)
167+
const { data } = await this.axios.get(`/api/v3/packages/${encodedPackageKey}/versions/${encodedVersionKey}?includeOperations=${includeOperations}`)
168168
return data
169169
}
170170

test/helpers/registry/local.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { calculateTotalChangeSummary } from '../../../src/components/compare'
8686
import { toVersionsComparisonDto } from '../../../src/utils/transformToDto'
8787
import path from 'path'
8888
import { ResolvedPackage } from '../../../src/types/external/package'
89+
import { version as apiProcessorVersion } from '../../../package.json'
8990

9091
const VERSIONS_PATH = 'test/versions'
9192
const DEFAULT_PROJECTS_PATH = 'test/projects'
@@ -175,6 +176,7 @@ export class LocalRegistry implements IRegistry {
175176
versionLabels: [],
176177
revision: 0,
177178
operationTypes: apiTypes.map(apiType => ({ apiType: apiType, changesSummary: getChangesSummary(apiType) })),
179+
apiProcessorVersion: apiProcessorVersion,
178180
}
179181
}
180182

0 commit comments

Comments
 (0)