1
1
import fs from 'fs'
2
2
import path from 'path'
3
3
import GitHub from 'github-api'
4
- import shell from 'shelljs '
4
+ import { exec } from '../utils '
5
5
import { version } from '../../package.json'
6
6
7
7
const { GITHUB_TOKEN } = process . env
8
8
const DIR = path . resolve ( path . join ( __dirname , '..' , '..' ) )
9
9
const DESKTOP_PKG_DIR = path . join ( DIR , 'out' , 'make' )
10
10
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 } )
19
13
}
20
14
21
15
const build = async ( ) => {
@@ -25,7 +19,18 @@ const build = async () => {
25
19
26
20
const repo = gh . getRepo ( 'meth' , 'app' )
27
21
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 } `
29
34
30
35
const newReleaseDetails = {
31
36
tag_name : tag ,
@@ -37,25 +42,25 @@ const build = async () => {
37
42
38
43
const { data : release } = await repo . createRelease ( newReleaseDetails )
39
44
40
- console . log ( `Release ID: ${ release . id } ` )
45
+ console . log ( `Release ID for ${ tag } : ${ release . id } ` )
41
46
42
47
let { upload_url : uploadUrl } = release
43
48
if ( 0 < uploadUrl . indexOf ( '{' ) ) {
44
49
uploadUrl = uploadUrl . substr ( 0 , uploadUrl . indexOf ( '{' ) )
45
50
}
46
51
47
- console . log ( `Asset upload URL: ${ uploadUrl } ` )
52
+ console . log ( `Asset upload URL for ${ tag } : ${ uploadUrl } ` )
48
53
49
54
fs . readdirSync ( DESKTOP_PKG_DIR ) . forEach ( file => {
50
55
const filePath = path . join ( DESKTOP_PKG_DIR , file )
51
56
52
- console . log ( `Uploading ${ filePath } ...` )
57
+ console . log ( `Uploading ${ filePath } to release ${ tag } ...` )
53
58
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 ) } ` )
55
60
} )
56
61
57
62
// public the release
58
- console . log ( `Publishing pre- release ...` )
63
+ console . log ( `Publishing release ${ tag } ...` )
59
64
60
65
await repo . updateRelease ( release . id , Object . assign ( { } , newReleaseDetails , {
61
66
draft : false
0 commit comments