Skip to content

Commit

Permalink
Refactor scripts into a single one
Browse files Browse the repository at this point in the history
  • Loading branch information
cipolleschi committed Jun 12, 2024
1 parent 035af74 commit 66ce55a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 180 deletions.
29 changes: 29 additions & 0 deletions .github/actions/create-release/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}" \
--tagAsLatestRelease "${{ 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
45 changes: 0 additions & 45 deletions .github/actions/prepare_release/action.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
9 changes: 2 additions & 7 deletions scripts/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
64 changes: 0 additions & 64 deletions scripts/releases/compute-npm-tag.js

This file was deleted.

73 changes: 73 additions & 0 deletions scripts/releases/create-release-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* 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 {execSync} = require('child_process');
const {getBranchName} = require('../scm-utils');
const yargs = require('yargs');
const {setReactNativeVersion} = require('../releases/set-rn-version');
const setVersion = require('../releases/set-version');
const {parseVersion} = require('./utils/version-utils');

async function main() {
const argv = await yargs
.option('reactNativeVersion', {
describe: 'The new React Native version.',
type: 'string',
required: true,
})
.option('tagAsLatestRelease', {
describe:
'Whether the version should be published as the latest version on npm.',
type: 'boolean',
default: false,
})
.option('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.tagAsLatestRelease;
const dryRun = argv.dryRun;
const branch = getBranchName();
console.info(`Running on branch: ${branch}`);

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

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');
execSync(
`git commit -a -m "Release ${version}" -m "#publish-packages-to-npm&${npmTag}"`,
);
execSync(`git tag -a v${version} -m "v${version}"`);
}

if (require.main === module) {
// eslint-disable-next-line no-void
void main();
}
60 changes: 0 additions & 60 deletions scripts/releases/validate-version.js

This file was deleted.

0 comments on commit 66ce55a

Please sign in to comment.