Skip to content

Commit

Permalink
Feature/build standalone app (#15)
Browse files Browse the repository at this point in the history
* First draft of publish release script
* completed script

* Sending files as zip
* Finalized the publish release script and added info on readme
  • Loading branch information
lmammino committed May 2, 2017
1 parent e9a821b commit ede2cc6
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ node_modules
# build folder
lib/
.babel_cache/
build/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ yarn.lock
.editorconfig
.gitignore
.babel_cache/
build/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ $ npm install -g norrisbot
```


### Alternative Installation (binaries)

From release 2.0.3, every release comes also with dependency-free binaries for linux, mac and windows that can be downloaded in the [Releases page on GitHub](https://github.com/lmammino/norrisbot/releases).


## Running the NorrisBot

To run the NorrisBot you must have a valid Slack [BOT token](#getting-the-bot-token-for-your-slack-channel) to authenticate the bot on your slack organization. Once you get it (instructions on the next paragraph) you just have to run:
Expand Down Expand Up @@ -157,4 +162,4 @@ Enjoy your reading!

## License

Licensed under [MIT License](LICENSE). © Luciano Mammino.
Licensed under [MIT License](LICENSE). © Luciano Mammino.
5 changes: 3 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ dependencies:
- yarn
cache_directories:
- ~/.cache/yarn
- ~/.pkg-cache

test:
override:
- yarn test
post:
- cp -r coverage/lcov-report $CIRCLE_TEST_REPORTS/coverage
- codecov
- if [ $CIRCLE_BRANCH = 'master' ]; then npm run build; fi
- if [ $CIRCLE_BRANCH = 'master' ]; then npm run release:tag && npm publish; fi
- if [ $CIRCLE_BRANCH = 'master' ]; then npm run build && npm run package:create; fi
- if [ $CIRCLE_BRANCH = 'master' ]; then npm run package:publish && npm publish; fi
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "norrisbot",
"version": "2.0.2",
"version": "2.0.3",
"description": "a Slack bot that kicks asses (roundhouse-kicks to be accurate...)",
"keywords": [
"Slack",
Expand All @@ -27,7 +27,9 @@
"lint": "eslint src tests",
"test:unit": "jest tests/* --coverage --verbose",
"test": "npm run lint && npm run test:unit",
"release:tag": "git tag $npm_package_version && git push --tags"
"release:tag": "git tag $npm_package_version && git push --tags",
"package:create": "pkg . -t node7-win,node7-macos,node7-linux --out-dir build",
"package:publish": "node publish-release $GITHUB_TOKEN lmammino/norrisbot $npm_package_version"
},
"author": {
"name": "Luciano Mammino",
Expand All @@ -54,6 +56,8 @@
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"jest": "^19.0.2",
"pkg": "^3.0.0",
"request-promise": "^4.2.0",
"rimraf": "^2.6.1"
}
}
77 changes: 77 additions & 0 deletions publish-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* eslint no-console: "off" */
/* eslint import/no-extraneous-dependencies: "off" */
const fs = require('fs');
const path = require('path');
const request = require('request-promise');

const USER_AGENT = 'publish-release-script-1';
const GH_API_ENDPOINT = 'https://api.github.com';
const GH_UPLOAD_URL = id => `https://uploads.github.com/repos/lmammino/norrisbot/releases/${id}/assets`;

const token = process.argv[2];
const repo = process.argv[3];
const release = process.argv[4];
const buildFolder = process.argv[5] || './build';

console.log(`Creating release "${release}" from "${buildFolder}"`);

const uploadFile = releaseId => file => new Promise((resolve, reject) => {
console.log('attaching', file.path);
return fs.readFile(file.path, (error, buffer) => {
if (error) {
return reject(error);
}

return resolve(request.post({
body: buffer,
url: `${GH_UPLOAD_URL(releaseId)}?name=${file.name}`,
headers: {
'User-Agent': USER_AGENT,
'Content-Type': 'application/zip',
Authorization: `token ${token}`,
},
}));
});
});

let releaseId;

request({
uri: `${GH_API_ENDPOINT}/repos/${repo}/releases`,
method: 'POST',
body: JSON.stringify({
tag_name: release,
name: `v${release}`,
}),
headers: {
'User-Agent': USER_AGENT,
'Content-Type': 'application/json',
Authorization: `token ${token}`,
},
})
.then((response) => {
const data = JSON.parse(response);
releaseId = data.id;
console.log(`Created release: ${data.url}`);

return new Promise((resolve, reject) => {
fs.readdir(buildFolder, (err, items) => {
if (err) {
return reject(err);
}

return resolve(items.map(item => ({
name: item,
path: path.resolve(path.join(buildFolder, item)),
})));
});
});
})
.then(files => Promise.all(files.map(uploadFile(releaseId))))
.then(() => {
console.log('✅ Done');
})
.catch((err) => {
console.error('Failed to create release', err);
process.exit(1);
});
Loading

0 comments on commit ede2cc6

Please sign in to comment.