From 1ca0d7220a03019509181ceb31d6b343f0c91929 Mon Sep 17 00:00:00 2001
From: Robpol86 <robpol86@gmail.com>
Date: Fri, 14 Jan 2022 23:10:54 -0800
Subject: [PATCH] Deduplicate GitHub Actions steps.

Now that GitHub supports nested composite actions:
https://github.com/actions/runner/issues/646#issuecomment-901358313
---
 .github/actions/init-deps/action.yml | 21 +++++++++++++++++++++
 .github/workflows/ci.yml             |  5 +----
 .github/workflows/deploy.yml         |  5 +----
 .github/workflows/diff.yml           |  5 +----
 CHANGELOG.md                         |  1 +
 5 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 .github/actions/init-deps/action.yml

diff --git a/.github/actions/init-deps/action.yml b/.github/actions/init-deps/action.yml
new file mode 100644
index 00000000..91b00abc
--- /dev/null
+++ b/.github/actions/init-deps/action.yml
@@ -0,0 +1,21 @@
+name: Initialize Dependencies
+description: Install project dependencies
+
+inputs:
+  python-version:
+    description: Python version to install
+    required: false
+    default: "3.10"
+
+outputs:
+  python-version:
+    description: Same as input
+    value: ${{ inputs.python-version }}
+
+runs:
+  using: composite
+  steps:
+    - {name: Install Python, uses: actions/setup-python@v2, with: {python-version: "${{ inputs.python-version }}"}}
+    - {name: Install Poetry, uses: abatilo/actions-poetry@v2.1.4}
+    - {name: Cache venv, uses: actions/cache@v2, with: {path: .venv, key: "${{ runner.os }}-venv-${{ hashFiles('poetry.lock') }}"}, id: cache}
+    - {name: Install dependencies, run: make deps, shell: bash, if: "steps.cache.outputs.cache-hit != 'true'"}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3dac9a92..9dfa30ea 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,9 +10,6 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - {name: Check out repository code, uses: actions/checkout@v2, with: {fetch-depth: 0}}
-      - {name: Install Python, uses: actions/setup-python@v2, with: {python-version: "3.10"}}
-      - {name: Install Poetry, uses: abatilo/actions-poetry@v2.1.4}
-      - {name: Cache venv, uses: actions/cache@v2, with: {path: .venv, key: "${{ runner.os }}-venv-${{ hashFiles('poetry.lock') }}"}, id: cache}
-      - {name: Install dependencies, run: make deps, if: "steps.cache.outputs.cache-hit != 'true'"}
+      - {name: Initialize dependencies, uses: ./.github/actions/init-deps}
       - {name: Run lints, run: make lint}
       - {name: Build docs, run: make docs}
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index a232787d..ca38335b 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -13,10 +13,7 @@ jobs:
       SPHINX_HTML_BASEURL: "https://${{ github.event_name != 'release' && 'rob86stage.' || '' }}robpol86.com/"
     steps:
       - {name: Check out repository code, uses: actions/checkout@v2, with: {fetch-depth: 0}}
-      - {name: Install Python, uses: actions/setup-python@v2, with: {python-version: "3.10"}}
-      - {name: Install Poetry, uses: abatilo/actions-poetry@v2.1.4}
-      - {name: Cache venv, uses: actions/cache@v2, with: {path: .venv, key: "${{ runner.os }}-venv-${{ hashFiles('poetry.lock') }}"}, id: cache}
-      - {name: Install dependencies, run: make deps, if: "steps.cache.outputs.cache-hit != 'true'"}
+      - {name: Initialize dependencies, uses: ./.github/actions/init-deps}
       - {name: Build docs, run: make docs}
       - {name: Store HTML, uses: actions/upload-artifact@v2, with: {name: html, path: build/html/, if-no-files-found: error}}
 
diff --git a/.github/workflows/diff.yml b/.github/workflows/diff.yml
index 14612211..3120a044 100644
--- a/.github/workflows/diff.yml
+++ b/.github/workflows/diff.yml
@@ -41,10 +41,7 @@ jobs:
       SPHINX_HTML_BASEURL: "https://robpol86.com/"
     steps:
       - {name: Check out repository code, uses: actions/checkout@v2, with: {fetch-depth: 0}}
-      - {name: Install Python, uses: actions/setup-python@v2, with: {python-version: "3.10"}}
-      - {name: Install Poetry, uses: abatilo/actions-poetry@v2.1.4}
-      - {name: Cache venv, uses: actions/cache@v2, with: {path: .venv, key: "${{ runner.os }}-venv-${{ hashFiles('poetry.lock') }}"}, id: cache}
-      - {name: Install dependencies, run: make deps, if: "steps.cache.outputs.cache-hit != 'true'"}
+      - {name: Initialize dependencies, uses: ./.github/actions/init-deps}
       - {name: Build docs, run: make docs}
       - {name: Prettify, uses: creyD/prettier_action@v3.3, with: {prettier_options: "--write html/**/*.{js,css,html,xml}", prettier_plugins: "@prettier/plugin-xml"}}
       - {name: Store HTML, uses: actions/upload-artifact@v2, with: {name: html_wf, path: build/html/, if-no-files-found: error}}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d0f6ab4..ff5f1f93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/
 ## [Unreleased]
 
 - Added Auto Reboot section to Franklin T9 page.
+- De-duplicating steps in multiple GitHub Actions workflows by defining my own composite action in this same repo.
 
 ## 2022-01-04