From d0bbef77bd3d9a9af70e3487bec6c81bc3dbc8ce Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Fri, 8 Nov 2024 23:22:45 +0800 Subject: [PATCH] setup-yarn --- .github/actions/setup-yarn/action.yml | 26 +++++++++++++++++++ .github/workflows/style.yml | 16 +++++------- .github/workflows/tool-test-sdks.yaml | 11 +++----- .../translate-i18n-base-on-english.yml | 9 +++---- .github/workflows/web-tests.yml | 17 +++++------- sdks/README.md | 1 + web/README.md | 1 - 7 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 .github/actions/setup-yarn/action.yml diff --git a/.github/actions/setup-yarn/action.yml b/.github/actions/setup-yarn/action.yml new file mode 100644 index 0000000000..e5f93da603 --- /dev/null +++ b/.github/actions/setup-yarn/action.yml @@ -0,0 +1,26 @@ +name: Setup Yarn and NodeJS + +inputs: + node-version: + description: NodeJS version to use and the Yarn installed with + required: true + default: 20 + yarn-lockfile: + description: Path to the Yarn lockfile to restore cache from + required: true + +runs: + using: composite + steps: + - name: Set up Python ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: yarn + cache-dependency-path: ${{ inputs.yarn-lockfile }} + + - name: Install Yarn packages + shell: bash + run: | + cd "$(dirname "${{ inputs.yarn-lockfile }}")" + yarn install --frozen-lockfile diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 282afefe74..5d46c32772 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -63,19 +63,15 @@ jobs: id: changed-files uses: tj-actions/changed-files@v45 with: - files: web/** + files: | + web/** + .github/workflows/style.yml - - name: Setup NodeJS - uses: actions/setup-node@v4 + - name: Setup NodeJS and Install Yarn dependencies + uses: .github/actions/setup-yarn if: steps.changed-files.outputs.any_changed == 'true' with: - node-version: 20 - cache: yarn - cache-dependency-path: ./web/package.json - - - name: Web dependencies - if: steps.changed-files.outputs.any_changed == 'true' - run: yarn install --frozen-lockfile + yarn-lockfile: web/yarn.lock - name: Web style check if: steps.changed-files.outputs.any_changed == 'true' diff --git a/.github/workflows/tool-test-sdks.yaml b/.github/workflows/tool-test-sdks.yaml index fb4bcb9d66..7d300dfd56 100644 --- a/.github/workflows/tool-test-sdks.yaml +++ b/.github/workflows/tool-test-sdks.yaml @@ -6,6 +6,7 @@ on: - main paths: - sdks/** + - .github/workflows/tool-test-sdks.yaml concurrency: group: sdk-tests-${{ github.head_ref || github.run_id }} @@ -27,15 +28,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 + - name: Setup NodeJS ${{ matrix.node-version }} and Install Yarn dependencies + uses: .github/actions/setup-yarn with: node-version: ${{ matrix.node-version }} - cache: '' - cache-dependency-path: 'yarn.lock' - - - name: Install Dependencies - run: yarn install + yarn-lockfile: sdks/nodejs-client/yarn.lock - name: Test run: yarn test diff --git a/.github/workflows/translate-i18n-base-on-english.yml b/.github/workflows/translate-i18n-base-on-english.yml index 3f51b3b2c7..c27a29bf23 100644 --- a/.github/workflows/translate-i18n-base-on-english.yml +++ b/.github/workflows/translate-i18n-base-on-english.yml @@ -30,15 +30,12 @@ jobs: echo "FILES_CHANGED=false" >> $GITHUB_ENV fi - - name: Set up Node.js + - name: Setup NodeJS and Install Yarn dependencies + uses: .github/actions/setup-yarn if: env.FILES_CHANGED == 'true' - uses: actions/setup-node@v2 with: - node-version: 'lts/*' + yarn-lockfile: web/yarn.lock - - name: Install dependencies - if: env.FILES_CHANGED == 'true' - run: yarn install --frozen-lockfile - name: Run npm script if: env.FILES_CHANGED == 'true' diff --git a/.github/workflows/web-tests.yml b/.github/workflows/web-tests.yml index 5aee64b8e6..3459e91622 100644 --- a/.github/workflows/web-tests.yml +++ b/.github/workflows/web-tests.yml @@ -6,6 +6,7 @@ on: - main paths: - web/** + - .github/workflows/web-tests.yml concurrency: group: web-tests-${{ github.head_ref || github.run_id }} @@ -27,19 +28,15 @@ jobs: id: changed-files uses: tj-actions/changed-files@v45 with: - files: web/** + files: | + web/** + .github/workflows/web-tests.yml - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Setup NodeJS and Install Yarn dependencies + uses: .github/actions/setup-yarn if: steps.changed-files.outputs.any_changed == 'true' with: - node-version: 20 - cache: yarn - cache-dependency-path: ./web/package.json - - - name: Install dependencies - if: steps.changed-files.outputs.any_changed == 'true' - run: yarn install --frozen-lockfile + yarn-lockfile: web/yarn.lock - name: Run tests if: steps.changed-files.outputs.any_changed == 'true' diff --git a/sdks/README.md b/sdks/README.md index df908ef151..a160cc4585 100644 --- a/sdks/README.md +++ b/sdks/README.md @@ -23,3 +23,4 @@ TODO move to another place ## Node.js TODO move to another place + diff --git a/web/README.md b/web/README.md index ce5239e57f..2cd00abf6b 100644 --- a/web/README.md +++ b/web/README.md @@ -108,7 +108,6 @@ If you are not familiar with writing tests, here is some code to refer to: - ## Documentation Visit to view the full documentation.