Skip to content

Commit

Permalink
Deduplicate GitHub Actions steps.
Browse files Browse the repository at this point in the history
Now that GitHub supports nested composite actions:
actions/runner#646 (comment)
  • Loading branch information
Robpol86 committed Jan 15, 2022
1 parent 9bf7673 commit 1ca0d72
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .github/actions/init-deps/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]}
- {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'"}
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]}
- {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}
5 changes: 1 addition & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]}
- {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}}

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]}
- {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/[email protected], 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}}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1ca0d72

Please sign in to comment.