Skip to content

Commit

Permalink
feat(github-releases): use prerelease metadata in filtering (#7567)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Oct 27, 2020
1 parent 9d71096 commit 40ae438
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/datasource/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface Release {
downloadUrl?: string;
gitRef?: string;
isDeprecated?: boolean;

isStable?: boolean;
releaseTimestamp?: any;
version: string;
newDigest?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Object {
"releaseTimestamp": "2020-03-09T10:00:00Z",
"version": "v1.1.0",
},
Object {
"gitRef": "2.0.0",
"isStable": false,
"releaseTimestamp": "2020-04-09T10:00:00Z",
"version": "2.0.0",
},
],
"sourceUrl": "https://github.com/some/dep",
}
Expand Down
10 changes: 9 additions & 1 deletion lib/datasource/github-releases/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@ describe('datasource/github-releases', () => {
{ tag_name: 'v', published_at: '2020-03-09T12:00:00Z' },
{ tag_name: '1.0.0', published_at: '2020-03-09T11:00:00Z' },
{ tag_name: 'v1.1.0', published_at: '2020-03-09T10:00:00Z' },
{
tag_name: '2.0.0',
published_at: '2020-04-09T10:00:00Z',
prerelease: true,
},
]);

const res = await getPkgReleases({
datasource,
depName: 'some/dep',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(2);
expect(res.releases).toHaveLength(3);
expect(
res.releases.find((release) => release.version === 'v1.1.0')
).toBeDefined();
expect(
res.releases.find((release) => release.version === '2.0.0').isStable
).toBe(false);
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
Expand Down
14 changes: 9 additions & 5 deletions lib/datasource/github-releases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const http = new GithubHttp();
type GithubRelease = {
tag_name: string;
published_at: string;
prerelease: boolean;
};

/**
Expand Down Expand Up @@ -43,11 +44,14 @@ export async function getReleases({
sourceUrl: 'https://github.com/' + repo,
releases: null,
};
dependency.releases = githubReleases.map(({ tag_name, published_at }) => ({
version: tag_name,
gitRef: tag_name,
releaseTimestamp: published_at,
}));
dependency.releases = githubReleases.map(
({ tag_name, published_at, prerelease }) => ({
version: tag_name,
gitRef: tag_name,
releaseTimestamp: published_at,
isStable: prerelease ? false : undefined,
})
);
const cacheMinutes = 10;
await packageCache.set(cacheNamespace, repo, dependency, cacheMinutes);
return dependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,20 @@ Array [
]
`;
exports[`workers/repository/process/lookup .lookupUpdates() should ignore unstable versions from datasource 1`] = `
Array [
Object {
"fromVersion": "1.4.4",
"isSingleVersion": true,
"newMajor": 2,
"newMinor": 0,
"newValue": "2.0.0",
"toVersion": "2.0.0",
"updateType": "major",
},
]
`;
exports[`workers/repository/process/lookup .lookupUpdates() should jump unstable versions if followTag 1`] = `
Array [
Object {
Expand Down
5 changes: 5 additions & 0 deletions lib/workers/repository/process/lookup/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export function filterVersions(
if (!versioning.isStable(version)) {
return false;
}
// Check if the datasource returned isStable = false
const release = releases.find((r) => r.version === version);
if (release?.isStable === false) {
return false;
}
return true;
}
versioning = allVersioning.get(config.versioning);
Expand Down
23 changes: 23 additions & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as datasourceDocker from '../../../../datasource/docker';
import { id as datasourceDockerId } from '../../../../datasource/docker';
import * as datasourceGitSubmodules from '../../../../datasource/git-submodules';
import { id as datasourceGitSubmodulesId } from '../../../../datasource/git-submodules';
import * as datasourceGithubReleases from '../../../../datasource/github-releases';
import { id as datasourceGithubTagsId } from '../../../../datasource/github-tags';
import { id as datasourceNpmId } from '../../../../datasource/npm';
import { id as datasourcePackagistId } from '../../../../datasource/packagist';
Expand All @@ -25,12 +26,14 @@ import * as lookup from '.';

jest.mock('../../../../datasource/docker');
jest.mock('../../../../datasource/git-submodules');
jest.mock('../../../../datasource/github-releases');

qJson.latestVersion = '1.4.1';

const docker = mocked(datasourceDocker) as any;
docker.defaultRegistryUrls = ['https://index.docker.io'];
const gitSubmodules = mocked(datasourceGitSubmodules);
const githubReleases = mocked(datasourceGithubReleases);

let config: lookup.LookupUpdateConfig;

Expand Down Expand Up @@ -639,6 +642,26 @@ describe('workers/repository/process/lookup', () => {
nock('https://registry.npmjs.org').get('/vue').reply(200, vueJson);
expect((await lookup.lookupUpdates(config)).updates).toHaveLength(0);
});
it('should ignore unstable versions from datasource', async () => {
config.currentValue = '1.4.4';
config.depName = 'some/action';
config.datasource = datasourceGithubReleases.id;
githubReleases.getReleases.mockResolvedValueOnce({
releases: [
{
version: '1.4.4',
},
{
version: '2.0.0',
},
{
version: '2.1.0',
isStable: false,
},
],
});
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('should allow unstable versions if the ignoreUnstable=false', async () => {
config.currentValue = '2.5.16';
config.ignoreUnstable = false;
Expand Down

0 comments on commit 40ae438

Please sign in to comment.