From c95894671f3febeda2207809f3be5a4903609192 Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:12:49 +0200 Subject: [PATCH] Improve CI performances - attempt 1 --- .github/workflows/run-ci.yaml | 71 +++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/.github/workflows/run-ci.yaml b/.github/workflows/run-ci.yaml index cae140b..21e1272 100644 --- a/.github/workflows/run-ci.yaml +++ b/.github/workflows/run-ci.yaml @@ -1,6 +1,6 @@ name: Build and test Sinch Node.js SDK -on: [push] +on: [push, pull_request] jobs: build: @@ -10,19 +10,45 @@ jobs: node-version: [18.x, 20.x] steps: - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} + - name: Set up Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - - run: yarn install - - run: npx eslint "packages/**/src/**/*.ts" - - run: npx eslint "packages/**/tests/**/*.ts" - - run: yarn run build - - run: yarn run test + + - name: Cache Node.js modules + uses: actions/cache@v3 + with: + path: '**/node_modules' + key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-node-${{ matrix.node-version }}- + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run ESLint + run: npx eslint "packages/**/{src,tests}/**/*.ts" + + - name: Build project + run: yarn run build + + - name: Cache build output + uses: actions/cache@v3 + with: + path: './build' + key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-node-${{ matrix.node-version }}-build- + + - name: Run unit tests + run: yarn run test e2e: needs: build runs-on: ubuntu-latest + strategy: + matrix: + node-version: [ 18.x, 20.x ] steps: - uses: actions/checkout@v3 - name: Checkout sinch-sdk-mockserver repository @@ -32,14 +58,38 @@ jobs: token: ${{ secrets.PAT_CI }} fetch-depth: 0 path: sinch-sdk-mockserver + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Restore Node.js modules cache + uses: actions/cache@v3 + with: + path: '**/node_modules' + key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-node-${{ matrix.node-version }}- + + - name: Restore build output + uses: actions/cache@v3 + with: + path: './build' + key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-node-${{ matrix.node-version }}-build- + - name: Install Docker Compose run: | sudo apt-get update sudo apt-get install -y docker-compose + - name: Start mock servers with Docker Compose run: | cd sinch-sdk-mockserver docker-compose up -d + - name: Create target directories for feature files run: | mkdir -p ./packages/fax/tests/e2e/features @@ -49,6 +99,7 @@ jobs: mkdir -p ./packages/sms/tests/e2e/features mkdir -p ./packages/verification/tests/e2e/features mkdir -p ./packages/voice/tests/e2e/features + - name: Copy feature files run: | cp sinch-sdk-mockserver/features/fax/*.feature ./packages/fax/tests/e2e/features/ @@ -58,11 +109,9 @@ jobs: cp sinch-sdk-mockserver/features/sms/*.feature ./packages/sms/tests/e2e/features/ cp sinch-sdk-mockserver/features/verification/*.feature ./packages/verification/tests/e2e/features/ cp sinch-sdk-mockserver/features/voice/*.feature ./packages/voice/tests/e2e/features/ + - name: Run e2e tests - run: | - yarn install - yarn run build - yarn run e2e + run: yarn run e2e sonarcloud: runs-on: ubuntu-latest