Skip to content

Commit

Permalink
Merge pull request #15 from sugarshin/fix-deploy
Browse files Browse the repository at this point in the history
Fix deploy
  • Loading branch information
sugarshin committed Sep 21, 2017
2 parents 7b7296e + 1e294ea commit 02686ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Expand Up @@ -35,8 +35,10 @@ jobs:
key: v1-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }}
- deploy:
command: |
npm run deploy -- -e SENTRY_DSN=$SENTRY_DSN --token=$NOW_TOKEN &>/dev/null
npm run deployment:pop
./node_modules/.bin/now --public -e NODE_ENV=production -e SENTRY_DSN=$SENTRY_DSN -n moci --no-clipboard --token=$NOW_TOKEN
if [ "${CIRCLE_BRANCH}" == "master" ]; then
npm run alias -- --token=$NOW_TOKEN &>/dev/null
npm run delete
npm run deployment:delete
DATA=\{\"text\":\"mo\ has\ been\ updated\ \<https://moci.now.sh/\>\"\}; curl -XPOST -d $DATA $SLACK_WEBHOOK_URL
fi
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -9,9 +9,9 @@
"dev": "node server",
"prebuild": "npm run clean:build",
"build": "next build",
"deploy": "now --public -e NODE_ENV=production -n moci --no-clipboard",
"deployment:pop": "node ./scripts/deployment-pop",
"deployment:delete": "node ./scripts/deployment-delete",
"alias": "now alias --no-clipboard",
"delete": "node ./scripts/deployment-delete",
"start": "node ./server"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions scripts/deployment-delete.js
Expand Up @@ -16,6 +16,7 @@ const main = async () => {
console.log(`Success!
${targets.map(t => `Deployment ${t.uid} removed`).join('\n')}
`)
return
}
Expand Down
22 changes: 22 additions & 0 deletions scripts/deployment-pop.js
@@ -0,0 +1,22 @@
const NowClient = require('now-client')

const now = new NowClient(process.env.NOW_TOKEN)

const main = async () => {
const deployments = await now.getDeployments()
if (deployments.length >= 3) { // upper limit for free plan
const aliases = await now.getAliases()
const mociId = (aliases.find(a => a.alias === 'moci.now.sh') || {}).deploymentId
const target = deployments.filter(d => d.uid !== mociId).pop()
await now.deleteDeployment(target.uid)
console.log(`Success!
Deployment ${target.uid} removed
`)
} else {
console.log('Does not require delete.')
}
}

main()

0 comments on commit 02686ca

Please sign in to comment.