Skip to content

Instantly share code, notes, and snippets.

@Jpuelpan
Created September 13, 2017 05:08
Show Gist options
  • Save Jpuelpan/f3cdefd8b38bf9ff5422008dd5822d09 to your computer and use it in GitHub Desktop.
Save Jpuelpan/f3cdefd8b38bf9ff5422008dd5822d09 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const exec = require('child_process').execSync;
const [ , , ...args] = process.argv;
// Check if is a git repo
if( !fs.existsSync('./.git') ){
return console.error('Current directory is not a git repo!');
}
// Get last commit id
const lastCommitId = exec('git log --format="%H" -n 1').toString().trim();
const remoteOriginUrl = exec('git remote get-url origin').toString().trim()
const repoUrl = remoteOriginUrl.split(":")[1].split('.')[0]
const appName = repoUrl.split('/')[1]
const deploymentGroup = args[0] || 'staging';
const deployCommand = `aws deploy create-deployment --application-name ${appName} --deployment-group-name ${deploymentGroup} --github-location=commitId=${lastCommitId},repository=${repoUrl}`
const deploymentId = JSON.parse(exec(deployCommand).toString().trim()).deploymentId;
console.log(`[${new Date()}] Created deployment: ${deploymentId}`)
setInterval(() => {
const deployment = JSON.parse(
exec(`aws deploy get-deployment --deployment-id ${deploymentId}`).toString().trim()
);
const status = deployment.deploymentInfo.status;
console.log(`[${new Date()}] Status: ${status}`)
if( status !== "InProgress" ){
process.exit(0);
}
}, 1500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment