feat(ci): deduplicate and fix node setup

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-11-29 17:36:57 +01:00 committed by David Mehren
parent 2241a3faea
commit 534540855c
8 changed files with 60 additions and 146 deletions

38
.github/actions/setup-node/action.yml vendored Normal file
View file

@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
#
# SPDX-License-Identifier: AGPL-3.0-only
name: Setup Node
description: "Setups node and configures the cache"
inputs:
NODE_VERSION:
required: true
type: string
runs:
using: "composite"
steps:
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache yarn cache
uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ inputs.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ inputs.NODE_VERSION }}
- name: Set up NodeJS
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.NODE_VERSION }}
- name: Install dependencies
run: yarn install --immutable
working-directory: .
shell: bash

View file

@ -49,16 +49,11 @@ jobs:
with:
fetch-depth: 0
- name: Use Node.js ${{ env.NODEJS_VERSION }}
- name: Setup node
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
uses: ./.github/actions/setup-node
with:
cache-dependency-path: backend/yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
cache: 'yarn'
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'
NODE_VERSION: ${{ env.NODEJS_VERSION }}
- run: yarn run test:e2e:cov
if: needs.changes.outputs.changed == 'true'
@ -93,9 +88,8 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
cache-dependency-path: backend/yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
cache: 'yarn'
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'
@ -126,9 +120,7 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
cache-dependency-path: backend/yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
cache: 'yarn'
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'

View file

@ -48,16 +48,11 @@ jobs:
- uses: actions/checkout@v3
if: needs.changes.outputs.changed == 'true'
- name: Use Node.js ${{ env.NODEJS_VERSION }}
- name: Setup node
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
uses: ./.github/actions/setup-node
with:
cache-dependency-path: backend/yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
cache: 'yarn'
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'
NODE_VERSION: ${{ env.NODEJS_VERSION }}
- run: yarn run lint
if: needs.changes.outputs.changed == 'true'
@ -76,9 +71,7 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
cache-dependency-path: backend/yarn.lock
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'
@ -99,9 +92,7 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
cache-dependency-path: backend/yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
cache: 'yarn'
- run: yarn install --immutable
if: needs.changes.outputs.changed == 'true'

View file

@ -71,32 +71,11 @@ jobs:
path: frontend/.next
key: ${{ env.HEAD_COMMIT_HASH }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache
uses: actions/cache@v3
id: yarn-cache
- name: Setup node
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
uses: ./.github/actions/setup-node
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
run: yarn install --immutable
NODE_VERSION: ${{ env.NODE_VERSION }}
- name: Build test production build
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
@ -159,8 +138,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies
if: needs.changes.outputs.changed == 'true'

View file

@ -49,32 +49,11 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3
- name: Get yarn cache directory path
- name: Setup node
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3
id: yarn-cache
uses: ./.github/actions/setup-node
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable
NODE_VERSION: ${{ env.NODE_VERSION }}
- name: Lint code
if: needs.changes.outputs.changed == 'true'

View file

@ -52,28 +52,11 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3
- name: Get yarn cache directory path
- name: Setup node
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3
id: yarn-cache
uses: ./.github/actions/setup-node
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
NODE_VERSION: ${{ env.NODE_VERSION }}
- name: Patch intro.md to include netlify banner.
if: needs.changes.outputs.changed == 'true'
@ -91,10 +74,6 @@ jobs:
if: needs.changes.outputs.changed == 'true'
run: echo "HD_EDITOR_BASE_URL=\"https://hedgedoc.dev/\"" >> .env.production
- name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable
- name: Build app
if: needs.changes.outputs.changed == 'true'
run: yarn build:mock

View file

@ -75,28 +75,11 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get yarn cache directory path
- name: Setup node
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3
id: yarn-cache
uses: ./.github/actions/setup-node
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
NODE_VERSION: ${{ env.NODE_VERSION }}
- name: Patch intro.md to include netlify banner.
if: needs.changes.outputs.changed == 'true'
@ -114,10 +97,6 @@ jobs:
if: needs.changes.outputs.changed == 'true'
run: echo "HD_EDITOR_BASE_URL=\"${{ env.DEPLOY_URL }}\"" >> .env.production
- name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable
- name: Build app
if: needs.changes.outputs.changed == 'true'
run: yarn build:mock

View file

@ -49,32 +49,11 @@ jobs:
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3
- name: Get yarn cache directory path
- name: Setup node
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3
id: yarn-cache
uses: ./.github/actions/setup-node
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ matrix.node }}
- name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable
NODE_VERSION: ${{ matrix.node }}
- name: Test Project
if: needs.changes.outputs.changed == 'true'