Move NPM and Node.js setup into re-usable workflow (#16994)

This commit is contained in:
Jon Koops 2023-02-10 14:14:23 +01:00 committed by GitHub
parent dc8b759c3d
commit dc2c73bb30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 26 deletions

29
.github/actions/npm-setup/action.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Setup NPM
description: Sets up Node.js and runs NPM so dependencies are installed.
inputs:
node-version:
description: Node.js version
required: false
default: "18"
working-directory:
description: The working directory where the `package-lock.json` is located.
required: false
default: ""
runs:
using: composite
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
check-latest: true
cache: npm
cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
shell: bash
run: npm ci

View file

@ -10,9 +10,6 @@ on:
- cron: 0 20,23,2,5 * * *
workflow_dispatch:
env:
NODE_VERSION: 18
concurrency:
# Only cancel jobs for PR updates
group: js-ci-${{ github.head_ref || github.run_id }}
@ -21,6 +18,7 @@ concurrency:
defaults:
run:
shell: bash
working-directory: js
jobs:
conditional:
@ -35,41 +33,27 @@ jobs:
- id: conditional
uses: ./.github/actions/conditional
npm-run:
admin-client:
name: Admin Client
needs: conditional
if: needs.conditional.outputs.js-ci == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Keycloak Admin Client
- workspace: "@keycloak/keycloak-admin-client"
command: lint
- workspace: "@keycloak/keycloak-admin-client"
command: build
env:
WORKSPACE: "@keycloak/keycloak-admin-client"
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
- uses: ./.github/actions/npm-setup
with:
node-version: ${{ env.NODE_VERSION }}
check-latest: true
cache: npm
cache-dependency-path: js/package-lock.json
- name: Install dependencies
working-directory: js
run: npm ci
- name: Run ${{ matrix.command }} task
working-directory: js
run: npm run ${{ matrix.command }} --workspace=${{ matrix.workspace }}
- run: npm run lint --workspace=${{ env.WORKSPACE }}
- run: npm run build --workspace=${{ env.WORKSPACE }}
check-set-status:
name: Set check conclusion
needs:
- npm-run
- admin-client
runs-on: ubuntu-latest
outputs:
conclusion: ${{ steps.check.outputs.conclusion }}