1
- require ( 'shelljs/global' ) ;
2
- const fs = require ( 'fs' ) ;
3
- const path = require ( 'path' ) ;
4
- const execSync = require ( 'child_process' ) . execSync ;
1
+ // Used to publish this fork of react-native
2
+ // Publish it as an attached tar asset to the GitHub release for general consumption, since we can't publish this to the npmjs npm feed
3
+
4
+ const fs = require ( "fs" ) ;
5
+ const path = require ( "path" ) ;
6
+ const execSync = require ( "child_process" ) . execSync ;
5
7
6
8
function exec ( command ) {
7
9
try {
8
10
console . log ( `Running command: ${ command } ` ) ;
9
11
return execSync ( command , {
10
- stdio : 'inherit'
11
- } ) ;
12
- }
13
- catch ( err ) {
12
+ stdio : "inherit"
13
+ } ) ;
14
+ } catch ( err ) {
14
15
process . exitCode = 1 ;
15
16
console . log ( `Failure running: ${ command } ` ) ;
16
17
throw err ;
17
18
}
18
19
}
19
20
20
21
function doPublish ( ) {
21
-
22
22
const publishBranchName = process . env . publishBranchName ;
23
23
24
24
const tempPublishBranch = `publish-${ Date . now ( ) } ` ;
25
25
26
- const pkgJsonPath = path . resolve ( __dirname , ' ../package.json' ) ;
27
- let pkgJson = JSON . parse ( fs . readFileSync ( pkgJsonPath , ' utf8' ) ) ;
26
+ const pkgJsonPath = path . resolve ( __dirname , " ../package.json" ) ;
27
+ let pkgJson = JSON . parse ( fs . readFileSync ( pkgJsonPath , " utf8" ) ) ;
28
28
29
29
let releaseVersion = pkgJson . version ;
30
30
31
31
const versionGroups = / ( .* - m i c r o s o f t \. ) ( [ 0 - 9 ] * ) / . exec ( releaseVersion ) ;
32
32
if ( versionGroups ) {
33
- releaseVersion = versionGroups [ 1 ] + ( parseInt ( versionGroups [ 2 ] ) + 1 ) ;
33
+ releaseVersion = versionGroups [ 1 ] + ( parseInt ( versionGroups [ 2 ] ) + 1 ) ;
34
34
} else {
35
- if ( releaseVersion . indexOf ( '-' ) === - 1 )
36
- {
37
- releaseVersion = releaseVersion + '-microsoft.0' ;
38
- }
39
- else
40
- {
41
- console . log ( 'Invalid version to publish' ) ;
35
+ if ( releaseVersion . indexOf ( "-" ) === - 1 ) {
36
+ releaseVersion = releaseVersion + "-microsoft.0" ;
37
+ } else {
38
+ console . log ( "Invalid version to publish" ) ;
42
39
exit ( 1 ) ;
43
40
}
44
41
}
@@ -54,27 +51,114 @@ function doPublish() {
54
51
exec ( `git push origin HEAD:${ tempPublishBranch } --follow-tags --verbose` ) ;
55
52
56
53
// -------- Generating Android Artifacts with JavaDoc
57
- exec ( ' gradlew installArchives' ) ;
54
+ exec ( " gradlew installArchives" ) ;
58
55
59
56
// undo uncommenting javadoc setting
60
- exec ( ' git checkout ReactAndroid/gradle.properties' ) ;
57
+ exec ( " git checkout ReactAndroid/gradle.properties" ) ;
61
58
62
59
// Configure npm to publish to internal feed
63
- const npmrcPath = path . resolve ( __dirname , '../.npmrc' ) ;
64
- const npmrcContents = `registry=https:${ process . env . publishnpmfeed } /registry/\nalways-auth=true` ;
60
+ const npmrcPath = path . resolve ( __dirname , "../.npmrc" ) ;
61
+ const npmrcContents = `registry=https:${
62
+ process . env . publishnpmfeed
63
+ } /registry/\nalways-auth=true`;
65
64
console . log ( `Creating ${ npmrcPath } for publishing` ) ;
66
65
fs . writeFileSync ( npmrcPath , npmrcContents ) ;
67
66
68
67
exec ( `npm publish` ) ;
69
68
exec ( `del ${ npmrcPath } ` ) ;
70
- exec ( `git tag v${ releaseVersion } ` ) ;
71
- exec ( `git push origin HEAD:${ tempPublishBranch } --follow-tags --verbose` ) ;
72
- exec ( `git checkout ${ publishBranchName } ` ) ;
73
- exec ( 'git pull origin ${publishBranchName}' ) ;
74
- exec ( 'git merge ${publishBranchName} --no-edit' ) ;
75
- exec ( 'git push origin HEAD:${publishBranchName} --follow-tags --verbose' ) ;
76
- exec ( 'git branch -d ${tempPublishBranch}' ) ;
77
- exec ( 'git push origin --delete -d ${tempPublishBranch}' ) ;
69
+
70
+ // Push tar to GitHub releases
71
+ exec ( `npm pack` ) ;
72
+
73
+ const npmTarPath = path . resolve (
74
+ __dirname ,
75
+ `../react-native-${ releaseVersion } .tgz`
76
+ ) ;
77
+ const assetUpdateUrl = `https://uploads.github.com/repos/Microsoft/react-native/releases/{id}/assets?name=react-native-${ releaseVersion } .tgz` ;
78
+ const authHeader =
79
+ "Basic " + new Buffer ( ":" + process . env . githubToken ) . toString ( "base64" ) ;
80
+ const userAgent = "Microsoft-React-Native-Release-Agent" ;
81
+
82
+ let uploadReleaseAssetUrl = "" ;
83
+ exec ( "npm install request@^2.69.0 --no-save" ) ;
84
+
85
+ const request = require ( "request" ) ;
86
+
87
+ const uploadTarBallToRelease = function ( ) {
88
+ request . post (
89
+ {
90
+ url : uploadReleaseAssetUrl ,
91
+ headers : {
92
+ "User-Agent" : userAgent ,
93
+ Authorization : authHeader ,
94
+ "Content-Type" : "application/octet-stream"
95
+ } ,
96
+ formData : {
97
+ file : fs . createReadStream ( npmTarPath )
98
+ }
99
+ } ,
100
+ function ( err , res , body ) {
101
+ if ( err ) {
102
+ console . error ( err ) ;
103
+ process . exitCode = 1 ;
104
+ throw err ;
105
+ }
106
+
107
+ var formattedResponse = JSON . parse ( body ) ;
108
+
109
+ if ( formattedResponse . errors ) {
110
+ process . exitCode = 1 ;
111
+ console . error ( formattedResponse . errors ) ;
112
+ throw formattedResponse . errors ;
113
+ }
114
+
115
+ exec ( `del ${ npmTarPath } ` ) ;
116
+ exec ( `git tag v${ releaseVersion } ` ) ;
117
+ exec (
118
+ `git push origin HEAD:${ tempPublishBranch } --follow-tags --verbose`
119
+ ) ;
120
+ exec ( `git checkout ${ publishBranchName } ` ) ;
121
+ exec ( `git pull origin ${ publishBranchName } ` ) ;
122
+ exec ( `git merge ${ publishBranchName } --no-edit` ) ;
123
+ exec (
124
+ `git push origin HEAD:${ publishBranchName } --follow-tags --verbose`
125
+ ) ;
126
+ exec ( `git branch -d ${ tempPublishBranch } ` ) ;
127
+ exec ( `git push origin --delete -d ${ tempPublishBranch } ` ) ;
128
+ }
129
+ ) ;
130
+ } ;
131
+
132
+ request . post (
133
+ {
134
+ url : "https://api.github.com/repos/Microsoft/react-native/releases" ,
135
+ headers : {
136
+ "User-Agent" : userAgent ,
137
+ Authorization : authHeader ,
138
+ "Content-Type" : "application/json"
139
+ } ,
140
+ body : JSON . stringify ( {
141
+ tag_name : `v${ releaseVersion } ` ,
142
+ target_commitish : publishBranchName ,
143
+ name : `v${ releaseVersion } ` ,
144
+ body : `v${ releaseVersion } ` ,
145
+ draft : false ,
146
+ prerelease : true
147
+ } )
148
+ } ,
149
+ function ( err , res , body ) {
150
+ if ( err ) {
151
+ console . log ( err ) ;
152
+ throw new Error ( "Error fetching release id." ) ;
153
+ }
154
+
155
+ console . log ( "Created GitHub Release: " + JSON . stringify ( body , null , 2 ) ) ;
156
+ var releaseId = JSON . parse ( body ) . id ;
157
+ uploadReleaseAssetUrl = assetUpdateUrl . replace ( / { i d } / , releaseId ) ;
158
+
159
+ uploadTarBallToRelease ( ) ;
160
+ }
161
+ ) ;
78
162
}
79
163
80
164
doPublish ( ) ;
0 commit comments