From e6d8aab84258a4815db009e0fa1578ed565d350b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Wed, 20 Mar 2024 13:26:07 +0100 Subject: [PATCH] fix: release scripts --- scripts/monorepo/for-each-package.js | 63 ++++++++++++++++++++++++++++ scripts/oot-release.js | 7 ++-- 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 scripts/monorepo/for-each-package.js diff --git a/scripts/monorepo/for-each-package.js b/scripts/monorepo/for-each-package.js new file mode 100644 index 00000000000000..f3d865dfdacffd --- /dev/null +++ b/scripts/monorepo/for-each-package.js @@ -0,0 +1,63 @@ +/** + * 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. + * + * @format + */ + +const path = require('path'); +const {readdirSync, readFileSync} = require('fs'); + +const ROOT_LOCATION = path.join(__dirname, '..', '..'); +const PACKAGES_LOCATION = path.join(ROOT_LOCATION, 'packages'); + +const DEFAULT_OPTIONS = {includeReactNative: false}; + +/** + * Function, which returns an array of all directories inside specified location + * + * @param {string} source Path to directory, where this should be executed + * @returns {string[]} List of directories names + */ +const getDirectories = source => + readdirSync(source, {withFileTypes: true}) + .filter(file => file.isDirectory()) + .map(directory => directory.name); + +/** + * @callback forEachPackageCallback + * @param {string} packageAbsolutePath + * @param {string} packageRelativePathFromRoot + * @param {Object} packageManifest + */ + +/** + * Iterate through every package inside /packages (ignoring react-native) and call provided callback for each of them + * + * @param {forEachPackageCallback} callback The callback which will be called for each package + * @param {{includeReactNative: (boolean|undefined)}} [options={}] description + */ +const forEachPackage = (callback, options = DEFAULT_OPTIONS) => { + const {includeReactNative} = options; + + // We filter react-native package on purpose, so that no CI's script will be executed for this package in future + // Unless includeReactNative options is provided + const packagesDirectories = getDirectories(PACKAGES_LOCATION).filter( + directoryName => directoryName !== 'react-native' || includeReactNative, + ); + + packagesDirectories.forEach(packageDirectory => { + const packageAbsolutePath = path.join(PACKAGES_LOCATION, packageDirectory); + const packageRelativePathFromRoot = path.join('packages', packageDirectory); + + const packageManifest = JSON.parse( + readFileSync(path.join(packageAbsolutePath, 'package.json')), + ); + + callback(packageAbsolutePath, packageRelativePathFromRoot, packageManifest); + }); +}; + +module.exports = forEachPackage; diff --git a/scripts/oot-release.js b/scripts/oot-release.js index 2e9f216b6b3360..a385a88f27b732 100644 --- a/scripts/oot-release.js +++ b/scripts/oot-release.js @@ -9,8 +9,7 @@ const forEachPackage = require('./monorepo/for-each-package'); const newGithubReleaseUrl = require('./new-github-release-url'); const {applyPackageVersions, publishPackage} = require('./npm-utils'); -const {failIfTagExists} = require('./release-utils'); -const updateTemplatePackage = require('./update-template-package'); +const updateTemplatePackage = require('./releases/update-template-package'); const {execSync} = require('child_process'); const fs = require('fs'); const path = require('path'); @@ -94,6 +93,7 @@ function releaseOOT( oneTimePassword, tag = 'latest', ) { + console.log('Releasing visionOS packages with tag: ', tag); const isNightly = tag === 'nightly'; const allPackages = getPackages(); const corePackages = Object.keys(allPackages).filter(packageName => @@ -150,7 +150,6 @@ function releaseOOT( } const gitTag = `v${newVersion}-visionos`; - failIfTagExists(gitTag, 'release'); // Create git tag execSync(`git tag -a ${gitTag} -m "Release ${newVersion}"`, { cwd: REPO_ROOT, @@ -164,7 +163,7 @@ function releaseOOT( .map(packagePath => { echo(`Releasing ${packagePath}`); const result = publishPackage(packagePath, { - tag, + tags: [tag], otp: oneTimePassword, });