From dc2c73bb3088102ef16de8b660f1a3776a567384 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Fri, 10 Feb 2023 14:14:23 +0100 Subject: [PATCH] Move NPM and Node.js setup into re-usable workflow (#16994) --- .github/actions/npm-setup/action.yml | 29 ++++++++++++++++++++++ .github/workflows/js-ci.yml | 36 ++++++++-------------------- 2 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 .github/actions/npm-setup/action.yml diff --git a/.github/actions/npm-setup/action.yml b/.github/actions/npm-setup/action.yml new file mode 100644 index 0000000000..85218dee36 --- /dev/null +++ b/.github/actions/npm-setup/action.yml @@ -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 diff --git a/.github/workflows/js-ci.yml b/.github/workflows/js-ci.yml index a88e49cf91..5591723e76 100644 --- a/.github/workflows/js-ci.yml +++ b/.github/workflows/js-ci.yml @@ -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 + working-directory: js - - 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 }}