-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from NordicSemiconductor/feat/artifactory/ve…
…rsioned_sources.json Add versioning to sources.json
- Loading branch information
Showing
13 changed files
with
7,118 additions
and
8,214 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause | ||
*/ | ||
|
||
import { existsSync } from 'fs'; | ||
|
||
import { readSchemedJsonFile, writeSchemedJsonFile } from '../../fileUtil'; | ||
import { migrateSourcesJson, oldSourcesJsonPath } from './migrateSourcesJson'; | ||
|
||
jest.mock('fs'); | ||
jest.mock('../../fileUtil'); | ||
|
||
describe('migrating sources.json', () => { | ||
const mockedExistsSync = jest.mocked(existsSync); | ||
const mockedReadSchemedJsonFile = jest.mocked(readSchemedJsonFile); | ||
const mockedWriteSchemedJsonFile = jest.mocked(writeSchemedJsonFile); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should migrate sources.json to sources-versioned.json', () => { | ||
const oldSourceJsonContent = { | ||
source1: 'http://source1.com/apps.json', | ||
source2: 'http://source2.com/source.json', | ||
}; | ||
const newSourceVersionedJsonContent = { | ||
v1: [ | ||
{ name: 'source1', url: 'http://source1.com/source.json' }, | ||
{ name: 'source2', url: 'http://source2.com/source.json' }, | ||
], | ||
}; | ||
|
||
// Arrange | ||
mockedExistsSync.mockImplementation( | ||
path => path === oldSourcesJsonPath() | ||
); | ||
mockedReadSchemedJsonFile.mockReturnValue(oldSourceJsonContent); | ||
|
||
// Act | ||
migrateSourcesJson(); | ||
|
||
// Assert | ||
expect(mockedWriteSchemedJsonFile).toBeCalledWith( | ||
expect.anything(), | ||
expect.anything(), | ||
newSourceVersionedJsonContent | ||
); | ||
}); | ||
|
||
it('should do nothing if sources.json does not exist', () => { | ||
mockedExistsSync.mockReturnValue(false); | ||
|
||
migrateSourcesJson(); | ||
|
||
expect(mockedReadSchemedJsonFile).not.toBeCalled(); | ||
}); | ||
|
||
it('should do nothing if sources-versioned.json already exists', () => { | ||
mockedExistsSync.mockReturnValue(true); | ||
|
||
migrateSourcesJson(); | ||
|
||
expect(mockedReadSchemedJsonFile).not.toBeCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2015 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause | ||
*/ | ||
|
||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { z } from 'zod'; | ||
|
||
import { getAppsExternalDir } from '../../config'; | ||
import { readSchemedJsonFile } from '../../fileUtil'; | ||
import { sourcesVersionedJsonPath, writeSourcesFile } from '../sources'; | ||
|
||
export const oldSourcesJsonPath = () => | ||
path.join(getAppsExternalDir(), 'sources.json'); | ||
|
||
const oldSourcesJsonSchema = z.record(z.string(), z.string().url()); | ||
|
||
export const migrateSourcesJson = () => { | ||
if ( | ||
!fs.existsSync(oldSourcesJsonPath()) || | ||
fs.existsSync(sourcesVersionedJsonPath()) | ||
) { | ||
return; | ||
} | ||
|
||
const oldSourcesJson = readSchemedJsonFile( | ||
oldSourcesJsonPath(), | ||
oldSourcesJsonSchema | ||
); | ||
const migratedSources = Object.entries(oldSourcesJson).map( | ||
([name, url]) => ({ | ||
name, | ||
url: url.replace(/apps\.json$/, 'source.json'), | ||
}) | ||
); | ||
|
||
writeSourcesFile(migratedSources); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.