Skip to content

Commit

Permalink
feat(EXPERIMENTAL): enable pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Aug 12, 2024
1 parent 53c1e8b commit ee2a1d0
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 27 deletions.
64 changes: 64 additions & 0 deletions .github/actions/action-00-toolbox-legacy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: action-00-toolbox
description: "Fetches the specified remote toolbox via the legacy installer scripts."
author: niall@niallbyrne.ca

inputs:
CICD_TOOLS_GPG_KEY:
default: "F07A79647E91E561A786B6D0D9020F7FEE20DBF2"
description: "Optional, allows you to specify the public key used to sign the remote CICD-Tools manifest."
required: false
CICD_TOOLS_GPG_KEYSERVER_PRIMARY:
default: "keys.openpgp.org"
description: "Optional, allows you to specify a keyserver being used to host the public GPG key."
required: false
CICD_TOOLS_GPG_KEYSERVER_SECONDARY:
default: "keyserver.ubuntu.com"
description: "Optional, allows you to specify a keyserver being used to host the public GPG key."
required: false
CICD_TOOLS_REMOTE_MANIFEST:
default: "https://raw.githubusercontent.com/cicd-tools-org/manifest/main/manifest.json.asc"
description: "Optional, allows you to specify the URL of the remote manifest used to coordinate CICD-Tools toolbox installs."
required: false
CICD_TOOLS_TOOLBOX_VERSION:
default: "0.1.0"
description: "Optional, allows you to specify a toolbox version to fetch from the manifest."
required: false
PROJECT_ROOT_PATH:
default: "."
description: "Optional, allows you to specify a path to the project's root."
required: false

runs:
using: "composite"
steps:
- name: Toolbox -- Install Required Software (Mac OSX Only)
if: runner.os == 'macOS'
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install coreutils
shell: bash

- name: Toolbox -- Import GPG Key
run: |
gpg \
--keyserver "${{ inputs.CICD_TOOLS_GPG_KEYSERVER_PRIMARY }}" \
--recv-key "${{ inputs.CICD_TOOLS_GPG_KEY }}" ||
gpg \
--keyserver "${{ inputs.CICD_TOOLS_GPG_KEYSERVER_SECONDARY }}" \
--recv-key "${{ inputs.CICD_TOOLS_GPG_KEY }}"
shell: bash

- name: Toolbox -- Verify Imported Key
run: |
./.cicd-tools/bin/verify.sh \
-k "${{ inputs.CICD_TOOLS_GPG_KEY }}"
shell: bash
working-directory: ${{ inputs.PROJECT_ROOT_PATH }}

- name: Toolbox -- Install CICD-Tools Toolbox Version '${{ inputs.VERSION }}'
run: |
./.cicd-tools/bin/toolbox.sh \
-b "${{ inputs.CICD_TOOLS_TOOLBOX_VERSION }}" \
-m "${{ inputs.CICD_TOOLS_REMOTE_MANIFEST }}"
shell: bash
working-directory: ${{ inputs.PROJECT_ROOT_PATH }}
94 changes: 94 additions & 0 deletions .github/actions/action-00-toolbox-pre-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
name: action-00-toolbox
description: "Fetches the specified remote toolbox."
author: niall@niallbyrne.ca

inputs:
CICD_TOOLS_GPG_KEY:
default: "F07A79647E91E561A786B6D0D9020F7FEE20DBF2"
description: "Optional, allows you to specify the public key used to sign the remote CICD-Tools manifest."
required: false
CICD_TOOLS_GPG_KEYSERVER_PRIMARY:
default: "keys.openpgp.org"
description: "Optional, allows you to specify a keyserver being used to host the public GPG key."
required: false
CICD_TOOLS_GPG_KEYSERVER_SECONDARY:
default: "keyserver.ubuntu.com"
description: "Optional, allows you to specify a keyserver being used to host the public GPG key."
required: false
CICD_TOOLS_REMOTE_MANIFEST:
default: "https://raw.githubusercontent.com/cicd-tools-org/manifest/main/manifest.json.asc"
description: "Optional, allows you to specify the URL of the remote manifest used to coordinate CICD-Tools toolbox installs."
required: false
CICD_TOOLS_TOOLBOX_VERSION:
default: "0.1.0"
description: "Optional, allows you to specify a toolbox version to fetch from the manifest."
required: false
PROJECT_ROOT_PATH:
default: "."
description: "Optional, allows you to specify a path to the project's root."
required: false

runs:
using: "composite"
steps:
- name: Toolbox -- Install Required Software (Mac OSX Only)
if: runner.os == 'macOS'
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install coreutils
shell: bash

- name: Toolbox -- Configure Toolbox Cache
run: |
TOOLBOX_CACHE_ROOT="${HOME}/.toolbox"
TOOLBOX_CACHE_TTL="$(date +%d)"
echo "TOOLBOX_CACHE_ROOT=${TOOLBOX_CACHE_ROOT}" >> "${GITHUB_ENV}"
echo "TOOLBOX_CACHE_TTL=${TOOLBOX_CACHE_TTL}" >> "${GITHUB_ENV}"
shell: bash

- name: Toolbox -- Initialize Toolbox Cache
run: |
mkdir -p "${TOOLBOX_CACHE_ROOT}/venv"
mkdir -p "${TOOLBOX_CACHE_ROOT}/pre-commit"
shell: bash

- name: Toolbox -- Mount Toolbox Cache
uses: actions/cache@v4
with:
path: ${{ env.TOOLBOX_CACHE_ROOT }}
key: toolbox-${{ hashFiles('.cicd-tools/configuration/pre-commit-bootstrap.yaml') }}-${{ runner.os }}-${{ env.TOOLBOX_CACHE_TTL }}

- name: Toolbox -- Install Pre-Commit To Virtual Environment
run: |
source "${TOOLBOX_CACHE_ROOT}/venv/bin/activate" || \
(
python -m venv "${TOOLBOX_CACHE_ROOT}/venv" &&
source "${TOOLBOX_CACHE_ROOT}/venv/bin/activate" &&
pip install -v pre-commit
)
shell: bash

- name: Toolbox -- Import GPG Key
run: |
source "${TOOLBOX_CACHE_ROOT}/venv/bin/activate"
PRE_COMMIT_HOME="${TOOLBOX_CACHE_ROOT}/pre-commit" \
pre-commit run --hook-stage=manual cicd-tools-key --verbose -c .cicd-tools/configuration/pre-commit-bootstrap.yaml
shell: bash
env:
TOOLBOX_OVERRIDE_DOCKER_IMAGE_GPG: "system"
TOOLBOX_OVERRIDE_GPG_KEY_SERVER_PRIMARY: ${{ inputs.CICD_TOOLS_GPG_KEYSERVER_PRIMARY }}
TOOLBOX_OVERRIDE_GPG_KEY_SERVER_SECONDARY: ${{ inputs.CICD_TOOLS_GPG_KEYSERVER_SECONDARY }}
TOOLBOX_OVERRIDE_GPG_KEY_NAME: ${{ inputs.CICD_TOOLS_GPG_KEY }}

- name: Toolbox -- Install the Project's Toolbox
run: |
source "${TOOLBOX_CACHE_ROOT}/venv/bin/activate"
PRE_COMMIT_HOME="${TOOLBOX_CACHE_ROOT}/pre-commit" \
pre-commit run --hook-stage=manual cicd-tools-box --verbose -c .cicd-tools/configuration/pre-commit-bootstrap.yaml
shell: bash
env:
TOOLBOX_OVERRIDE_DOCKER_IMAGE_CURL: "system"
TOOLBOX_OVERRIDE_DOCKER_IMAGE_GPG: "system"
TOOLBOX_OVERRIDE_DOCKER_IMAGE_JQ: "system"
TOOLBOX_OVERRIDE_MANIFEST_URL: ${{ inputs.CICD_TOOLS_REMOTE_MANIFEST }}
TOOLBOX_OVERRIDE_TOOLBOX_VERSION: ${{ inputs.CICD_TOOLS_TOOLBOX_VERSION }}
51 changes: 25 additions & 26 deletions .github/actions/action-00-toolbox/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,32 @@ inputs:
runs:
using: "composite"
steps:
- name: Toolbox -- Install Required Software (Mac OSX Only)
if: runner.os == 'macOS'
- name: Toolbox -- Legacy Scripting Compatibility Shim
id: identify_legacy_install
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install coreutils
[[ -f "${{ inputs.PROJECT_ROOT_PATH }}/.cicd-tools/bin/toolbox.sh" ]] \
&& echo "CICD_TOOLS_LEGACY_INSTALL=1" >> "${GITHUB_OUTPUT}" \
|| echo "CICD_TOOLS_LEGACY_INSTALL=0" >> "${GITHUB_OUTPUT}"
shell: bash

- name: Toolbox -- Import GPG Key
run: |
gpg \
--keyserver "${{ inputs.CICD_TOOLS_GPG_KEYSERVER_PRIMARY }}" \
--recv-key "${{ inputs.CICD_TOOLS_GPG_KEY }}" ||
gpg \
--keyserver "${{ inputs.CICD_TOOLS_GPG_KEYSERVER_SECONDARY }}" \
--recv-key "${{ inputs.CICD_TOOLS_GPG_KEY }}"
shell: bash
- name: Toolbox - Install CICD-Tools Toolbox (Legacy Scripting)
if: steps.identify_legacy_install.outputs.CICD_TOOLS_LEGACY_INSTALL == '1'
uses: cicd-tools-org/cicd-tools/.github/actions/action-00-toolbox-legacy@main
with:
CICD_TOOLS_GPG_KEY: ${{ inputs.CICD_TOOLS_GPG_KEY }}
CICD_TOOLS_GPG_KEYSERVER_PRIMARY: ${{ inputs.CICD_TOOLS_GPG_KEYSERVER_PRIMARY }}
CICD_TOOLS_GPG_KEYSERVER_SECONDARY: ${{ inputs.CICD_TOOLS_GPG_KEYSERVER_SECONDARY }}
CICD_TOOLS_REMOTE_MANIFEST: ${{ inputs.CICD_TOOLS_REMOTE_MANIFEST }}
CICD_TOOLS_TOOLBOX_VERSION: ${{ inputs.CICD_TOOLS_TOOLBOX_VERSION }}
PROJECT_ROOT_PATH: ${{ inputs.PROJECT_ROOT_PATH }}

- name: Toolbox -- Verify Imported Key
run: |
./.cicd-tools/bin/verify.sh \
-k "${{ inputs.CICD_TOOLS_GPG_KEY }}"
shell: bash
working-directory: ${{ inputs.PROJECT_ROOT_PATH }}

- name: Toolbox -- Install CICD-Tools Toolbox Version '${{ inputs.VERSION }}'
run: |
./.cicd-tools/bin/toolbox.sh \
-b "${{ inputs.CICD_TOOLS_TOOLBOX_VERSION }}" \
-m "${{ inputs.CICD_TOOLS_REMOTE_MANIFEST }}"
shell: bash
working-directory: ${{ inputs.PROJECT_ROOT_PATH }}
- name: Toolbox - Install CICD-Tools Toolbox (Pre-Commit)
if: steps.identify_legacy_install.outputs.CICD_TOOLS_LEGACY_INSTALL == '0'
uses: cicd-tools-org/cicd-tools/.github/actions/action-00-toolbox-pre-commit@main
with:
CICD_TOOLS_GPG_KEY: ${{ inputs.CICD_TOOLS_GPG_KEY }}
CICD_TOOLS_GPG_KEYSERVER_PRIMARY: ${{ inputs.CICD_TOOLS_GPG_KEYSERVER_PRIMARY }}
CICD_TOOLS_GPG_KEYSERVER_SECONDARY: ${{ inputs.CICD_TOOLS_GPG_KEYSERVER_SECONDARY }}
CICD_TOOLS_REMOTE_MANIFEST: ${{ inputs.CICD_TOOLS_REMOTE_MANIFEST }}
CICD_TOOLS_TOOLBOX_VERSION: ${{ inputs.CICD_TOOLS_TOOLBOX_VERSION }}
PROJECT_ROOT_PATH: ${{ inputs.PROJECT_ROOT_PATH }}
25 changes: 24 additions & 1 deletion {{cookiecutter.project_slug}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/cicd-tools-org/pre-commit.git
rev: c58cb72acbf89070f7496957599e79ce17afe9f8
rev: d1beab76aee01c287e4b7fc98d220e68e7e64c67
hooks:
- id: format-shell
args:
Expand All @@ -30,6 +30,29 @@ repos:
{%- if cookiecutter.optional_toml_linting == 'true' %}
- id: format-toml
{%- endif %}
- id: gettext-translations-add
args:
- "-p"
- "python/locales"
- id: gettext-translations-compile
args:
- "-p"
- "python/locales"
- id: gettext-translations-missing
args:
- "-p"
- "python/locales"
- "-s"
- "en"
- id: gettext-translations-update
args:
- "-p"
- "python/locales"
- "-c"
- "python"
- "-e"
- "niall@niallbyrne.ca"
- "-u"
- id: git-conflict-markers
{%- if cookiecutter.optional_workflow_linting == 'true' %}
- id: lint-github-workflow-header
Expand Down

0 comments on commit ee2a1d0

Please sign in to comment.