Skip to content
This repository was archived by the owner on Nov 9, 2020. It is now read-only.

Commit b54893b

Browse files
committed
fix release numbering
1 parent acd58f6 commit b54893b

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

build-tools/scripts/github-release-upload-beta.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import fs from 'fs'
22
import path from 'path'
33
import GitHub from 'github-api'
4-
import shell from 'shelljs'
4+
import { exec } from '../utils'
55
import { version } from '../../package.json'
66

77
const { GITHUB_TOKEN } = process.env
88
const DIR = path.resolve(path.join(__dirname, '..', '..'))
99
const DESKTOP_PKG_DIR = path.join(DIR, 'out', 'make')
1010

11-
const exec = cmd => {
12-
const { code, stdout, stderr } = shell.exec(cmd, { cwd: DIR })
13-
14-
if (0 !== code) {
15-
console.error(stdout)
16-
console.error(stderr)
17-
throw new Error(`Error executing command (exit code: ${code}): ${cmd}`)
18-
}
11+
const _exec = cmd => {
12+
exec(cmd, { cwd: DIR })
1913
}
2014

2115
const build = async () => {
@@ -25,7 +19,18 @@ const build = async () => {
2519

2620
const repo = gh.getRepo('meth', 'app')
2721

28-
const tag = `v${version}-beta`
22+
const tagPrefix = `v${version}-beta`
23+
24+
// work out beta number
25+
const { data: existing } = await repo.listReleases()
26+
let betaNumber = 1
27+
existing.forEach(r => {
28+
if (r.tag_name.startsWith(tagPrefix)) {
29+
betaNumber += 1
30+
}
31+
})
32+
33+
const tag = `v${version}-beta${betaNumber}`
2934

3035
const newReleaseDetails = {
3136
tag_name: tag,
@@ -37,25 +42,25 @@ const build = async () => {
3742

3843
const { data: release } = await repo.createRelease(newReleaseDetails)
3944

40-
console.log(`Release ID: ${release.id}`)
45+
console.log(`Release ID for ${tag}: ${release.id}`)
4146

4247
let { upload_url: uploadUrl } = release
4348
if (0 < uploadUrl.indexOf('{')) {
4449
uploadUrl = uploadUrl.substr(0, uploadUrl.indexOf('{'))
4550
}
4651

47-
console.log(`Asset upload URL: ${uploadUrl}`)
52+
console.log(`Asset upload URL for ${tag}: ${uploadUrl}`)
4853

4954
fs.readdirSync(DESKTOP_PKG_DIR).forEach(file => {
5055
const filePath = path.join(DESKTOP_PKG_DIR, file)
5156

52-
console.log(`Uploading ${filePath} ...`)
57+
console.log(`Uploading ${filePath} to release ${tag} ...`)
5358

54-
exec(`curl --data-binary @"${filePath}" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" ${uploadUrl}?name=${encodeURIComponent(file)}`)
59+
_exec(`curl --data-binary @"${filePath}" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" ${uploadUrl}?name=${encodeURIComponent(file)}`)
5560
})
5661

5762
// public the release
58-
console.log(`Publishing pre-release ...`)
63+
console.log(`Publishing release ${tag} ...`)
5964

6065
await repo.updateRelease(release.id, Object.assign({}, newReleaseDetails, {
6166
draft: false

0 commit comments

Comments
 (0)