Auto-rebuild dist files using Github Actions (#8)

* ci: auto-build the dist files

* Rebuild

* ci: only rebuild on release branches

* ci: support any version branch

Co-authored-by: Automated <github@asdf.kooi.me>
This commit is contained in:
Renée Kooi 2020-03-07 16:05:55 +01:00 committed by GitHub
parent 09b0beda20
commit 23860f7d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 173 additions and 48 deletions

21
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,21 @@
name: Build
on:
push:
branches:
- 'default'
- 'v[0-9]+'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- uses: EndBug/add-and-commit@v4
with:
add: dist
message: Rebuild
author_name: Automated
author_email: github@asdf.kooi.me
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

200
dist/index.js vendored
View File

@ -1391,16 +1391,18 @@ const knownProperties = [
]; ];
module.exports = (fromStream, toStream) => { module.exports = (fromStream, toStream) => {
const fromProps = new Set(Object.keys(fromStream).concat(knownProperties)); const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties));
for (const prop of fromProps) { for (const property of fromProperties) {
// Don't overwrite existing properties // Don't overwrite existing properties.
if (prop in toStream) { if (property in toStream) {
continue; continue;
} }
toStream[prop] = typeof fromStream[prop] === 'function' ? fromStream[prop].bind(fromStream) : fromStream[prop]; toStream[property] = typeof fromStream[property] === 'function' ? fromStream[property].bind(fromStream) : fromStream[property];
} }
return toStream;
}; };
@ -2824,6 +2826,13 @@ exports.setFailed = setFailed;
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Logging Commands // Logging Commands
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/**
* Gets whether Actions Step Debug is on or not
*/
function isDebug() {
return process.env['RUNNER_DEBUG'] === '1';
}
exports.isDebug = isDebug;
/** /**
* Writes debug message to user log * Writes debug message to user log
* @param message debug message * @param message debug message
@ -3075,9 +3084,12 @@ const os = __importStar(__webpack_require__(87));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const httpm = __importStar(__webpack_require__(539)); const httpm = __importStar(__webpack_require__(539));
const semver = __importStar(__webpack_require__(550)); const semver = __importStar(__webpack_require__(550));
const stream = __importStar(__webpack_require__(413));
const util = __importStar(__webpack_require__(669));
const v4_1 = __importDefault(__webpack_require__(826)); const v4_1 = __importDefault(__webpack_require__(826));
const exec_1 = __webpack_require__(986); const exec_1 = __webpack_require__(986);
const assert_1 = __webpack_require__(357); const assert_1 = __webpack_require__(357);
const retry_helper_1 = __webpack_require__(979);
class HTTPError extends Error { class HTTPError extends Error {
constructor(httpStatusCode) { constructor(httpStatusCode) {
super(`Unexpected HTTP response: ${httpStatusCode}`); super(`Unexpected HTTP response: ${httpStatusCode}`);
@ -3122,52 +3134,58 @@ if (!tempDirectory || !cacheRoot) {
*/ */
function downloadTool(url, dest) { function downloadTool(url, dest) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Wrap in a promise so that we can resolve from within stream callbacks dest = dest || path.join(tempDirectory, v4_1.default());
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { yield io.mkdirP(path.dirname(dest));
try { core.debug(`Downloading ${url}`);
const http = new httpm.HttpClient(userAgent, [], { core.debug(`Destination ${dest}`);
allowRetries: true, const maxAttempts = 3;
maxRetries: 3 const minSeconds = getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 10);
}); const maxSeconds = getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 20);
dest = dest || path.join(tempDirectory, v4_1.default()); const retryHelper = new retry_helper_1.RetryHelper(maxAttempts, minSeconds, maxSeconds);
yield io.mkdirP(path.dirname(dest)); return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { return yield downloadToolAttempt(url, dest || ''); }));
core.debug(`Downloading ${url}`);
core.debug(`Downloading ${dest}`);
if (fs.existsSync(dest)) {
throw new Error(`Destination file path ${dest} already exists`);
}
const response = yield http.get(url);
if (response.message.statusCode !== 200) {
const err = new HTTPError(response.message.statusCode);
core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
throw err;
}
const file = fs.createWriteStream(dest);
file.on('open', () => __awaiter(this, void 0, void 0, function* () {
try {
const stream = response.message.pipe(file);
stream.on('close', () => {
core.debug('download complete');
resolve(dest);
});
}
catch (err) {
core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
reject(err);
}
}));
file.on('error', err => {
file.end();
reject(err);
});
}
catch (err) {
reject(err);
}
}));
}); });
} }
exports.downloadTool = downloadTool; exports.downloadTool = downloadTool;
function downloadToolAttempt(url, dest) {
return __awaiter(this, void 0, void 0, function* () {
if (fs.existsSync(dest)) {
throw new Error(`Destination file path ${dest} already exists`);
}
// Get the response headers
const http = new httpm.HttpClient(userAgent, [], {
allowRetries: false
});
const response = yield http.get(url);
if (response.message.statusCode !== 200) {
const err = new HTTPError(response.message.statusCode);
core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
throw err;
}
// Download the response body
const pipeline = util.promisify(stream.pipeline);
const responseMessageFactory = getGlobal('TEST_DOWNLOAD_TOOL_RESPONSE_MESSAGE_FACTORY', () => response.message);
const readStream = responseMessageFactory();
let succeeded = false;
try {
yield pipeline(readStream, fs.createWriteStream(dest));
core.debug('download complete');
succeeded = true;
return dest;
}
finally {
// Error, delete dest before retry
if (!succeeded) {
core.debug('download failed');
try {
yield io.rmRF(dest);
}
catch (err) {
core.debug(`Failed to delete '${dest}'. ${err.message}`);
}
}
}
});
}
/** /**
* Extract a .7z file * Extract a .7z file
* *
@ -3257,14 +3275,17 @@ function extractTar(file, dest, flags = 'xz') {
// Create dest // Create dest
dest = yield _createExtractFolder(dest); dest = yield _createExtractFolder(dest);
// Determine whether GNU tar // Determine whether GNU tar
core.debug('Checking tar --version');
let versionOutput = ''; let versionOutput = '';
yield exec_1.exec('tar --version', [], { yield exec_1.exec('tar --version', [], {
ignoreReturnCode: true, ignoreReturnCode: true,
silent: true,
listeners: { listeners: {
stdout: (data) => (versionOutput += data.toString()), stdout: (data) => (versionOutput += data.toString()),
stderr: (data) => (versionOutput += data.toString()) stderr: (data) => (versionOutput += data.toString())
} }
}); });
core.debug(versionOutput.trim());
const isGnuTar = versionOutput.toUpperCase().includes('GNU TAR'); const isGnuTar = versionOutput.toUpperCase().includes('GNU TAR');
// Initialize args // Initialize args
const args = [flags]; const args = [flags];
@ -3521,6 +3542,15 @@ function _evaluateVersions(versions, versionSpec) {
} }
return version; return version;
} }
/**
* Gets a global variable
*/
function getGlobal(key, defaultValue) {
/* eslint-disable @typescript-eslint/no-explicit-any */
const value = global[key];
/* eslint-enable @typescript-eslint/no-explicit-any */
return value !== undefined ? value : defaultValue;
}
//# sourceMappingURL=tool-cache.js.map //# sourceMappingURL=tool-cache.js.map
/***/ }), /***/ }),
@ -6865,6 +6895,80 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
createToken('STAR', '(<|>)?=?\\s*\\*') createToken('STAR', '(<|>)?=?\\s*\\*')
/***/ }),
/***/ 979:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"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(__webpack_require__(470));
/**
* Internal class for retries
*/
class RetryHelper {
constructor(maxAttempts, minSeconds, maxSeconds) {
if (maxAttempts < 1) {
throw new Error('max attempts should be greater than or equal to 1');
}
this.maxAttempts = maxAttempts;
this.minSeconds = Math.floor(minSeconds);
this.maxSeconds = Math.floor(maxSeconds);
if (this.minSeconds > this.maxSeconds) {
throw new Error('min seconds should be less than or equal to max seconds');
}
}
execute(action) {
return __awaiter(this, void 0, void 0, function* () {
let attempt = 1;
while (attempt < this.maxAttempts) {
// Try
try {
return yield action();
}
catch (err) {
core.info(err.message);
}
// Sleep
const seconds = this.getSleepAmount();
core.info(`Waiting ${seconds} seconds before trying again`);
yield this.sleep(seconds);
attempt++;
}
// Last attempt
return yield action();
});
}
getSleepAmount() {
return (Math.floor(Math.random() * (this.maxSeconds - this.minSeconds + 1)) +
this.minSeconds);
}
sleep(seconds) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
});
}
}
exports.RetryHelper = RetryHelper;
//# sourceMappingURL=retry-helper.js.map
/***/ }), /***/ }),
/***/ 986: /***/ 986: