Skip to content

Commit

Permalink
chore: organize scripts into separate folders (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Aug 21, 2024
1 parent 60b9cf8 commit 4808d0b
Show file tree
Hide file tree
Showing 33 changed files with 114 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/actions/init-test-app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
steps:
- name: Install
run: |
scripts/install-test-template.sh ${{ inputs.platform }}
scripts/build/install-test-template.sh ${{ inputs.platform }}
shell: bash
- name: Initialize a new app
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- scripts/embed-manifest/validate.mjs
- scripts/init.mjs
- scripts/template.mjs
- scripts/xcodebuild.sh
- scripts/build/xcodebuild.sh
- test_app.rb
"platform: macOS":
- changed-files:
Expand Down Expand Up @@ -63,7 +63,7 @@
- scripts/embed-manifest/validate.mjs
- scripts/init.mjs
- scripts/template.mjs
- scripts/xcodebuild.sh
- scripts/build/xcodebuild.sh
"platform: visionOS":
- changed-files:
- any-glob-to-any-file:
Expand All @@ -84,7 +84,7 @@
- scripts/embed-manifest/validate.mjs
- scripts/init.mjs
- scripts/template.mjs
- scripts/xcodebuild.sh
- scripts/build/xcodebuild.sh
- visionos/**/*
"platform: Windows":
- changed-files:
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
# TODO: GITHUB_TOKEN is not set if a PR comes from a forked repo.
# Ignore errors until we can create a GitHub PAT from a system
# account.
scripts/clang-format-diff.sh || true
scripts/build/clang-format-diff.sh || true
- name: CocoaPods
if: ${{ runner.os == 'macOS' }}
run: |
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
- name: Build
if: ${{ steps.affected.outputs.ios != '' }}
run: |
../scripts/xcodebuild.sh ios/Example.xcworkspace build-for-testing
../scripts/build/xcodebuild.sh ios/Example.xcworkspace build-for-testing
working-directory: example
- name: Test `react-native config`
if: ${{ steps.affected.outputs.ios != '' }}
Expand All @@ -193,7 +193,7 @@ jobs:
- name: Test
if: ${{ steps.affected.outputs.ios != '' }}
run: |
../scripts/xcodebuild.sh ios/Example.xcworkspace test-without-building
../scripts/build/xcodebuild.sh ios/Example.xcworkspace test-without-building
working-directory: example
timeout-minutes: 60
ios-template:
Expand Down Expand Up @@ -243,12 +243,12 @@ jobs:
- name: Build
if: ${{ steps.affected.outputs.ios != '' }}
run: |
../scripts/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
working-directory: template-example
- name: react-native run-ios
if: ${{ steps.affected.outputs.ios != '' }}
run: |
../scripts/react-native.mjs run-ios
../scripts/testing/react-native.mjs run-ios
working-directory: template-example
timeout-minutes: 60
android:
Expand Down Expand Up @@ -335,7 +335,7 @@ jobs:
- name: react-native run-android
if: ${{ steps.affected.outputs.android != '' }}
run: |
../scripts/react-native.mjs run-android
../scripts/testing/react-native.mjs run-android
working-directory: template-example
timeout-minutes: 60
macos:
Expand Down Expand Up @@ -379,7 +379,7 @@ jobs:
- name: Build x86
if: ${{ steps.affected.outputs.macos != '' }}
run: |
../scripts/xcodebuild.sh macos/Example.xcworkspace build-for-testing
../scripts/build/xcodebuild.sh macos/Example.xcworkspace build-for-testing
working-directory: example
- name: Test `react-native config`
if: ${{ steps.affected.outputs.macos != '' }}
Expand All @@ -390,7 +390,7 @@ jobs:
# Temporarily disabled due to random failures
if: false # ${{ steps.affected.outputs.macos != '' && github.event_name != 'schedule' }}
run: |
../scripts/xcodebuild.sh macos/Example.xcworkspace test-without-building
../scripts/build/xcodebuild.sh macos/Example.xcworkspace test-without-building
working-directory: example
- name: Prepare for arm64 build
if: ${{ steps.affected.outputs.macos != '' }}
Expand All @@ -406,7 +406,7 @@ jobs:
- name: Build arm64
if: ${{ steps.affected.outputs.macos != '' }}
run: |
../scripts/xcodebuild.sh macos/Example.xcworkspace build ARCHS=arm64
../scripts/build/xcodebuild.sh macos/Example.xcworkspace build ARCHS=arm64
working-directory: example
timeout-minutes: 60
macos-template:
Expand Down Expand Up @@ -456,7 +456,7 @@ jobs:
- name: Build
if: ${{ steps.affected.outputs.macos != '' }}
run: |
../scripts/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
working-directory: template-example
timeout-minutes: 60
visionos:
Expand Down Expand Up @@ -501,7 +501,7 @@ jobs:
- name: Build
if: ${{ steps.affected.outputs.visionos != '' }}
run: |
../scripts/xcodebuild.sh visionos/Example.xcworkspace build-for-testing
../scripts/build/xcodebuild.sh visionos/Example.xcworkspace build-for-testing
working-directory: example
- name: Test `react-native config`
if: ${{ steps.affected.outputs.visionos != '' }}
Expand Down Expand Up @@ -557,7 +557,7 @@ jobs:
- name: Build
if: ${{ steps.affected.outputs.visionos != '' }}
run: |
../scripts/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
working-directory: template-example
timeout-minutes: 60
windows:
Expand Down Expand Up @@ -612,8 +612,8 @@ jobs:
- name: Test
if: ${{ steps.affected.outputs.windows != '' && matrix.platform == 'x64' }}
run: |
../../../scripts/MSBuild.ps1 -Configuration ${{ matrix.configuration }} -Platform ${{ matrix.platform }} -Target Build ReactAppTests.vcxproj
../../../scripts/VSTest.ps1 ${{ matrix.platform }}\${{ matrix.configuration }}\ReactAppTests.dll
../../../scripts/build/MSBuild.ps1 -Configuration ${{ matrix.configuration }} -Platform ${{ matrix.platform }} -Target Build ReactAppTests.vcxproj
../../../scripts/build/VSTest.ps1 ${{ matrix.platform }}\${{ matrix.configuration }}\ReactAppTests.dll
working-directory: example/windows/ReactAppTests
timeout-minutes: 60
windows-template:
Expand Down
9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,8 @@ the template we currently use:
> - Fix #2
Make sure you're on latest `trunk`, then run
`node scripts/release-notes.mjs <last version> <this version>` to get a list of
user-facing changes. You will likely need to prune and rewrite some of these
entries.
`yarn release-notes <last version> <this version>` to get a list of user-facing
changes. You will likely need to prune and rewrite some of these entries.

<!-- References -->

Expand All @@ -380,15 +379,15 @@ entries.
[`dependencies.gradle`]:
https://github.com/microsoft/react-native-test-app/blob/trunk/android/dependencies.gradle
[`generate-schema.mjs`]:
https://github.com/microsoft/react-native-test-app/blob/trunk/scripts/generate-schema.mjs
https://github.com/microsoft/react-native-test-app/blob/trunk/scripts/internal/generate-schema.mjs
[`package.json`]:
https://github.com/microsoft/react-native-test-app/blob/trunk/package.json
[`react-native-releases`]:
https://github.com/reactwg/react-native-releases/discussions
[`scripts/docs/`]:
https://github.com/microsoft/react-native-test-app/tree/trunk/scripts/docs
[`test:matrix`]:
https://github.com/microsoft/react-native-test-app/blob/trunk/scripts/test-matrix.mjs
https://github.com/microsoft/react-native-test-app/blob/trunk/scripts/testing/test-matrix.mjs
[`uuid`]: https://github.com/uuidjs/uuid
[commitlint-lite]:
https://github.com/microsoft/rnx-kit/tree/main/incubator/commitlint-lite#readme
Expand Down
16 changes: 12 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,25 @@ module.exports = [
},
{
files: [
"scripts/set-react-version.mjs",
"scripts/test-e2e.mjs",
"scripts/test-matrix.mjs",
"scripts/internal/generate-manifest-docs.mjs",
"scripts/internal/generate-manifest.mjs",
"scripts/internal/generate-schema.mjs",
"scripts/internal/pack.mjs",
"scripts/internal/set-react-version.mjs",
"scripts/internal/test.mjs",
"scripts/schema.mjs",
"scripts/testing/test-apple.mjs",
"scripts/testing/test-e2e.mjs",
"scripts/testing/test-matrix.mjs",
"scripts/utils/colors.mjs",
],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["[a-z]*", "!./*", "!./utils/*", "!node:*"],
group: ["[a-z]*", "!../**", "!./**", "!node:*", "!node:*/**"],
message:
"External dependencies are not allowed in this file because it needs to be runnable before install.",
},
Expand Down
29 changes: 12 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@
"react-native.config.js",
"schema.json",
"scripts/*.js",
"scripts/apply-config-plugins.mjs",
"scripts/colors.mjs",
"scripts/*.mjs",
"scripts/config-plugins",
"scripts/configure.mjs",
"scripts/embed-manifest",
"scripts/init.mjs",
"scripts/parseargs.mjs",
"scripts/schema.mjs",
"scripts/template.mjs",
"scripts/utils/npm.mjs",
"scripts/utils",
"test-app.gradle",
"test_app.rb",
"visionos",
Expand All @@ -75,21 +69,22 @@
"format:c": "clang-format -i $(git ls-files '*.cpp' '*.h' '*.m' '*.mm')",
"format:js": "prettier --write --log-level error $(git ls-files '*.[cm]js' '*.[jt]s' '*.tsx' '*.yml' 'CONTRIBUTING.md' 'README.md' 'test/**/*.json' ':!:.yarn/releases')",
"format:swift": "swiftformat $(git ls-files '*.swift')",
"generate:code": "node scripts/generate-manifest.mjs",
"generate:docs": "node scripts/generate-manifest-docs.mjs",
"generate:schema": "node scripts/generate-schema.mjs",
"generate:code": "node scripts/internal/generate-manifest.mjs",
"generate:docs": "node scripts/internal/generate-manifest-docs.mjs",
"generate:schema": "node scripts/internal/generate-schema.mjs",
"lint:commit": "git log --format='%s' origin/trunk..HEAD | tail -1 | npx @rnx-kit/commitlint-lite@1.0.1",
"lint:js": "eslint $(git ls-files '*.[cm]js' '*.[jt]s' '*.tsx' ':!:*.config.js' ':!:.yarn/releases') && tsc && tsc --project tsconfig.cjs.json",
"lint:kt": "ktlint --relative 'android/app/src/**/*.kt'",
"lint:rb": "bundle exec rubocop",
"lint:swift": "swiftlint",
"prepack": "node scripts/pack.mjs pre",
"postpack": "node scripts/pack.mjs post",
"set-react-version": "node scripts/set-react-version.mjs",
"show-affected": "node scripts/affected.mjs",
"test": "node scripts/test.mjs",
"prepack": "node scripts/internal/pack.mjs pre",
"postpack": "node scripts/internal/pack.mjs post",
"release-notes": "node scripts/internal/release-notes.mjs",
"set-react-version": "node scripts/internal/set-react-version.mjs",
"show-affected": "node --import tsx scripts/build/affected.ts",
"test": "node scripts/internal/test.mjs",
"test:js": "node --import tsx --test $(git ls-files '*.test.ts')",
"test:matrix": "node scripts/test-matrix.mjs",
"test:matrix": "node scripts/testing/test-matrix.mjs",
"test:rb": "bundle exec ruby -Ilib:test -e \"Dir.glob('./test/test_*.rb').each { |file| require(file) }\""
},
"dependencies": {
Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 13 additions & 30 deletions scripts/affected.mjs → scripts/build/affected.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
// @ts-check
import yaml from "js-yaml";
import { Minimatch } from "minimatch";
import { spawnSync } from "node:child_process";
import * as fs from "node:fs";

/**
* @typedef {import("./types.js").Match} Match
*/
type MatchChangedFiles = { "any-glob-to-any-file": string[] };
type Match = { "changed-files": MatchChangedFiles[] };

/**
* Cleans up the given array.
* @param {string[]} platforms
*/
function clean(platforms) {
function clean(platforms: string[]): string[] {
return platforms.map((p) => p.toLowerCase()).sort();
}

/**
* Executes a Git command.
* @param {...string} args
* @returns {string}
*/
function git(...args) {
function git(...args: string[]): string {
const { stderr, stdout } = spawnSync("git", args);
const message = stderr.toString().trim();
if (message) {
Expand All @@ -32,9 +27,8 @@ function git(...args) {

/**
* Returns the default Git branch.
* @returns {string}
*/
function getDefaultBranch() {
function getDefaultBranch(): string {
if (process.env["CI"]) {
// CIs don't clone the repo, but use a different way to checkout a branch.
// This means that `origin/HEAD` is never created, which in turn means that
Expand All @@ -52,10 +46,8 @@ function getDefaultBranch() {

/**
* Returns the commit from which this branch was forked.
* @param {string | undefined} targetBranch
* @returns {string}
*/
function getBaseCommit(targetBranch) {
function getBaseCommit(targetBranch: string | undefined): string {
targetBranch =
!targetBranch || targetBranch.endsWith("/")
? getDefaultBranch()
Expand All @@ -69,10 +61,8 @@ function getBaseCommit(targetBranch) {

/**
* Returns changed files since fork point.
* @param {string} since
* @returns {string[]}
*/
function getChangedFiles(since) {
function getChangedFiles(since: string): string[] {
const changedFiles = git("diff", "--name-only", since);
if (!changedFiles) {
return [];
Expand All @@ -82,21 +72,17 @@ function getChangedFiles(since) {

/**
* Loads labels from Pull Request Labeler action configuration.
* @see {@link https://github.com/actions/labeler}
* @returns {Record<string, Match[] | undefined>}
*/
function loadLabels() {
function loadLabels(): Record<string, Match[] | undefined> {
const yml = fs.readFileSync(".github/labeler.yml", { encoding: "utf-8" });
return /** @type {Record<string, Match[] | undefined>} */ (yaml.load(yml));
return yaml.load(yml) as Record<string, Match[] | undefined>;
}

/**
* Makes platform specific file path matchers.
* @returns {Record<string, Minimatch[]>}
*/
function makeMatchers() {
/** @type {Record<string, Minimatch[]>} */
const matchers = {};
function makeMatchers(): Record<string, Minimatch[]> {
const matchers: Record<string, Minimatch[]> = {};
const options = { dot: true };
const labels = loadLabels();

Expand All @@ -115,10 +101,8 @@ function makeMatchers() {

/**
* Returns platforms affected by changed files.
* @param {string | undefined} targetBranch
* @returns {string[]}
*/
function getAffectedPlatforms(targetBranch) {
function getAffectedPlatforms(targetBranch: string | undefined): string[] {
const platformMatchers = makeMatchers();

const baseCommit = getBaseCommit(targetBranch);
Expand All @@ -142,8 +126,7 @@ function getAffectedPlatforms(targetBranch) {
}
}

/** @type {Set<string>} */
const affectedPlatforms = new Set();
const affectedPlatforms = new Set<string>();
for (const [platform, matchers] of Object.entries(platformMatchers)) {
if (matchers.some((m) => changedFiles.some((f) => m.match(f)))) {
affectedPlatforms.add(platform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eo pipefail

if [[ -z $DEBUG ]]; then
brew install clang-format
curl --silent --show-error --remote-name https://raw.githubusercontent.com/llvm/llvm-project/release/14.x/clang/tools/clang-format/clang-format-diff.py
curl --silent --show-error --remote-name https://raw.githubusercontent.com/llvm/llvm-project/release/18.x/clang/tools/clang-format/clang-format-diff.py
fi
git diff --unified=0 --no-color @^ \
| python clang-format-diff.py -p1 -regex '.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hh|hpp|m|mm|inc)' -sort-includes \
Expand Down
File renamed without changes.
Loading

0 comments on commit 4808d0b

Please sign in to comment.