diff --git a/.github/actions/create-release/action.yml b/.github/actions/create-release/action.yml new file mode 100644 index 00000000000000..0ee01f7f82f1d2 --- /dev/null +++ b/.github/actions/create-release/action.yml @@ -0,0 +1,29 @@ +name: prepare_release +description: Prepare React Native release +runs: + using: composite + steps: + - name: Yarn install + shell: bash + run: yarn install --non-interactive + - name: Creating release commit + shell: bash + run: | + node scripts/releases/create-release-commit.js \ + --reactNativeVersion "${{ inputs.version }}" \ + --isLatestOnNpm "${{ inputs.is_latest_on_npm }}" \ + --dryRun "${{ inputs.dry_run }}" + GIT_PAGER=cat git show HEAD + - name: Update "latest" tag if needed + shell: bash + if: ${{ inputs.tag == 'latest' }} + run: | + git tag -d "latest" + git push origin :latest + git tag -a "latest" -m "latest" + - name: Pushing release commit + shell: bash + if: ${{ inputs.dry_run == false }} + run: | + CURR_BRANCH="$(git branch --show-current)" + git push origin "$CURR_BRANCH" --follow-tags diff --git a/.github/actions/prepare_release/action.yml b/.github/actions/prepare_release/action.yml deleted file mode 100644 index fe0eaeac27a360..00000000000000 --- a/.github/actions/prepare_release/action.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: prepare_release -description: Prepare React Native release -runs: - using: composite - steps: - - name: Yarn install - shell: bash - run: yarn install --non-interactive - - name: Validate version - shell: bash - run: node ./scripts/releases/validate-version.js --build-type release --version "${{ inputs.version }}" - - name: Versioning workspace packages - shell: bash - run: | - node scripts/releases/set-version "${{ inputs.version }}" --skip-react-native-version - - name: Versioning react-native package - shell: bash - run: | - node scripts/releases/set-rn-version.js -v "<< parameters.version >>" --build-type "release" - - name: Creating release commit - shell: bash - run: | - BRANCH="$(git branch --show-current)" - NPM_TAG="$(node ./scripts/releases/compute-npm-tag.js --version ${{ inputs.version }} --branch $BRANCH)" - - if [[ "${{ inputs.is-latest-on-npm }}" ]]; then - NPM_TAG="$(node ./scripts/releases/compute-npm-tag.js --is_latest_on_npm --version ${{ inputs.version }} --branch $BRANCH)" - fi - - git commit -a -m "Release ${{ inputs.version }}" -m "#publish-packages-to-npm&$NPM_TAG" - git tag -a "v${{ inputs.version }}" -m "v${{ inputs.version }}" - GIT_PAGER=cat git show HEAD - - name: Update "latest" tag if needed - shell: bash - if: ${{ inputs.tag == 'latest' }} - run: | - git tag -d "latest" - git push origin :latest - git tag -a "latest" -m "latest" - - name: Pushing release commit - shell: bash - if: ${{ inputs.dry_run == false }} - run: | - CURR_BRANCH="$(git branch --show-current)" - git push origin "$CURR_BRANCH" --follow-tags diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/create-release.yml similarity index 92% rename from .github/workflows/prepare-release.yml rename to .github/workflows/create-release.yml index b976638a681eff..85e14987843cae 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/create-release.yml @@ -1,13 +1,13 @@ -name: Prepare Release +name: Create release on: workflow_dispatch: inputs: version: - description: 'The version of React Native we want to release' + description: 'The version of React Native we want to release. For example 0.75.0-rc.0' required: true type: string - is-latest-on-npm: + is_latest_on_npm: description: 'Whether we want to tag this release as latest on NPM' required: true type: boolean @@ -45,4 +45,4 @@ jobs: fi - name: Execute Prepare Release if: ${{ steps.check_stable_branch.outputs.ON_STABLE_BRANCH && !steps.check_if_tag_exists.outputs.TAG_EXISTS }} - uses: ./.github/actions/prepare_release + uses: ./.github/actions/create-release diff --git a/scripts/releases/README.md b/scripts/releases/README.md index 98e663a665c2d5..e929d6fea716d4 100644 --- a/scripts/releases/README.md +++ b/scripts/releases/README.md @@ -22,11 +22,6 @@ Updates relevant files in the `react-native` package and template to materialize Updates workspace dependencies in the template app`package.json` -### `validate-version` +### `create-release-commit` -Takes a version and a build type and validates whether the version passed is valid for the given build type -It is intended to use in CI - -### `compute-npm-tag` - -Takes a version, a branch and whether we want to explicitly tag the release as "latest" and outputs the most appropriate NPM tag for the release. +Creates a release commit to trigger a new release diff --git a/scripts/releases/compute-npm-tag.js b/scripts/releases/compute-npm-tag.js deleted file mode 100644 index 79616005b0d760..00000000000000 --- a/scripts/releases/compute-npm-tag.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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 - * @format - * @oncall react_native - */ - -const {parseVersion} = require('./utils/version-utils'); -const {parseArgs} = require('@pkgjs/parseargs'); - -const config = { - options: { - is_latest_on_npm: { - type: 'boolean', - short: 'l', - default: false, - }, - version: { - type: 'string', - short: 'v', - }, - branch: { - type: 'string', - short: 'b', - }, - help: {type: 'boolean'}, - }, -}; - -async function main() { - const { - values: {help, is_latest_on_npm: latest, version: version, branch: branch}, - } = parseArgs(config); - - if (help) { - console.log(` - Usage: node ./scripts/releases/compute-npm-tag.js [OPTIONS] - - Validates a version string for a given build type. - - Options: - --is-latest-on-npm Whether we need to publish this as latest on NPM or not. Defaults to false. - --version The new version string. - --branch The branch name. - `); - return; - } - - const {prerelease} = parseVersion(version, 'release'); - - const npmTag = latest ? 'latest' : !prerelease ? branch : 'next'; - - console.log(npmTag); - return; -} - -if (require.main === module) { - // eslint-disable-next-line no-void - void main(); -} diff --git a/scripts/releases/create-release-commit.js b/scripts/releases/create-release-commit.js new file mode 100644 index 00000000000000..9c01cf0f234b94 --- /dev/null +++ b/scripts/releases/create-release-commit.js @@ -0,0 +1,80 @@ +/** + * 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 + * @format + * @oncall react_native + */ + +const {getBranchName} = require('../scm-utils'); + +const yargs = require('yargs'); +const {setReactNativeVersion} = require('../releases/set-rn-version'); +const setVersion = require('../releases/set-version'); +const {parseVersion, validateBuildType} = require('./utils/version-utils'); +const {exec} = require('shelljs'); + +async function main() { + const argv = await yargs + .option('v', { + alias: 'reactNativeVersion', + describe: 'The new React Native version.', + type: 'string', + required: true, + }) + .option('l', { + alias: 'isLatestOnNpm', + describe: + 'Whether the version should be published as the latest version on npm.', + type: 'boolean', + default: false, + }) + .option('d', { + alias: 'dryRun', + description: 'Whether we should push the commit to github or not', + type: 'boolean', + default: true, + }).argv; + + const buildType = 'release'; + const version = argv.reactNativeVersion; + const latest = argv.isLatestOnNpm; + const dryRun = argv.dryRun; + const branch = getBranchName(); + console.info() + + console.info('Validating version', version); + const {prerelease} = parseVersion(version, buildType); + + const npmTag = latest ? 'latest' : prerelease ? 'next' : branch; + console.info('NPM tag:', npmTag); + + console.info('Setting version for monorepo packages'); + await setVersion(version, true); // version, skip-react-native + + console.info('Setting React Native version'); + await setReactNativeVersion(version, {}, buildType); // version, dependencyVersions, build-type + + if (dryRun) { + console.info('Running in dry-run mode, skipping git commit'); + console.info( + `git commit -a -m "Release ${version}" -m "#publish-packages-to-npm&${npmTag}"`, + ); + console.info(`git tag -a v${version} -m "v${version}"`); + return; + } + + console.info('Committing to git'); + exec( + `git commit -a -m "Release ${version}" -m "#publish-packages-to-npm&${npmTag}"`, + ); + exec(`git tag -a v${version} -m "v${version}"`); +} + +if (require.main === module) { + // eslint-disable-next-line no-void + void main(); +} diff --git a/scripts/releases/validate-version.js b/scripts/releases/validate-version.js deleted file mode 100644 index 5c29f5a3c4dde0..00000000000000 --- a/scripts/releases/validate-version.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * 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 - * @format - * @oncall react_native - */ - -const {parseVersion, validateBuildType} = require('./utils/version-utils'); -const {parseArgs} = require('@pkgjs/parseargs'); - -const config = { - options: { - 'build-type': { - type: 'string', - short: 'b', - }, - version: { - type: 'string', - short: 'v', - }, - help: {type: 'boolean'}, - }, -}; - -async function main() { - const { - values: {help, 'build-type': buildType, version: version}, - } = parseArgs(config); - - if (help) { - console.log(` - Usage: node ./scripts/releases/validate-version.js [OPTIONS] - - Validates a version string for a given build type. - - Options: - --build-type One of ['dry-run', 'nightly', 'release', 'prealpha']. - --version The new version string. - `); - return; - } - - if (!validateBuildType(buildType)) { - throw new Error(`Unsupported build type: ${buildType}`); - } - - parseVersion(version, 'release'); - - console.log(`Version ${version} is valid for ${buildType} build.`); - return; -} - -if (require.main === module) { - // eslint-disable-next-line no-void - void main(); -}