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