From 091721852a04e509f0e17fab788da257d6d8eae0 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 16:27:03 +0100 Subject: [PATCH] Move environment setup to custom action --- .github/actions/set-up-environment/action.yml | 17 +++++++++++ .github/workflows/pull-request.yml | 30 ++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 .github/actions/set-up-environment/action.yml diff --git a/.github/actions/set-up-environment/action.yml b/.github/actions/set-up-environment/action.yml new file mode 100644 index 00000000..1f2c4348 --- /dev/null +++ b/.github/actions/set-up-environment/action.yml @@ -0,0 +1,17 @@ +name: 'Set up environment' +description: 'Sets up Node and installs dependencies' +runs: + using: 'composite' + steps: + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 18 + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: node-modules-${{ hashFiles('**/package-lock.json') }} + - name: Install dependencies + run: npm ci + shell: bash diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 446e5678..65b245fd 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,37 +5,19 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Check out code uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: node-modules-${{ hashFiles('**/package-lock.json') }} - - name: Install dependencies - run: npm ci + - name: Set up environment + uses: ./.github/actions/set-up-environment - name: Build app run: npm run build unit_tests: needs: build runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Check out code uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: node-modules-${{ hashFiles('**/package-lock.json') }} - - name: Install dependencies - run: npm ci + - name: Set up environment + uses: ./.github/actions/set-up-environment - name: Run tests run: npm test