Skip to content

Commit

Permalink
Add beachball change transformer (#9488)
Browse files Browse the repository at this point in the history
* Add beachball change transformer

Beachball has a relatively recent option, which allows modifying changefiles before trying to bump/publish. We can use this to workaround two common painpoints.

1. Changes backported to 0.69 and later will not need any modification to changefiles when cherry-picking.
2. We do some formatting to create consistency of omiting the version in change messages in our changelogs

* Remove stale file

* Change files

* Fix bug around missing packages

* Fuller JS env in setup

* Simplify logic

* Fix template path

* use remote midgard-yarn on ubuntu agent

* yaml

* Build more

* Move beachball config to its own package

* Consistency

* Cleanup yarn install logic for hosted vs managed images

* Fixup lockfile issues

* Update min to node 14

* Import shared variables and rename

* Variable fixup
  • Loading branch information
NickGerleman authored Feb 12, 2022
1 parent e8f0f0d commit dfc6ca9
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 121 deletions.
24 changes: 5 additions & 19 deletions .ado/jobs/macos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,16 @@
jobs:
- job: MacTests
displayName: macOS Tests

variables:
- template: ../variables/macos.yml

pool:
vmImage: $(VmImage)

timeoutInMinutes: 20 # how long to run the job before automatically cancelling
cancelTimeoutInMinutes: 5 # how much time to give 'run always even if cancelled tasks' before killing them
timeoutInMinutes: 20
variables: [template: ../variables/shared.yml]
pool: {vmImage: macOS-10.15}

steps:
- template: ../templates/checkout-shallow.yml

# Explicitly set Node version and install midgard-yarn since we are
# running on a public pool
- task: NodeTool@0
displayName: Set Node Version
inputs:
versionSpec: '16.x'

- script: npm install -g [email protected]
displayName: Install midgard-yarn

- template: ../templates/prepare-js-env.yml
parameters:
agentImage: HostedImage

- script: yarn test
displayName: yarn test
Expand Down
16 changes: 11 additions & 5 deletions .ado/jobs/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ parameters:

jobs:
- job: Setup
timeoutInMinutes: 3
pool:
vmImage: ubuntu-latest
displayName: Setup
timeoutInMinutes: 3 # Kill the job early to catch Beachball hangs
variables: [template: ../variables/shared.yml]
pool: {vmImage: ubuntu-latest}

steps:
- template: ../templates/checkout-full.yml

Expand All @@ -18,8 +20,12 @@ jobs:

- template: ../templates/compute-beachball-branch-name.yml

- script: npm install -g [email protected]
displayName: Install beachball
- template: ../templates/yarn-install.yml
parameters:
agentImage: HostedImage

- script: npx lage build --scope @rnw-scripts/beachball-config --no-deps
displayName: Minimal build

- ${{ if eq(parameters.buildEnvironment, 'PullRequest') }}:
- script: npx beachball check --branch origin/$(BeachBallBranchName) --verbose --changehint "##vso[task.logissue type=error]Run `yarn change` from root of repo to generate a change file."
Expand Down
16 changes: 15 additions & 1 deletion .ado/templates/prepare-js-env.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Steps to setup an environment that can run JavaScript executables
parameters:
- name: agentImage
type: string
default: ManagedImage
values:
- ManagedImage
- HostedImage

steps:
- ${{ if eq(parameters.agentImage, 'HostedImage') }}:
- task: NodeTool@0
displayName: Set Node Version
inputs:
versionSpec: '16.x'

- template: yarn-install.yml
parameters:
agentImage: ${{ parameters.agentImage }}

- script: yarn build
displayName: yarn build
19 changes: 13 additions & 6 deletions .ado/templates/yarn-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ parameters:
- name: workingDirectory
type: string
default: .
- name: frozenLockfile
type: boolean
default: true
- name: agentImage
type: string
default: ManagedImage
values:
- ManagedImage
- HostedImage

steps:
- ${{ if eq(parameters.frozenLockfile, true) }}:
# When using our own images, prefer the machine-installed version of
# `midgard-yarn`.
- ${{ if eq(parameters.agentImage, 'ManagedImage') }}:
- script: midgard-yarn --frozen-lockfile --cwd ${{ parameters.workingDirectory }}
displayName: midgard-yarn (faster yarn install)

- ${{ if eq(parameters.frozenLockfile, false) }}:
- script: midgard-yarn --cwd ${{ parameters.workingDirectory }}
# If using an image we don't control, acquire a fixed version of midgard-yarn
# before install
- ${{ else }}:
- script: npx --yes [email protected] --frozen-lockfile --cwd ${{ parameters.workingDirectory }}
displayName: midgard-yarn (faster yarn install)
5 changes: 0 additions & 5 deletions .ado/variables/macos.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@ nul
.verdaccio-db.json

# Graveyard of old packages (whose build-outputs may exist on disk after pull)
/packages/@rnw-bots/*
/packages/jest-environment-winappdriver/*
/packages/node-rnw-rpc/*
2 changes: 2 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"orta.vscode-jest",
"ms-azure-devops.azure-pipelines",
"streetsidesoftware.code-spell-checker",
]
}
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"files.exclude": {
"**/.git": true
},
"files.associations": {
"**/.ado/**/*.yml": "azure-pipelines"
},
"search.exclude": {
"**/node_modules": true,
"**/lib": true,
"**/dist": true
"**/lib/**/*.js": true,
"**/dist/**/*.js": true
},
"editor.formatOnSave": true,
"eslint.format.enable": true,
Expand Down
27 changes: 1 addition & 26 deletions beachball.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
* @format
* @ts-check
*/

const {execSync} = require('child_process');

module.exports = {
...require(`${__dirname}/packages/@rnw-scripts/generated-beachball-config/beachball.config.g.json`),

// Do not generate tags for monorepo packages by default, to avoid a GitHub
// release for every package.
gitTags: false,

hooks: {
// Stamp versions when we publish a new package
postbump: (_packagePath, name, version) => {
if (name === 'react-native-windows') {
console.log(`Stamping RNW Version ${version}`);
execSync(`yarn stamp-version ${version}`);
}
}
}
}
module.exports = require("@rnw-scripts/beachball-config");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Sync variants",
"packageName": "@react-native-windows/find-repo-root",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Sync variants",
"packageName": "@react-native-windows/package-utils",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 0 additions & 7 deletions change/node-rnw-rpc-6fae19ab-7d3e-488e-83c6-cb979474aebb.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/@react-native-windows/find-repo-root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"directory": "packages/@react-native-windows/find-repo-root"
},
"dependencies": {
"@react-native-windows/fs": "^1.0.1",
"find-up": "^4.1.0"
},
"devDependencies": {
Expand Down
28 changes: 26 additions & 2 deletions packages/@react-native-windows/find-repo-root/src/findRepoRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

import findUp from 'find-up';
import fs from '@react-native-windows/fs';
import path from 'path';

/**
* Find the root directory of a repo upward from cwd
*/
export default async (): Promise<string> => {
async function findRepoRoot(): Promise<string> {
const root = await findUp(
async (dir: string): Promise<findUp.Match> => {
return (await findUp.exists(path.join(dir, '.git'))) ? dir : undefined;
Expand All @@ -27,4 +28,27 @@ export default async (): Promise<string> => {
}

return root;
};
}

/**
* Synchronously finds the root directory of a repo upward from cwd
*/
function findRepoRootSync(): string {
const root = findUp.sync(
(dir: string): findUp.Match => {
return fs.existsSync(path.join(dir, '.git')) ? dir : undefined;
},
{type: 'directory'},
);

if (!root) {
throw new Error(
'Unable to find the root of react-native-windows. Are you running within the repo?',
);
}

return root;
}

const exportObj = Object.assign(findRepoRoot, {sync: findRepoRootSync});
export default exportObj;
30 changes: 30 additions & 0 deletions packages/@react-native-windows/package-utils/src/packageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ export async function enumerateRepoPackages(
return filteredPackages;
}

/**
* Synchronously Finds monorepo-local packages matching a given predicate. The
* root package is not included.
*
* @param pred predicate describing whether to match a package
*/
export function enumerateRepoPackagesSync(
pred: (pkg: NpmPackage) => boolean = () => true,
): WritableNpmPackage[] {
const repoRoot = findRepoRoot.sync();
const allPackges = getMonorepoPackages(repoRoot).map(
(pkg) => new WritableNpmPackage(pkg.location, pkg.package),
);

return allPackges.filter(pred);
}

/**
* Finds a package with a given name (local or dependency)
*/
Expand Down Expand Up @@ -164,3 +181,16 @@ export async function findRepoPackage(
return packages[0];
}
}

/**
* Synchronously a monorepo-local package with a given name
*/
export function findRepoPackageSync(name: string): WritableNpmPackage | null {
const packages = enumerateRepoPackagesSync((p) => p.json.name === name);

if (packages.length === 0) {
return null;
} else {
return packages[0];
}
}

This file was deleted.

This file was deleted.

This file was deleted.

38 changes: 0 additions & 38 deletions packages/@rnw-bots/coordinator/package.json

This file was deleted.

2 changes: 2 additions & 0 deletions packages/@rnw-scripts/beachball-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
lib-commonjs/
41 changes: 41 additions & 0 deletions packages/@rnw-scripts/beachball-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@rnw-scripts/beachball-config",
"private": true,
"version": "0.0.0",
"license": "MIT",
"scripts": {
"build": "rnw-scripts build",
"clean": "rnw-scripts clean",
"lint": "rnw-scripts lint",
"lint:fix": "rnw-scripts lint:fix",
"watch": "rnw-scripts watch"
},
"main": "lib-commonjs/beachball.config.js",
"repository": {
"type": "git",
"url": "https://github.com/microsoft/react-native-windows.git",
"directory": "packages/@rnw-scripts/beachball-config"
},
"dependencies": {
"@react-native-windows/package-utils": "0.0.0-canary.25",
"@rnw-scripts/stamp-version": "0.0.0",
"find-up": "^4.1.0"
},
"devDependencies": {
"@rnw-scripts/eslint-config": "1.1.11",
"@rnw-scripts/just-task": "2.2.3",
"@rnw-scripts/ts-config": "2.0.2",
"@types/node": "^14.14.22",
"beachball": "^2.20.0",
"eslint": "^7.32.0",
"just-scripts": "^1.3.3",
"prettier": "^2.4.1",
"typescript": "^4.4.4"
},
"files": [
"lib-commonjs"
],
"engines": {
"node": ">= 14.0.0"
}
}
Loading

0 comments on commit dfc6ca9

Please sign in to comment.