Add support to specify version in \d.x notation

This commit is contained in:
Shivam Mathur
2021-01-16 11:16:13 +05:30
parent 6972aed899
commit fbc8407035
5 changed files with 95 additions and 18 deletions

View File

@ -1,4 +1,6 @@
import {IncomingMessage} from 'http';
import * as fs from 'fs';
import * as https from 'https';
import * as path from 'path';
import * as core from '@actions/core';
@ -41,15 +43,34 @@ export async function getInput(
}
}
/**
* Function to fetch an URL
*
* @param url
*/
export async function fetch(url: string): Promise<string> {
const fetch_promise: Promise<string> = new Promise(resolve => {
const req = https.get(url, (res: IncomingMessage) => {
res.setEncoding('utf8');
let body = '';
res.on('data', chunk => (body += chunk));
res.on('end', () => resolve(body));
});
req.end();
});
return await fetch_promise;
}
/**
* Function to parse PHP version.
*
* @param version
*/
export async function parseVersion(version: string): Promise<string> {
switch (version) {
case 'latest':
return '8.0';
const manifest = 'https://dl.bintray.com/shivammathur/php/php-versions.json';
switch (true) {
case /latest|\d.x/.test(version):
return JSON.parse(await fetch(manifest))[version];
default:
switch (true) {
case version.length > 1: