2017-02-06 18:02:32 +03:00
#!/usr/bin/env node
2016-03-24 18:40:38 +03:00
/ * *
2021-12-31 02:08:43 +03:00
* Copyright ( c ) Meta Platforms , Inc . and affiliates .
2016-03-24 18:40:38 +03:00
*
2018-02-17 05:24:55 +03:00
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree .
2018-05-11 23:32:39 +03:00
*
* @ format
2016-03-24 18:40:38 +03:00
* /
2019-10-16 20:03:47 +03:00
2016-03-24 18:40:38 +03:00
'use strict' ;
/ * *
2021-12-18 05:35:48 +03:00
* This script walks a releaser through bumping the version for a release
* It will commit the appropriate tags to trigger the CircleCI jobs .
2016-03-24 18:40:38 +03:00
* /
2022-04-23 02:25:25 +03:00
const { exit } = require ( 'shelljs' ) ;
2019-02-15 16:51:23 +03:00
const yargs = require ( 'yargs' ) ;
2021-12-18 05:35:48 +03:00
const inquirer = require ( 'inquirer' ) ;
2022-01-25 01:06:49 +03:00
const request = require ( 'request' ) ;
2021-12-18 05:35:48 +03:00
const {
parseVersion ,
isReleaseBranch ,
getBranchName ,
} = require ( './version-utils' ) ;
2016-03-24 18:40:38 +03:00
2020-08-18 22:07:57 +03:00
let argv = yargs
. option ( 'r' , {
alias : 'remote' ,
default : 'origin' ,
} )
2022-01-25 01:06:49 +03:00
. option ( 't' , {
alias : 'token' ,
describe :
'Your CircleCI personal API token. See https://circleci.com/docs/2.0/managing-api-tokens/#creating-a-personal-api-token to set one' ,
required : true ,
} )
. option ( 'v' , {
alias : 'to-version' ,
describe : 'Version you aim to release, ex. 0.67.0-rc.1, 0.66.3' ,
required : true ,
} )
2021-12-18 05:35:48 +03:00
. check ( ( ) => {
const branch = getBranchName ( ) ;
exitIfNotOnReleaseBranch ( branch ) ;
return true ;
2020-08-18 22:07:57 +03:00
} ) . argv ;
2017-02-06 18:02:32 +03:00
2021-12-18 05:35:48 +03:00
function exitIfNotOnReleaseBranch ( branch ) {
if ( ! isReleaseBranch ( branch ) ) {
console . log (
'This script must be run in a react-native git repository checkout and on a release branch' ,
2020-03-14 07:46:45 +03:00
) ;
exit ( 1 ) ;
}
2016-03-24 18:40:38 +03:00
}
2022-01-25 01:06:49 +03:00
function triggerReleaseWorkflow ( options ) {
return new Promise ( ( resolve , reject ) => {
request ( options , function ( error , response , body ) {
if ( error ) {
reject ( error ) ;
} else {
resolve ( body ) ;
}
} ) ;
} ) ;
}
2021-12-18 05:35:48 +03:00
async function main ( ) {
const branch = getBranchName ( ) ;
2022-01-25 01:06:49 +03:00
const token = argv . token ;
const releaseVersion = argv . toVersion ;
2016-03-24 18:40:38 +03:00
2022-01-25 01:06:49 +03:00
const { pushed } = await inquirer . prompt ( {
2021-12-18 05:35:48 +03:00
type : 'confirm' ,
2022-01-25 01:06:49 +03:00
name : 'pushed' ,
message : ` This script will trigger a release with whatever changes are on the remote branch: ${ branch } . \n Make sure you have pushed any updates remotely. ` ,
2021-12-18 05:35:48 +03:00
} ) ;
2021-10-02 07:21:03 +03:00
2022-01-25 01:06:49 +03:00
if ( ! pushed ) {
console . log ( ` Please run 'git push ${ argv . remote } ${ branch } ' ` ) ;
2020-03-14 07:46:45 +03:00
exit ( 1 ) ;
2021-12-18 05:35:48 +03:00
return ;
2020-03-14 07:46:45 +03:00
}
2022-01-25 01:06:49 +03:00
let latest = false ;
2021-12-18 05:35:48 +03:00
const { version , prerelease } = parseVersion ( releaseVersion ) ;
if ( ! prerelease ) {
2022-01-25 01:06:49 +03:00
const { setLatest } = await inquirer . prompt ( {
2021-12-18 05:35:48 +03:00
type : 'confirm' ,
2022-01-25 01:06:49 +03:00
name : 'setLatest' ,
message : ` Do you want to set ${ version } as "latest" release on npm? ` ,
2021-12-18 05:35:48 +03:00
} ) ;
2022-01-25 01:06:49 +03:00
latest = setLatest ;
2021-09-24 05:27:43 +03:00
}
2022-01-25 01:06:49 +03:00
const npmTag = latest ? 'latest' : ! prerelease ? branch : 'next' ;
2021-12-18 05:35:48 +03:00
const { confirmRelease } = await inquirer . prompt ( {
type : 'confirm' ,
name : 'confirmRelease' ,
message : ` Releasing version " ${ version } " with npm tag " ${ npmTag } ". Is this correct? ` ,
} ) ;
if ( ! confirmRelease ) {
console . log ( 'Aborting.' ) ;
return ;
2020-03-14 07:46:45 +03:00
}
2022-01-25 01:06:49 +03:00
const parameters = {
release _version : version ,
release _latest : latest ,
run _package _release _workflow _only : true ,
} ;
const options = {
method : 'POST' ,
url : 'https://circleci.com/api/v2/project/github/facebook/react-native/pipeline' ,
headers : {
'Circle-Token' : token ,
'content-type' : 'application/json' ,
} ,
body : {
branch ,
parameters ,
} ,
json : true ,
} ;
// See response: https://circleci.com/docs/api/v2/#operation/triggerPipeline
const body = await triggerReleaseWorkflow ( options ) ;
console . log (
` Monitor your release workflow: https://app.circleci.com/pipelines/github/facebook/react-native/ ${ body . number } ` ,
) ;
2020-03-14 07:46:45 +03:00
2021-12-18 05:35:48 +03:00
// TODO
2022-01-25 01:06:49 +03:00
// - Output the release changelog to paste into Github releases
// - Link to release discussions to update
// - Verify RN-diff publish is through
2016-03-24 18:40:38 +03:00
}
2021-12-18 05:35:48 +03:00
main ( ) . then ( ( ) => {
exit ( 0 ) ;
} ) ;