-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
237 additions
and
25 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
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 @@ | ||
node_modules/ |
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,87 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const process = require('process'); | ||
const path = require('path'); | ||
|
||
const fetch = require('node-fetch'); | ||
const semver = require('semver'); | ||
|
||
const File = require('./file'); | ||
|
||
const gh = { | ||
url: process.env['GITHUB_API_URL'] || 'https://api.github.com/', | ||
user: process.env['CIRCLE_PROJECT_USERNAME'], | ||
repo: process.env['CIRCLE_PROJECT_REPONAME'], | ||
branch: process.env['CIRCLE_BRANCH'], | ||
headers: { | ||
'Accept': 'application/vnd.github.v3+json', | ||
'Authorization': `Basic ${process.env['GITHUB_AUTH']}` | ||
} | ||
} | ||
|
||
const files = [ | ||
// Linux files | ||
new File('./target/x86_64-unknown-linux-gnu/release/library-loader'), | ||
new File('./target/x86_64-unknown-linux-gnu/release/library-loader.sha256'), | ||
// Windows files | ||
new File('./target/x86_64-pc-windows-gnu/release/library-loader.exe'), | ||
new File('./target/x86_64-pc-windows-gnu/release/library-loader.exe.sha256') | ||
]; | ||
|
||
let cargoToml = fs.readFileSync('Cargo.toml', 'utf8').toString().split('\n'); | ||
let currentVersion = cargoToml.filter(l => l.includes('version = '))[0].split(' = ')[1].replace(/\"/g, ''); | ||
|
||
(async () => { | ||
|
||
const releases = await (await fetch(`${gh.url}repos/${gh.user}/${gh.repo}/releases`, { | ||
headers: gh.headers | ||
})).json(); | ||
|
||
if (semver.lte(currentVersion, releases[0].tag_name)) { | ||
throw new Error('Current version is not newer than last release!'); | ||
} | ||
|
||
console.log('Creating new release!'); | ||
|
||
let newReleaseRes = await (await fetch(`${gh.url}repos/${gh.user}/${gh.repo}/releases`, { | ||
headers: gh.headers, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
tag_name: currentVersion, | ||
target_commitish: gh.branch, | ||
name: `Release v${currentVersion}`, | ||
body: '', | ||
draft: false, | ||
prerelease: false | ||
}) | ||
})).json(); | ||
|
||
let uploadUrl = new URL(newReleaseRes['upload_url'].replace('{?name,label}', '')); | ||
|
||
files.forEach(async file => { | ||
|
||
let baseName = path.basename(file.path); | ||
uploadUrl.searchParams.set('name', baseName); | ||
uploadUrl.searchParams.set('label', baseName); | ||
|
||
let res = await fetch(uploadUrl, { | ||
headers: { | ||
...gh.headers, | ||
'Content-Type': file.mime, | ||
}, | ||
method: 'POST', | ||
body: file.read() | ||
}); | ||
|
||
if (await res.status === 201) { | ||
console.log(`Uploaded file ${baseName}`) | ||
} else { | ||
console.error(`Failed to upload ${baseName}`) | ||
} | ||
|
||
}); | ||
|
||
})(); | ||
|
||
|
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,32 @@ | ||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
module.exports = class File { | ||
|
||
constructor(path) { | ||
|
||
this.path = path; | ||
this.mime = null; | ||
|
||
if (!fs.existsSync(this.path)) { | ||
throw new Error(`${this.path} does not exist`); | ||
} | ||
|
||
let res = execSync(`file ${this.path} --mime-type`).toString('utf8'); | ||
|
||
let mime = res.split(': ')[1].trim(); | ||
if (mime.length) { | ||
this.mime = mime; | ||
} else { | ||
throw new Error('Error getting mime-type'); | ||
} | ||
|
||
} | ||
|
||
read() { | ||
|
||
return fs.readFileSync(this.path) | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
{ | ||
"name": "deploy", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "deploy.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"node-fetch": "^2.6.0", | ||
"semver": "^6.3.0" | ||
} | ||
} |