From ed665a0eaee09cbac94449b81b10b836211f7838 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Fri, 21 Jun 2024 11:36:59 -0400 Subject: [PATCH] [ci] Parallelize flow github action The existing flow-ci script makes some assumptions about running inside of circleci for parallelization. This PR forks the script with very smal ll tweaks to allow for a short name to be passed in as an argument. These short names are discovered in a new GH job and then each one is passed as an argument for parallelization ghstack-source-id: 8676079eebda8d5d14129c752ff6e59574357b47 Pull Request resolved: https://github.com/facebook/react/pull/30026 --- .github/workflows/flow.yml | 26 +++++++++++++++++++++++--- scripts/tasks/flow-ci-ghaction.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 scripts/tasks/flow-ci-ghaction.js diff --git a/.github/workflows/flow.yml b/.github/workflows/flow.yml index b1943302764c7..115726b45f2a4 100644 --- a/.github/workflows/flow.yml +++ b/.github/workflows/flow.yml @@ -6,9 +6,28 @@ on: pull_request: jobs: - flow: - name: Run flow + discover_flow_inline_configs: + name: Discover flow inline configs runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.result }} + steps: + - uses: actions/checkout@v4 + - uses: actions/github-script@v7 + id: set-matrix + with: + script: | + const inlinedHostConfigs = require('./scripts/shared/inlinedHostConfigs.js'); + return inlinedHostConfigs.map(config => config.shortName); + + Flow: + name: Flow check ${{ matrix.flow_inline_config_shortname }} + needs: discover_flow_inline_configs + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + flow_inline_config_shortname: ${{ fromJSON(needs.discover_flow_inline_configs.outputs.matrix) }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -18,8 +37,9 @@ jobs: cache-dependency-path: yarn.lock - name: Restore cached node_modules uses: actions/cache@v4 + id: node_modules with: path: "**/node_modules" key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }} - run: yarn install --frozen-lockfile - - run: node ./scripts/tasks/flow-ci + - run: node ./scripts/tasks/flow-ci-ghaction ${{ matrix.flow_inline_config_shortname }} diff --git a/scripts/tasks/flow-ci-ghaction.js b/scripts/tasks/flow-ci-ghaction.js new file mode 100644 index 0000000000000..f420c80c37562 --- /dev/null +++ b/scripts/tasks/flow-ci-ghaction.js @@ -0,0 +1,30 @@ +/** + * 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. + */ + +'use strict'; + +process.on('unhandledRejection', err => { + throw err; +}); + +const runFlow = require('../flow/runFlow'); +const inlinedHostConfigs = require('../shared/inlinedHostConfigs'); + +async function check(shortName) { + if (shortName == null) { + throw new Error('Expected an inlinedHostConfig shortName'); + } + const rendererInfo = inlinedHostConfigs.find( + config => config.shortName === shortName + ); + if (rendererInfo.isFlowTyped) { + await runFlow(rendererInfo.shortName, ['check']); + console.log(); + } +} + +check(process.argv[2]);