forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
41,775 additions
and
0 deletions.
There are no files selected for viewing
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
34,026 changes: 34,026 additions & 0 deletions
34,026
lib/modules/datasource/unity3d/__fixtures__/beta.xml
Large diffs are not rendered by default.
Oops, something went wrong.
3,865 changes: 3,865 additions & 0 deletions
3,865
lib/modules/datasource/unity3d/__fixtures__/lts.xml
Large diffs are not rendered by default.
Oops, something went wrong.
3,694 changes: 3,694 additions & 0 deletions
3,694
lib/modules/datasource/unity3d/__fixtures__/stable.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { getPkgReleases } from '..'; | ||
import { Fixtures } from '../../../../test/fixtures'; | ||
import * as httpMock from '../../../../test/http-mock'; | ||
import { Unity3dDatasource } from '.'; | ||
|
||
const mockRSSFeeds = (streams: { [keys: string]: string }) => { | ||
Object.entries(streams).map(([stream, url]) => { | ||
const content = Fixtures.get(stream + '.xml'); | ||
|
||
const uri = new URL(url); | ||
|
||
httpMock.scope(uri.origin).get(uri.pathname).reply(200, content); | ||
}); | ||
}; | ||
|
||
describe('modules/datasource/unity3d/index', () => { | ||
it('returns stable and lts releases by default', async () => { | ||
const qualifyingStreams = { ...Unity3dDatasource.streams }; | ||
delete qualifyingStreams.beta; | ||
mockRSSFeeds(qualifyingStreams); | ||
const responses = ( | ||
await getPkgReleases({ | ||
datasource: Unity3dDatasource.id, | ||
packageName: 'm_EditorVersion', | ||
}) | ||
)?.releases.map((release) => release.version); | ||
|
||
// check that only letter f is present (final releases) | ||
expect(responses!.every((version) => /[fp]/.test(version))).toBe(true); | ||
// check that no version contains the letter b (beta release) | ||
expect(responses!.every((version) => !/b/.test(version))).toBe(true); | ||
}); | ||
|
||
it('returns hash if requested', async () => { | ||
mockRSSFeeds({ stable: Unity3dDatasource.streams.stable }); | ||
const responsesWithoutHash = (await getPkgReleases({ | ||
datasource: Unity3dDatasource.id, | ||
packageName: 'm_EditorVersionWithRevision', | ||
registryUrls: [Unity3dDatasource.streams.stable], | ||
}))!.releases.map((release) => release.version); | ||
|
||
expect(responsesWithoutHash.length).toBeGreaterThan(0); | ||
expect( | ||
responsesWithoutHash.every((version) => /\(.*\)/.test(version)), | ||
).toBe(true); | ||
}); | ||
|
||
it('returns no hash if not requested', async () => { | ||
mockRSSFeeds({ stable: Unity3dDatasource.streams.stable }); | ||
const responsesWithoutHash = ( | ||
await getPkgReleases({ | ||
datasource: Unity3dDatasource.id, | ||
packageName: 'm_EditorVersion', | ||
registryUrls: [Unity3dDatasource.streams.stable], | ||
}) | ||
)?.releases.map((release) => release.version); | ||
|
||
expect(responsesWithoutHash!.length).toBeGreaterThan(0); | ||
expect( | ||
responsesWithoutHash!.every((version) => !/\(.*\)/.test(version)), | ||
).toBe(true); | ||
}); | ||
|
||
it('returns different versions for each stream', async () => { | ||
mockRSSFeeds(Unity3dDatasource.streams); | ||
const responses: { [keys: string]: string[] } = Object.fromEntries( | ||
await Promise.all( | ||
Object.keys(Unity3dDatasource.streams).map(async (stream) => [ | ||
stream, | ||
( | ||
await getPkgReleases({ | ||
datasource: Unity3dDatasource.id, | ||
packageName: 'm_EditorVersion', | ||
registryUrls: [Unity3dDatasource.streams[stream]], | ||
}) | ||
)?.releases.map((release) => release.version), | ||
]), | ||
), | ||
); | ||
|
||
// none of the items in responses.beta are in responses.stable or responses.lts | ||
expect( | ||
responses.beta.every( | ||
(betaVersion) => | ||
!responses.stable.includes(betaVersion) && | ||
!responses.lts.includes(betaVersion), | ||
), | ||
).toBe(true); | ||
// some items in responses.stable are in responses.lts | ||
expect( | ||
responses.stable.some((stableVersion) => | ||
responses.lts.includes(stableVersion), | ||
), | ||
).toBe(true); | ||
// not all items in responses.stable are in responses.lts | ||
expect( | ||
responses.stable.every((stableVersion) => | ||
responses.lts.includes(stableVersion), | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it('returns only lts and stable by default', async () => { | ||
const qualifyingStreams = { ...Unity3dDatasource.streams }; | ||
delete qualifyingStreams.beta; | ||
mockRSSFeeds(qualifyingStreams); | ||
const responses = (await getPkgReleases({ | ||
datasource: Unity3dDatasource.id, | ||
packageName: 'm_EditorVersionWithRevision', | ||
}))!.releases.map((release) => release.version); | ||
|
||
expect(responses.every((version) => /[fp]/.test(version))).toBe(true); | ||
}); | ||
}); |
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,73 @@ | ||
import { XmlDocument } from 'xmldoc'; | ||
import { cache } from '../../../util/cache/package/decorator'; | ||
import * as Unity3dVersioning from '../../versioning/unity3d'; | ||
import { Datasource } from '../datasource'; | ||
import type { GetReleasesConfig, Release, ReleaseResult } from '../types'; | ||
|
||
export class Unity3dDatasource extends Datasource { | ||
static readonly streams: { [key: string]: string } = { | ||
lts: 'https://unity.com/releases/editor/lts-releases.xml', | ||
stable: 'https://unity.com/releases/editor/releases.xml', | ||
beta: 'https://unity.com/releases/editor/beta/latest.xml', | ||
}; | ||
|
||
static readonly id = 'unity3d'; | ||
|
||
override readonly defaultRegistryUrls = [ | ||
Unity3dDatasource.streams.stable, | ||
Unity3dDatasource.streams.lts, | ||
]; | ||
|
||
override readonly defaultVersioning = Unity3dVersioning.id; | ||
|
||
override readonly registryStrategy = 'merge'; | ||
|
||
constructor() { | ||
super(Unity3dDatasource.id); | ||
} | ||
|
||
getByStream = async ( | ||
registryUrl: string | undefined, | ||
withHash: boolean, | ||
): Promise<ReleaseResult | null> => { | ||
const response = await this.http.get(registryUrl!); | ||
const document = new XmlDocument(response.body); | ||
const releases = document | ||
.childNamed('channel')! | ||
.childrenNamed('item') | ||
.map((itemNode) => { | ||
const versionWithHash = `${itemNode.childNamed('title')?.val} (${itemNode.childNamed('guid')?.val})`; | ||
const versionWithoutHash = itemNode.childNamed('title')?.val; | ||
const release: Release = { | ||
version: withHash ? versionWithHash : versionWithoutHash!, | ||
releaseTimestamp: itemNode.childNamed('pubDate')?.val, | ||
changelogUrl: itemNode.childNamed('link')?.val, | ||
isStable: registryUrl !== Unity3dDatasource.streams.beta, | ||
registryUrl, | ||
}; | ||
return release; | ||
}) | ||
.filter((release): release is Release => !!release); | ||
|
||
return { | ||
releases, | ||
homepage: 'https://unity.com/', | ||
}; | ||
}; | ||
|
||
@cache({ | ||
namespace: `datasource-${Unity3dDatasource.id}`, | ||
key: ({ registryUrl, packageName }: GetReleasesConfig) => | ||
`${registryUrl}:${packageName}`, | ||
ttlMinutes: 24 * 60, | ||
}) | ||
async getReleases({ | ||
packageName, | ||
registryUrl, | ||
}: GetReleasesConfig): Promise<ReleaseResult | null> { | ||
return await this.getByStream( | ||
registryUrl, | ||
packageName === 'm_EditorVersionWithRevision', | ||
); | ||
} | ||
} |
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