mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Fix tools.getLatestVersion
This commit is contained in:
parent
0a601ebeee
commit
1db2ec93f3
@ -42,12 +42,14 @@ jest
|
|||||||
.spyOn(utils, 'fetch')
|
.spyOn(utils, 'fetch')
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
async (url: string, token?: string): Promise<Record<string, string>> => {
|
async (url: string, token?: string): Promise<Record<string, string>> => {
|
||||||
if (url.includes('atom') && !url.includes('no-release')) {
|
if (url.includes('atom') && !url.includes('no-')) {
|
||||||
return {
|
return {
|
||||||
data: '"releases/tag/1.2.3", "releases/tag/3.2.1", "releases/tag/2.3.1"'
|
data: '"releases/tag/1.2.3", "releases/tag/3.2.1", "releases/tag/2.3.1"'
|
||||||
};
|
};
|
||||||
|
} else if (url.includes('no-data')) {
|
||||||
|
return {};
|
||||||
} else if (url.includes('no-release')) {
|
} else if (url.includes('no-release')) {
|
||||||
return {data: ''};
|
return {data: 'no-release'};
|
||||||
} else if (!token || token === 'valid_token') {
|
} else if (!token || token === 'valid_token') {
|
||||||
return {data: `[{"ref": "refs/tags/1.2.3", "url": "${url}"}]`};
|
return {data: `[{"ref": "refs/tags/1.2.3", "url": "${url}"}]`};
|
||||||
} else if (token === 'beta_token') {
|
} else if (token === 'beta_token') {
|
||||||
@ -77,6 +79,7 @@ describe('Tools tests', () => {
|
|||||||
it.each`
|
it.each`
|
||||||
tool | fetch_latest | version
|
tool | fetch_latest | version
|
||||||
${'tool'} | ${'true'} | ${'3.2.1'}
|
${'tool'} | ${'true'} | ${'3.2.1'}
|
||||||
|
${'tool-no-data'} | ${'true'} | ${'latest'}
|
||||||
${'tool-no-release'} | ${'true'} | ${'latest'}
|
${'tool-no-release'} | ${'true'} | ${'latest'}
|
||||||
${'tool'} | ${'false'} | ${'latest'}
|
${'tool'} | ${'false'} | ${'latest'}
|
||||||
`(
|
`(
|
||||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -548,6 +548,7 @@ async function getLatestVersion(data) {
|
|||||||
return 'latest';
|
return 'latest';
|
||||||
}
|
}
|
||||||
const resp = await utils.fetch(`${data['github']}/${data['repository']}/releases.atom`);
|
const resp = await utils.fetch(`${data['github']}/${data['repository']}/releases.atom`);
|
||||||
|
if (resp['data']) {
|
||||||
const releases = [
|
const releases = [
|
||||||
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
|
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
|
||||||
].map(match => match[2]);
|
].map(match => match[2]);
|
||||||
@ -555,6 +556,8 @@ async function getLatestVersion(data) {
|
|||||||
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
|
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
|
||||||
.pop() || 'latest');
|
.pop() || 'latest');
|
||||||
}
|
}
|
||||||
|
return 'latest';
|
||||||
|
}
|
||||||
exports.getLatestVersion = getLatestVersion;
|
exports.getLatestVersion = getLatestVersion;
|
||||||
async function getVersion(version, data) {
|
async function getVersion(version, data) {
|
||||||
const semver_regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
const semver_regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
||||||
|
@ -43,6 +43,7 @@ export async function getLatestVersion(data: RS): Promise<string> {
|
|||||||
const resp: Record<string, string> = await utils.fetch(
|
const resp: Record<string, string> = await utils.fetch(
|
||||||
`${data['github']}/${data['repository']}/releases.atom`
|
`${data['github']}/${data['repository']}/releases.atom`
|
||||||
);
|
);
|
||||||
|
if (resp['data']) {
|
||||||
const releases: string[] = [
|
const releases: string[] = [
|
||||||
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
|
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
|
||||||
].map(match => match[2]);
|
].map(match => match[2]);
|
||||||
@ -55,6 +56,8 @@ export async function getLatestVersion(data: RS): Promise<string> {
|
|||||||
.pop() || 'latest'
|
.pop() || 'latest'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return 'latest';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get tool version
|
* Function to get tool version
|
||||||
|
Loading…
Reference in New Issue
Block a user