diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d39ba576fc..45ddc3cce8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,5 @@ +name: CI + on: # Postsubmit CI on main. push: @@ -77,25 +79,12 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - # Install dependencies - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 - # Switch flavor if necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable + - name: Install Dependencies + id: install-dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - name: Check result of flavor switch - if: ${{ always() && steps.switch-flavor.outcome == 'failure' }} - run: echo "Failed to switch to stable flavor, please make sure you run 'rush update:stable' if dependencies were updated." && exit 1 - + if: ${{ always() && steps.install-dependencies.outcome == 'failure' }} + run: echo "Failed to install dependencies, please make sure you run `rush update:all-flavors` if dependencies were updated." && exit 1 - name: Check the necessary change file has been submitted if: ${{ github.event_name == 'pull_request' }} run: | @@ -169,20 +158,9 @@ jobs: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} # Install dependencies - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 - # Switch flavor if necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} + # Build and test - name: Build Packages run: rush build -t @azure/communication-react - name: Test Packages @@ -275,17 +253,9 @@ jobs: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} # Install dependencies - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies + - name: Install Dependencies if: ${{ matrix.flavor == 'beta-release'}} - run: rush install --max-install-attempts 3 - # Switch flavor if necessary - - name: Switch flavor for beta-release build - id: switch-flavor - if: ${{ matrix.flavor == 'beta-release'}} - run: | - rush switch-flavor:beta-release + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} # Perform lint check - name: Run linter if: ${{ matrix.flavor == 'beta-release'}} @@ -334,23 +304,12 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - uses: browser-actions/setup-chrome@v1 id: setup-chrome with: chrome-version: 120.0.6099 - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable - name: Build Call Composite Test App run: | cd packages/react-composites @@ -414,23 +373,12 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - uses: browser-actions/setup-chrome@v1 id: setup-chrome with: chrome-version: 120.0.6099 - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable - name: Build Chat Composite Test App run: | cd packages/react-composites @@ -494,23 +442,12 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - uses: browser-actions/setup-chrome@v1 id: setup-chrome with: chrome-version: 120.0.6099 - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable - name: Build CallWithChatComposite Test App run: | cd packages/react-composites @@ -571,23 +508,12 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - uses: browser-actions/setup-chrome@v1 id: setup-chrome with: chrome-version: 120.0.6099 - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable # Build the packages # This is needed because react-components depends on acs-ui-common and # acs-ui-common specifies main/module variables in package.json @@ -638,11 +564,9 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies + - name: Install Dependencies if: ${{ matrix.flavor == 'beta' || matrix.flavor == 'beta-release'}} - run: rush install --max-install-attempts 3 + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - name: Build if: ${{ matrix.flavor == 'beta' || matrix.flavor == 'beta-release' }} run: rush build -o storybook @@ -703,20 +627,8 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 - # Switch flavor if necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - name: Build dependencies run: rush build -t @azure/communication-react - name: Build @@ -749,20 +661,8 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 - # Switch flavor if necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - name: Build dependencies run: rush build -t @azure/communication-react - name: Build @@ -795,20 +695,8 @@ jobs: with: path: common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }} - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 - # Switch flavor if necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - name: Build dependencies run: rush build -t @azure/communication-react - name: Build @@ -838,24 +726,12 @@ jobs: uses: actions/setup-node@v4 with: node-version: 'lts/*' - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - uses: browser-actions/setup-chrome@v1 id: setup-chrome with: chrome-version: 120.0.6099 - # Switch flavor if necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable - name: Build run: rush build -t sample-static-html-composites - name: Visual Regression Tests @@ -902,24 +778,12 @@ jobs: uses: actions/setup-node@v4 with: node-version: 'lts/*' - - name: Install rush - run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json") - - name: Install dependencies - run: rush install --max-install-attempts 3 + - name: Install Dependencies + run: node ./common/scripts/install-dependencies-ci.mjs ${{ matrix.flavor }} - uses: browser-actions/setup-chrome@v1 id: setup-chrome with: chrome-version: 120.0.6099 - # Switch flavor when necessary - - name: Switch flavor for build - id: switch-flavor - if: ${{ matrix.flavor != 'beta' }} - run: | - rush switch-flavor:${{ matrix.flavor }} - node ./common/scripts/force-build-flavor.mjs ${{ matrix.flavor }} - - name: Run dependency update for stable - if: ${{ matrix.flavor == 'stable' }} - run: rush update:stable - name: Build run: rush build -t component-examples - name: Visual Regression Tests diff --git a/change/@azure-communication-react-bb221623-4baf-4501-bf5e-d994e842aee7.json b/change/@azure-communication-react-bb221623-4baf-4501-bf5e-d994e842aee7.json new file mode 100644 index 0000000000..647b506b40 --- /dev/null +++ b/change/@azure-communication-react-bb221623-4baf-4501-bf5e-d994e842aee7.json @@ -0,0 +1,9 @@ +{ + "type": "none", + "area": "improvement", + "workstream": "CI", + "comment": "Run rush switch-flavor as the install command to prevent multiple installs being called", + "packageName": "@azure/communication-react", + "email": "2684369+JamesBurnside@users.noreply.github.com", + "dependentChangeType": "none" +} diff --git a/common/scripts/install-dependencies-ci.mjs b/common/scripts/install-dependencies-ci.mjs new file mode 100644 index 0000000000..64b3623f44 --- /dev/null +++ b/common/scripts/install-dependencies-ci.mjs @@ -0,0 +1,39 @@ +#!/usr/bin/env node +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/// +/// This script is used to run install dependency commands in CI. +/// `yml` files are not good at reusing commands, so this script helps us to write-once and reuse. +/// + +import { execSync } from 'child_process'; +import fs from 'fs'; +import { fileURLToPath } from 'url'; +import { resolve, dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +async function main(args) { + const flavor = args[2]; + if (!flavor) { + throw new Error('Usage: node install-dependencies-ci.mjs '); + } + + // Install rush based on the version in rush.json. + // If we do not install that specific version, the first rush command has to reinstall rush. + const rushVersion = JSON.parse(fs.readFileSync(resolve(__dirname, '../../rush.json'))).rushVersion; + execSync(`npm install -g @microsoft/rush@${rushVersion}`); + + // Force build flavor. This is necessary in CI to catch downstream dependency issues. + // For example, we had an issue where our stable flavor was not catching that the + // `@azure/communication-calling-effects` package should've only be installed in beta flavor + // and was failing to error out in stable flavor. + execSync(`node ./common/scripts/force-build-flavor.mjs ${flavor}`); + + // Finally, install node module dependencies based on the flavor. + execSync(`rush switch-flavor:${flavor}`); +} + +main(process.argv);