Skip to content

Commit

Permalink
Merge pull request #8 from BrownUniversity/task/make-artisan-commands…
Browse files Browse the repository at this point in the history
…-serial

Make artisan commands serial
  • Loading branch information
christopher-keith authored Jan 19, 2020
2 parents 2d04e6a + 84e98ac commit bfd59b1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DOCKER_COMPOSE = docker-compose

.phony: compile
compile: install
compile: npm-ci
${DOCKER_COMPOSE} run --rm node node_modules/.bin/ncc build index.js

.phony: format
Expand All @@ -15,3 +15,7 @@ lint:
.phony: install
install:
${DOCKER_COMPOSE} run --rm node npm install

.phony: npm-ci
npm-ci:
${DOCKER_COMPOSE} run --rm node npm ci
67 changes: 39 additions & 28 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports =
/******/ // the startup function
/******/ function startup() {
/******/ // Load entry module and return exports
/******/ return __webpack_require__(334);
/******/ return __webpack_require__(104);
/******/ };
/******/
/******/ // run startup
Expand Down Expand Up @@ -941,14 +941,7 @@ module.exports = require("os");

/***/ }),

/***/ 129:
/***/ (function(module) {

module.exports = require("child_process");

/***/ }),

/***/ 334:
/***/ 104:
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {

const core = __webpack_require__(470);
Expand All @@ -959,7 +952,7 @@ function getRequiredInput(input) {
if (capturedInput === null || capturedInput === "") {
core.setFailed(`Action failed, unable to get required input: ${input}`);
}

return capturedInput;
}

Expand All @@ -968,7 +961,7 @@ function getOptions() {
user: getRequiredInput("user"),
host: getRequiredInput("host"),
versionsRoot: getRequiredInput("versionsRoot"),
version: core.getInput("version") || process.env["GITHUB_SHA"] || '',
version: core.getInput("version") || process.env.GITHUB_SHA || "",
key: getRequiredInput("key"),
artisanCommands: core.getInput("artisanCommands").split("|"),
artifact: core.getInput("artifact"),
Expand All @@ -988,8 +981,8 @@ async function executeSSH({ key, user, host }, command, execOptions = {}) {
await executeCall(`ssh -i ${key} ${user}@${host} ${command}`, execOptions);
}

async function executeSCP({ key, user, host }, source, destination) {
await executeCall(`scp -i ${key} ${source} ${destination}`)
async function executeSCP({ key }, source, destination) {
await executeCall(`scp -i ${key} ${source} ${destination}`);
}

async function ensureTargetDirectoryExists(options) {
Expand All @@ -1006,8 +999,11 @@ async function deployArtifact(options) {
}

async function explodeTarball(options) {
const { artifact, version, versionsRoot} = options;
await executeSSH(options, `tar -xzf ${versionsRoot}/${artifact} -C ${versionsRoot}/${version}`);
const { artifact, version, versionsRoot } = options;
await executeSSH(
options,
`tar -xzf ${versionsRoot}/${artifact} -C ${versionsRoot}/${version}`
);
}

async function removeArtifact(options) {
Expand All @@ -1022,52 +1018,60 @@ async function updateVersionDirectoryTimeStamp(options) {

async function setTargetPermissions(options) {
const { versionsRoot, version } = options;
const path = `${versionsRoot}/${version}`
const path = `${versionsRoot}/${version}`;
await executeSSH(options, `chmod -R 770 ${path}`);
await executeSSH(options, `chmod -R 775 ${path}/storage`);
}

async function executeArtisan(options) {
const { versionsRoot, version } = options;
options.artisanCommands.forEach(async command => {
await executeSSH(options, `cd ${versionsRoot}/${version}; php artisan ${command}`);
});
/* eslint-disable no-restricted-syntax */
for (const command of options.artisanCommands) {
// eslint-disable-next-line no-await-in-loop
await executeSSH(
options,
`cd ${versionsRoot}/${version}; php artisan ${command}`
);
}
/* eslint-enable no-restricted-syntax */
}

async function updateSymlink(options) {
const { version, versionsRoot } = options;
await executeSSH(options, `rm -f ${versionsRoot}/current`);
await executeSSH(options, `ln -s ${versionsRoot}/${version} ${versionsRoot}/current`);
await executeSSH(
options,
`ln -s ${versionsRoot}/${version} ${versionsRoot}/current`
);
}

async function removeOldVersions(options) {
const { versionsToKeep, versionsRoot } = options;
if (versionsToKeep === 0) {
return;
}

let output = "";
let error = "";
const execOptions = {};
execOptions.listeners = {
stdout: (data) => {
stdout: data => {
output += data.toString();
},
stderr: (data) => {
error += data.toString();
}
};
await executeSSH(options, `ls -t ${versionsRoot}`, execOptions);

const rawDirs = output.split(/\s+/).filter(dir => dir !== "current");
rawDirs.splice(-1, 1);
if (rawDirs.length <= versionsToKeep) {
return;
}
const dirsToRemove = rawDirs.slice(versionsToKeep);
for(dir of dirsToRemove) {
/* eslint-disable no-restricted-syntax */
for (const dir of dirsToRemove) {
// eslint-disable-next-line no-await-in-loop
await executeSSH(options, `rm -fr ${versionsRoot}/${dir}`);
}
/* eslint-enable no-restricted-syntax */
}

async function main() {
Expand All @@ -1086,6 +1090,13 @@ async function main() {
main();


/***/ }),

/***/ 129:
/***/ (function(module) {

module.exports = require("child_process");

/***/ }),

/***/ 357:
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ async function setTargetPermissions(options) {

async function executeArtisan(options) {
const { versionsRoot, version } = options;
options.artisanCommands.forEach(async command => {
/* eslint-disable no-restricted-syntax */
for (const command of options.artisanCommands) {
// eslint-disable-next-line no-await-in-loop
await executeSSH(
options,
`cd ${versionsRoot}/${version}; php artisan ${command}`
);
});
}
/* eslint-enable no-restricted-syntax */
}

async function updateSymlink(options) {
Expand Down

0 comments on commit bfd59b1

Please sign in to comment.