Skip to content

Commit

Permalink
ci: reduce duplication in workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
k3nsei authored Mar 31, 2023
1 parent b513390 commit b60caa9
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 165 deletions.
42 changes: 42 additions & 0 deletions .github/actions/install-npm-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Setup Node.js and install NPM dependencies
description: Install Node.js and NPM, then install NPM dependencies

inputs:
node-version:
description: 'Which version of Node.js to install'
required: false
default: 'lts/*'
registry-url:
description: 'Which NPM registry url to use'
required: false
default: 'https://registry.npmjs.org'
npm-cache-key:
description: 'Key for naming NPM cache'
required: false
default: npm-cache

runs:
using: composite
steps:
- name: Setup Node.js and NPM
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
registry-url: ${{ inputs.registry-url }}

- name: Get NPM cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache --global)" >> ${GITHUB_OUTPUT}

- name: Restore NPM cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-${{ inputs.npm-cache-key }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ inputs.npm-cache-key }}
- name: Install NPM dependencies
shell: bash
run: npm ci
69 changes: 6 additions & 63 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-main-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps

- name: Check code format
run: npm run format
Expand Down Expand Up @@ -95,27 +76,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-main-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps

- name: Download build artifact
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -152,27 +114,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-main-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps

- name: Download build artifact
uses: actions/download-artifact@v3
Expand Down
69 changes: 9 additions & 60 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-pr-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
npm-cache-key: 'npm-cache-pr'

- name: Check code format
run: npm run format
Expand Down Expand Up @@ -83,27 +66,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-pr-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
npm-cache-key: 'npm-cache-pr'

- name: Download build artifact
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -140,27 +106,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-pr-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
npm-cache-key: 'npm-cache-pr'

- name: Download build artifact
uses: actions/download-artifact@v3
Expand Down
23 changes: 3 additions & 20 deletions .github/workflows/qodana-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup node.js
uses: actions/setup-node@v3
- name: Setup Node.js and install NPM dependencies
uses: ./.github/actions/install-npm-deps
with:
node-version: 'lts/*'

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
id: npm-cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-qodana-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
npm-cache-key: 'npm-cache-qodana'

- name: Qodana Scan
uses: JetBrains/qodana-action@v2022.3.4
Expand Down
24 changes: 2 additions & 22 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,13 @@ jobs:
if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3

- name: Setup node.js
- name: Setup Node.js and install NPM dependencies
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-node@v3
uses: ./.github/actions/install-npm-deps
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'

- name: Get npm cache directory
if: ${{ steps.release.outputs.release_created }}
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Restore dependencies cache
if: ${{ steps.release.outputs.release_created }}
id: npm-cache
uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-release-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
if: ${{ steps.release.outputs.release_created }}
run: npm ci

- name: Build library
if: ${{ steps.release.outputs.release_created }}
run: npm run build:lib
Expand Down
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ testem.log
# System files
.DS_Store
Thumbs.db

# GitHub
/.github/*
/.github/actions/*
/.github/workflows/*
!/.github/dependabot.yml
!/.github/funding.yml
!/.github/actions/install-npm-deps/action.yml
!/.github/workflows/main.yml
!/.github/workflows/pr.yml
!/.github/workflows/qodana-scan.yml
!/.github/workflows/release-please.yml

1 comment on commit b60caa9

@vercel
Copy link

@vercel vercel bot commented on b60caa9 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ng-in-viewport – ./

ng-in-viewport-k3nsei.vercel.app
ng-in-viewport.vercel.app
ng-in-viewport-git-develop-k3nsei.vercel.app

Please sign in to comment.