From 883df58724dba4d82140fa29bb1bcb6b5a3887e0 Mon Sep 17 00:00:00 2001
From: Tom French <tom@tomfren.ch>
Date: Wed, 29 Jun 2022 16:16:10 +0100
Subject: [PATCH] ci: turn boilerplate into composite action

---
 .github/actions/setup/action.yml | 19 ++++++++++++++
 .github/workflows/build.yml      | 45 +++++---------------------------
 .github/workflows/lint.yml       | 15 ++---------
 3 files changed, 27 insertions(+), 52 deletions(-)
 create mode 100644 .github/actions/setup/action.yml

diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml
new file mode 100644
index 000000000..c628ff28f
--- /dev/null
+++ b/.github/actions/setup/action.yml
@@ -0,0 +1,19 @@
+name: Setup
+
+runs:
+  using: composite
+  steps:
+    - name: Install node
+      uses: actions/setup-node@v1
+      with:
+        node-version: 16
+    - name: Cache
+      uses: actions/cache@v2
+      id: cache
+      with:
+        path: '**/node_modules'
+        key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
+    - name: Install
+      run: yarn --immutable
+      shell: bash
+      if: steps.cache.outputs.cache-hit != 'true'
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index fac7559ff..1a308221b 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -19,19 +19,8 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-      - name: Install node
-        uses: actions/setup-node@v1
-        with:
-          node-version: 16
-      - name: Cache
-        uses: actions/cache@v2
-        id: cache
-        with:
-          path: '**/node_modules'
-          key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
-      - name: Install
-        run: yarn --immutable
-        if: steps.cache.outputs.cache-hit != 'true'
+      - name: Set up environment
+        uses: ./.github/actions/setup
       - name: Build API
         run: cd packages/loot-core && yarn build:api
 
@@ -39,19 +28,8 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-      - name: Install node
-        uses: actions/setup-node@v1
-        with:
-          node-version: 16
-      - name: Cache
-        uses: actions/cache@v2
-        id: cache
-        with:
-          path: '**/node_modules'
-          key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
-      - name: Install
-        run: yarn --immutable
-        if: steps.cache.outputs.cache-hit != 'true'
+      - name: Set up environment
+        uses: ./.github/actions/setup
       - name: Build Web
         run: ./bin/package-browser
 
@@ -67,18 +45,7 @@ jobs:
     runs-on: ${{ matrix.os }}
     steps:
       - uses: actions/checkout@v2
-      - name: Install node
-        uses: actions/setup-node@v1
-        with:
-          node-version: 16
-      - name: Cache
-        uses: actions/cache@v2
-        id: cache
-        with:
-          path: '**/node_modules'
-          key: yarn-v1-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
-      - name: Install
-        run: yarn --immutable
-        if: steps.cache.outputs.cache-hit != 'true'
+      - name: Set up environment
+        uses: ./.github/actions/setup
       - name: Build Electron
         run: ./bin/package
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 3a1ccb713..10fc5f3bb 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -12,18 +12,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-      - name: Install node
-        uses: actions/setup-node@v1
-        with:
-          node-version: 16
-      - name: Cache
-        uses: actions/cache@v2
-        id: cache
-        with:
-          path: '**/node_modules'
-          key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
-      - name: Install
-        run: yarn --immutable
-        if: steps.cache.outputs.cache-hit != 'true'
+      - name: Set up environment
+        uses: ./.github/actions/setup
       - name: Lint
         run: yarn lint
-- 
GitLab