-
Notifications
You must be signed in to change notification settings - Fork 24.6k
/
Copy pathrelease-utils.js
183 lines (162 loc) · 5.27 KB
/
release-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
'use strict';
const {
createHermesPrebuiltArtifactsTarball,
} = require('../../../packages/react-native/scripts/hermes/hermes-utils');
const {echo, exec, exit, popd, pushd, test} = require('shelljs');
/*::
type BuildType = 'dry-run' | 'release' | 'nightly';
*/
function generateAndroidArtifacts(releaseVersion /*: string */) {
// -------- Generating Android Artifacts
echo('Generating Android artifacts inside /tmp/maven-local');
if (exec('./gradlew publishAllToMavenTempLocal').code) {
echo('Could not generate artifacts');
exit(1);
}
echo('Generated artifacts for Maven');
let artifacts = [
'.module',
'.pom',
'-debug.aar',
'-release.aar',
'-debug-sources.jar',
'-release-sources.jar',
].map(suffix => {
return `react-android-${releaseVersion}${suffix}`;
});
artifacts.forEach(name => {
if (
!test(
'-e',
`/tmp/maven-local/com/facebook/react/react-android/${releaseVersion}/${name}`,
)
) {
echo(
`Failing as expected file: \n\
/tmp/maven-local/com/facebook/react/react-android/${releaseVersion}/${name}\n\
was not correctly generated.`,
);
exit(1);
}
});
}
function publishAndroidArtifactsToMaven(
releaseVersion /*: string */,
buildType /*: BuildType */,
) {
// We want to gate ourselves against accidentally publishing a 1.x or a 1000.x on
// maven central which will break the semver for our artifacts.
if (buildType === 'release' && releaseVersion.startsWith('0.')) {
// -------- For stable releases, we also need to close and release the staging repository.
if (
exec(
'./gradlew findSonatypeStagingRepository closeAndReleaseSonatypeStagingRepository',
).code
) {
echo(
'Failed to close and release the staging repository on Sonatype (Maven Central) for Android artifacts',
);
exit(1);
}
} else {
echo(
'Nothing to do as this is not a stable release - Nightlies Android artifacts are published by build_android',
);
}
echo('Finished publishing Android artifacts to Maven Central');
}
function publishExternalArtifactsToMaven(
releaseVersion /*: string */,
buildType /*: BuildType */,
) {
// We want to gate ourselves against accidentally publishing a 1.x or a 1000.x on
// maven central which will break the semver for our artifacts.
if (buildType === 'release' && releaseVersion.startsWith('0.')) {
// -------- For stable releases, we do the publishing and close the staging repository.
// This can't be done earlier in build_android because this artifact are partially built by the iOS jobs.
if (
exec(
'./gradlew :packages:react-native:ReactAndroid:external-artifacts:publishToSonatype closeAndReleaseSonatypeStagingRepository',
).code
) {
echo(
'Failed to close and release the staging repository on Sonatype (Maven Central) for external artifacts',
);
exit(1);
}
} else {
const isSnapshot = buildType === 'nightly';
// -------- For nightly releases, we only need to publish the snapshot to Sonatype snapshot repo.
if (
exec(
'./gradlew :packages:react-native:ReactAndroid:external-artifacts:publishToSonatype -PisSnapshot=' +
isSnapshot.toString(),
).code
) {
echo('Failed to publish external artifacts to Sonatype (Maven Central)');
exit(1);
}
}
echo('Finished publishing external artifacts to Maven Central');
}
function generateiOSArtifacts(
jsiFolder /*: string */,
hermesCoreSourceFolder /*: string */,
buildType /*: 'Debug' | string */,
targetFolder /*: string */,
) /*: string */ {
pushd(`${hermesCoreSourceFolder}`);
//Generating iOS Artifacts
exec(
`JSI_PATH=${jsiFolder} BUILD_TYPE=${buildType} ${hermesCoreSourceFolder}/utils/build-mac-framework.sh`,
);
exec(
`JSI_PATH=${jsiFolder} BUILD_TYPE=${buildType} ${hermesCoreSourceFolder}/utils/build-ios-framework.sh`,
);
popd();
const tarballOutputPath = createHermesPrebuiltArtifactsTarball(
hermesCoreSourceFolder,
buildType,
targetFolder,
true, // this is excludeDebugSymbols, we keep it as the default
);
return tarballOutputPath;
}
function failIfTagExists(version /*: string */, buildType /*: BuildType */) {
// When dry-run in stable branch, the tag already exists.
// We are bypassing the tag-existence check when in a dry-run to have the CI pass
if (buildType === 'dry-run') {
return;
}
if (checkIfTagExists(version)) {
echo(`Tag v${version} already exists.`);
echo('You may want to rollback the last commit');
echo('git reset --hard HEAD~1');
exit(1);
}
}
function checkIfTagExists(version /*: string */) {
const {code, stdout} = exec('git tag -l', {silent: true});
if (code !== 0) {
throw new Error('Failed to retrieve the list of tags');
}
const tags = new Set(stdout.split('\n'));
return tags.has(`v${version}`);
}
module.exports = {
generateAndroidArtifacts,
generateiOSArtifacts,
publishAndroidArtifactsToMaven,
publishExternalArtifactsToMaven,
failIfTagExists,
};