Skip to content

Commit

Permalink
chore: Add local scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
colinjfw committed Feb 20, 2020
1 parent 3d55c67 commit 70f7622
Show file tree
Hide file tree
Showing 12 changed files with 6,510 additions and 402 deletions.
9 changes: 9 additions & 0 deletions .github/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
production:
auto_deploy_on: refs/heads/master
environment: production
required_contexts: ["build (10.x)", "deliverybot/promotion"]

development:
auto_deploy_on: refs/heads/master
environment: development
required_contexts: ["build (10.x)"]
52 changes: 52 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy

on: ['deployment']

jobs:
deployment:

runs-on: 'ubuntu-latest'

steps:
- uses: actions/checkout@v1
- name: 'use node 8.x'
uses: actions/setup-node@v1
with:
node-version: 8.x

- name: 'deployment pending'
uses: 'deliverybot/deployment-status@master'
with:
state: 'pending'
token: '${{ github.token }}'

- name: 'deploy'
env:
PRODUCTION_SA: '${{ secrets.PRODUCTION_SA }}'
DEVELOPMENT_SA: '${{ secrets.DEVELOPMENT_SA }}'
run: |
npm install
echo 'deploy with ${{ github.event.deployment.environment }}_sa'
echo $PRODUCTION_SA > production-sa.json
echo $DEVELOPMENT_SA > development-sa.json
cp ${{ github.event.deployment.environment }}-sa.json service-account.json
echo ''
echo ''
echo ''
echo "${{ github.event.deployment.environment }}-sa.json"
cat ${{ github.event.deployment.environment }}-sa.json
GOOGLE_APPLICATION_CREDENTIALS=./service-account.json make deploy/${{ github.event.deployment.environment }}
- name: 'deployment success'
if: success()
uses: 'deliverybot/deployment-status@master'
with:
state: 'success'
token: '${{ github.token }}'

- name: 'deployment failure'
if: failure()
uses: 'deliverybot/deployment-status@master'
with:
state: 'failure'
token: '${{ github.token }}'
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI
name: Node CI

on: [push, pull_request]
on: [push]

jobs:
build:
Expand All @@ -17,9 +17,10 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
- name: yarn install, build, and test
run: |
yarn install
yarn build
yarn test
env:
CI: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
/tmp
/node_modules
/lib
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# deploybot
# Deliverybot

Complete deployment automation for GitHub. https://deliverybot.dev
https://deliverybot.dev

## Features
Simple Continuous Delivery for GitHub: Fast, safe and secure Continous Delivery
pipelines you can setup in minutes. Fully open source.

Deployment automation:
![Product screenshot](https://deliverybot.dev/assets/images/deploy-list.png)

- Automatic deployments on master or specific branches.
- Wait for status checks to pass before deploying.
- Review environments using `/deploy` commands in pull requests.
- Validate a deploy has succeeded before merging.

## Setup

```sh
# Install dependencies
yarn install

# Run typescript
yarn run build

# Run the bot
yarn start
```
* Click to deploy: Click the latest commit in the Deliverybot dashboard to
deploy your code. It doesn't get any simpler than that.
* Automatic deployments: Deploy automatically to multiple clusters and
environments given a specific branch.
* Advanced deployment workflows: Orchestrate canary deployments to test code in
incremental steps. Push out environments per pull request.
* Integrates with slack: Deploy from slack as well as deployments from a
dashboard.

## Contributing

Expand All @@ -31,6 +23,12 @@ a bug, open an issue! We'd love all and any contributions.

For more, check out the [Contributing Guide](CONTRIBUTING.md).

### Setup

yarn install
yarn start

## License

[MIT](LICENSE) © 2019 Deliverybot (https://github.com/deliverybot/deliverybot)

30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"private": true,
"version": "0.7.2",
"workspaces": [
"packages/app",
"packages/client",
"packages/firebase",
"packages/core",
"packages/deploybot",
"packages/slackbot",
"packages/run"
],
"scripts": {
"bump": "./bump.sh",
"start": "node ./scripts/build.js --watch",
"test": "node ./scripts/build.js --test",
"server": "node ./scripts/server.js",
"format": "prettier --write 'packages/*/src/**/*.{ts,js}'",
"build": "node ./scripts/build.js",
"push": "node ./scripts/build.js --publish"
},
"prettier": {
"trailingComma": "all"
},
"devDependencies": {
"prettier": "1.19.1",
"smee-client": "^1.1.0",
"standard-version": "7.1.0"
}
}
136 changes: 136 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const fs = require('fs');
const { spawn } = require('child_process');

const procs = [];

function shutdown() {
procs.forEach(proc => {
proc.kill('SIGTERM');
});
}

function run(pkg, cmd, onChange) {
function pad(name, to) {
let p = "";
for (let i = 0; i < to - name.length; i++) {
p += " ";
}
return `${name}:${p}`
}

return new Promise((resolve, reject) => {
const proc = spawn('yarn', [cmd], { cwd: pkg === '.' ? '.' : `./packages/${pkg}` });
const name = pad(pkg, 10);
procs.push(proc);
proc.stdout.on('data', (data) => {
data.toString().split("\n").forEach(line => {
if (line.trim()) process.stdout.write(`${name} ${line}\n`);
});
if (onChange) onChange();
});
proc.stderr.on('data', (data) => {
data.toString().split("\n").forEach(line => {
if (line.trim()) process.stdout.write(`${name} ${line}\n`);
});
if (onChange) onChange();
});
proc.on("close", (code) => {
if (code !== 0) {
console.log(`${name} ${cmd} exited with code ${code}`);
return reject(code);
}
return resolve();
});
});
}

function debounce(func, wait) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}

const restart = debounce(() => {
console.log("--> restart");
fs.utimes("tmp/restart.txt", new Date(), new Date(), (err) => {
if (err) console.error("Failed touch restart.txt", err);
});
}, 1000);

async function main() {
try {
fs.mkdirSync("./tmp");
} catch (err) {
// Ignore.
}
try {
fs.writeFileSync("./tmp/restart.txt", "");
} catch (err) {
// Ignore.
}

const watch = process.argv[2] == '--watch';
const publish = process.argv[2] == '--publish';
const test = process.argv[2] == '--test';

if (watch) {
await Promise.all([
run('.', 'server'),
run('core', 'build:watch', restart),
run('app', 'build:watch', restart),
run('app', 'partials:watch', restart),
run('client', 'build:watch', restart),
run('run', 'build:watch', restart),
run('run', 'bundle:watch', restart),
]);
} else if (test) {
await Promise.all([
run('app', 'test'),
]);
} else {
await Promise.all([
run('core', 'clean'),
run('app', 'clean'),
run('client', 'clean'),
run('run', 'clean'),
run('firebase', 'clean'),
run('deploybot', 'clean'),
run('slackbot', 'clean'),
]);
await run('core', 'build');
await Promise.all([
await run('deploybot', 'build'),
await run('slackbot', 'build'),
]);
await Promise.all([
run('app', 'build'),
run('app', 'partials'),
run('client', 'build'),
]);
await run('run', 'build');
await run('run', 'bundle');
await run('firebase', 'build');
}

if (publish) {
console.log("\n\nPublishing...")
await run('app', 'publish');
await run('client', 'publish');
await run('core', 'publish');
}

console.log("done");
process.exit(0);
}

main().catch(() => {
shutdown();
});

['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach(sig => process.on(sig, () => {
shutdown();
}));
16 changes: 16 additions & 0 deletions scripts/bump-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const pkg = require("../package.json");
const fs = require("fs");

const version = pkg.version;

pkg.workspaces.forEach(wrk => {
const path = `${wrk}/package.json`;
const wrkPkg = JSON.parse(fs.readFileSync(path).toString());
wrkPkg.version = version;
Object.keys(wrkPkg.dependencies).forEach(dep => {
if (dep.startsWith("@deliverybot")) {
wrkPkg.dependencies[dep] = version;
}
});
fs.writeFileSync(path, JSON.stringify(wrkPkg, null, 2) + "\n");
});
11 changes: 11 additions & 0 deletions scripts/bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

./node_modules/.bin/standard-version --skip.commit $@
node ./scripts/bump-versions.js

version=$(jq -r '.version' < ./package.json)

git add .
git commit -m "chore: release v${version}"
git tag "v${version}"
git push --follow-tags origin master
Loading

0 comments on commit 70f7622

Please sign in to comment.