Fix race condition in get_file

This commit is contained in:
Shivam Mathur 2019-09-06 18:00:08 +05:30
parent 202f1bbec1
commit 2f94ea1a79
9 changed files with 94 additions and 114 deletions

View File

@ -18,14 +18,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec/lib/exec"); const exec_1 = require("@actions/exec/lib/exec");
var https = require('https'); const https = require('https');
const fs = require('fs'); const fs = require('fs');
function get_file(filename) { function get_file(filename) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let github_path = 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/'; let github_path = 'https://raw.githubusercontent.com/shivammathur/setup-php/master/src/';
const file = fs.createWriteStream(filename); const file = fs.createWriteStream(filename);
const request = https.get(github_path + filename, function (response) { file.on('open', function (fd) {
response.pipe(file); https.get(github_path + filename, function (response) {
response
.on('data', function (chunk) {
file.write(chunk);
})
.on('end', function () {
file.end();
});
});
}); });
}); });
} }

View File

@ -1,58 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec/lib/exec");
var https = require('https');
const fs = require('fs');
function get_file(filename) {
let github_path = 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/';
const file = fs.createWriteStream(filename);
const request = https.get(github_path + filename, function (response) {
response.pipe(file);
});
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('php-version', { required: true });
console.log('Input: ' + version);
let os_version = process.platform;
if (os_version == 'darwin') {
get_file('darwin.sh');
yield exec_1.exec('sudo chmod a+x darwin.sh');
yield exec_1.exec('./darwin.sh ' + version);
}
else if (os_version == 'win32') {
get_file('windows.ps1');
yield exec_1.exec('powershell windows.ps1 -version ' + version);
}
else if (os_version == 'linux') {
get_file('linux.sh');
yield exec_1.exec('sudo chmod a+x linux.sh');
yield exec_1.exec('./linux.sh ' + version);
}
}
catch (err) {
core.setFailed(err.message);
}
});
}
run().then(() => {
console.log('done');
});

View File

@ -1,4 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let v = process.env['php-version'];
console.log(v);

View File

@ -1,32 +1,37 @@
{ {
"_from": "@types/jest-diff@*", "_args": [
[
"@types/jest-diff@20.0.1",
"E:\\python\\setup-php"
]
],
"_development": true,
"_from": "@types/jest-diff@20.0.1",
"_id": "@types/jest-diff@20.0.1", "_id": "@types/jest-diff@20.0.1",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==", "_integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==",
"_location": "/@types/jest-diff", "_location": "/@types/jest-diff",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "range", "type": "version",
"registry": true, "registry": true,
"raw": "@types/jest-diff@*", "raw": "@types/jest-diff@20.0.1",
"name": "@types/jest-diff", "name": "@types/jest-diff",
"escapedName": "@types%2fjest-diff", "escapedName": "@types%2fjest-diff",
"scope": "@types", "scope": "@types",
"rawSpec": "*", "rawSpec": "20.0.1",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "*" "fetchSpec": "20.0.1"
}, },
"_requiredBy": [ "_requiredBy": [
"/@types/jest" "/@types/jest"
], ],
"_resolved": "https://registry.npmjs.org/@types/jest-diff/-/jest-diff-20.0.1.tgz", "_resolved": "https://registry.npmjs.org/@types/jest-diff/-/jest-diff-20.0.1.tgz",
"_shasum": "35cc15b9c4f30a18ef21852e255fdb02f6d59b89", "_spec": "20.0.1",
"_spec": "@types/jest-diff@*", "_where": "E:\\python\\setup-php",
"_where": "E:\\python\\setup-php\\node_modules\\@types\\jest",
"bugs": { "bugs": {
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues" "url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
}, },
"bundleDependencies": false,
"contributors": [ "contributors": [
{ {
"name": "Alex Coles", "name": "Alex Coles",
@ -34,7 +39,6 @@
} }
], ],
"dependencies": {}, "dependencies": {},
"deprecated": false,
"description": "TypeScript definitions for jest-diff", "description": "TypeScript definitions for jest-diff",
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme", "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme",
"license": "MIT", "license": "MIT",

View File

@ -1,32 +1,37 @@
{ {
"_from": "@types/jest@^24.0.13", "_args": [
[
"@types/jest@24.0.18",
"E:\\python\\setup-php"
]
],
"_development": true,
"_from": "@types/jest@24.0.18",
"_id": "@types/jest@24.0.18", "_id": "@types/jest@24.0.18",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha512-jcDDXdjTcrQzdN06+TSVsPPqxvsZA/5QkYfIZlq1JMw7FdP5AZylbOc+6B/cuDurctRe+MziUMtQ3xQdrbjqyQ==", "_integrity": "sha512-jcDDXdjTcrQzdN06+TSVsPPqxvsZA/5QkYfIZlq1JMw7FdP5AZylbOc+6B/cuDurctRe+MziUMtQ3xQdrbjqyQ==",
"_location": "/@types/jest", "_location": "/@types/jest",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "range", "type": "version",
"registry": true, "registry": true,
"raw": "@types/jest@^24.0.13", "raw": "@types/jest@24.0.18",
"name": "@types/jest", "name": "@types/jest",
"escapedName": "@types%2fjest", "escapedName": "@types%2fjest",
"scope": "@types", "scope": "@types",
"rawSpec": "^24.0.13", "rawSpec": "24.0.18",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "^24.0.13" "fetchSpec": "24.0.18"
}, },
"_requiredBy": [ "_requiredBy": [
"#DEV:/" "#DEV:/"
], ],
"_resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.18.tgz", "_resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.18.tgz",
"_shasum": "9c7858d450c59e2164a8a9df0905fc5091944498", "_spec": "24.0.18",
"_spec": "@types/jest@^24.0.13",
"_where": "E:\\python\\setup-php", "_where": "E:\\python\\setup-php",
"bugs": { "bugs": {
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues" "url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
}, },
"bundleDependencies": false,
"contributors": [ "contributors": [
{ {
"name": "Asana", "name": "Asana",
@ -120,7 +125,6 @@
"dependencies": { "dependencies": {
"@types/jest-diff": "*" "@types/jest-diff": "*"
}, },
"deprecated": false,
"description": "TypeScript definitions for Jest", "description": "TypeScript definitions for Jest",
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme", "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme",
"license": "MIT", "license": "MIT",

22
node_modules/fs/package.json generated vendored
View File

@ -1,34 +1,36 @@
{ {
"_from": "fs", "_args": [
[
"fs@0.0.1-security",
"E:\\python\\setup-php"
]
],
"_from": "fs@0.0.1-security",
"_id": "fs@0.0.1-security", "_id": "fs@0.0.1-security",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=", "_integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=",
"_location": "/fs", "_location": "/fs",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "tag", "type": "version",
"registry": true, "registry": true,
"raw": "fs", "raw": "fs@0.0.1-security",
"name": "fs", "name": "fs",
"escapedName": "fs", "escapedName": "fs",
"rawSpec": "", "rawSpec": "0.0.1-security",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "latest" "fetchSpec": "0.0.1-security"
}, },
"_requiredBy": [ "_requiredBy": [
"#USER",
"/" "/"
], ],
"_resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", "_resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"_shasum": "8a7bd37186b6dddf3813f23858b57ecaaf5e41d4", "_spec": "0.0.1-security",
"_spec": "fs",
"_where": "E:\\python\\setup-php", "_where": "E:\\python\\setup-php",
"author": "", "author": "",
"bugs": { "bugs": {
"url": "https://github.com/npm/security-holder/issues" "url": "https://github.com/npm/security-holder/issues"
}, },
"bundleDependencies": false,
"deprecated": false,
"description": "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.", "description": "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.",
"homepage": "https://github.com/npm/security-holder#readme", "homepage": "https://github.com/npm/security-holder#readme",
"keywords": [], "keywords": [],

22
node_modules/https/package.json generated vendored
View File

@ -1,35 +1,37 @@
{ {
"_from": "https", "_args": [
[
"https@1.0.0",
"E:\\python\\setup-php"
]
],
"_from": "https@1.0.0",
"_id": "https@1.0.0", "_id": "https@1.0.0",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha1-PDfHrhqO65ZpBKKtHpdaGUt+06Q=", "_integrity": "sha1-PDfHrhqO65ZpBKKtHpdaGUt+06Q=",
"_location": "/https", "_location": "/https",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "tag", "type": "version",
"registry": true, "registry": true,
"raw": "https", "raw": "https@1.0.0",
"name": "https", "name": "https",
"escapedName": "https", "escapedName": "https",
"rawSpec": "", "rawSpec": "1.0.0",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "latest" "fetchSpec": "1.0.0"
}, },
"_requiredBy": [ "_requiredBy": [
"#USER",
"/" "/"
], ],
"_resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz", "_resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
"_shasum": "3c37c7ae1a8eeb966904a2ad1e975a194b7ed3a4", "_spec": "1.0.0",
"_spec": "https",
"_where": "E:\\python\\setup-php", "_where": "E:\\python\\setup-php",
"author": { "author": {
"name": "hardus van der berg", "name": "hardus van der berg",
"email": "hardus@sunfork.com", "email": "hardus@sunfork.com",
"url": "http://www.sunfork.com" "url": "http://www.sunfork.com"
}, },
"bundleDependencies": false,
"deprecated": false,
"description": "https mediation", "description": "https mediation",
"keywords": [ "keywords": [
"https", "https",

28
package-lock.json generated
View File

@ -1761,12 +1761,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -1781,17 +1783,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -1908,7 +1913,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -1920,6 +1926,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -1934,6 +1941,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -1941,12 +1949,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -1965,6 +1975,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -2045,7 +2056,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -2057,6 +2069,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -2178,6 +2191,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",

View File

@ -7,8 +7,16 @@ async function get_file(filename: string) {
let github_path: string = let github_path: string =
'https://raw.githubusercontent.com/shivammathur/setup-php/master/src/'; 'https://raw.githubusercontent.com/shivammathur/setup-php/master/src/';
const file: any = fs.createWriteStream(filename); const file: any = fs.createWriteStream(filename);
file.on('open', function(fd: any) {
https.get(github_path + filename, function(response: any) { https.get(github_path + filename, function(response: any) {
response.pipe(file); response
.on('data', function(chunk: any) {
file.write(chunk);
})
.on('end', function() {
file.end();
});
});
}); });
} }