Skip to content

Commit

Permalink
fix: release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Mar 20, 2024
1 parent 41a7dbf commit f85b399
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
63 changes: 63 additions & 0 deletions scripts/monorepo/for-each-package.js
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 3 additions & 4 deletions scripts/oot-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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,
Expand All @@ -164,7 +163,7 @@ function releaseOOT(
.map(packagePath => {
echo(`Releasing ${packagePath}`);
const result = publishPackage(packagePath, {
tag,
tags: [tag],
otp: oneTimePassword,
});

Expand Down

0 comments on commit f85b399

Please sign in to comment.