-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
7 changed files
with
283 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ node_modules | |
# build folder | ||
lib/ | ||
.babel_cache/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ yarn.lock | |
.editorconfig | ||
.gitignore | ||
.babel_cache/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
Oops, something went wrong.