Skip to content

Commit

Permalink
feat(WIP): updated bootstrap scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Aug 12, 2024
1 parent ee2a1d0 commit b51eac1
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 106 deletions.
11 changes: 11 additions & 0 deletions .cicd-tools/configuration/pre-commit-bootstrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
default_install_hook_types: []
repos:
- repo: https://github.com/cicd-tools-org/pre-commit.git
rev: ec60458b77727e575576c7af58f5916e0343f340
hooks:
- id: cicd-tools-box
entry: ./src/pre-commit/cicd-tools-box.sh -c system -j system -g system
- id: cicd-tools-key
entry: ./src/pre-commit/cicd-tools-key.sh -g system
- id: commitizen-pre-bump
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ repos:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/cicd-tools-org/pre-commit.git
rev: 0.5.0
rev: df123082c2c4ef2d5194657de380ec5a9539f647
hooks:
- id: cicd-tools-schema-cookiecutter
files: "^(cookiecutter\\.json|\\.github/scenarios/.*\\.json)$"
stages: [manual]
- id: format-shell
args:
- "-w"
Expand Down
96 changes: 61 additions & 35 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,81 @@

set -eo pipefail

# shellcheck source=./.cicd-tools/boxes/bootstrap/libraries/logging.sh
source "$(dirname -- "${BASH_SOURCE[0]}")/../.cicd-tools/boxes/bootstrap/libraries/logging.sh"

CICD_TOOLS_TOOLBOX_PATH="${CICD_TOOLS_TOOLBOX_PATH-"cicd-tools/boxes"}"
CICD_TOOLS_INSTALL_SUB_PATH="boxes/bootstrap"

main() {
local CICD_TOOLS_INSTALL_TARGET_PATH
local CICD_TOOLS_TOOLBOX_VERSION

_link_args "$@"
_link_symlinks ".cicd-tools"
_link_symlinks "{{cookiecutter.project_slug}}/.cicd-tools"
_link_symlinks_template
_bootstrap_args "$@"
_bootstrap_import_installer_libraries "${CICD_TOOLS_TOOLBOX_VERSION}"

_installer_update_precommit_repo
_installer_update_legacy_bootstrap "${CICD_TOOLS_INSTALL_TARGET_PATH}"
_installer_precommit_hooks_update "${CICD_TOOLS_INSTALL_TARGET_PATH}"

_bootstrap_symlinks ".cicd-tools"
_installer_update_legacy_bootstrap "."
_installer_precommit_hooks_update "."

_bootstrap_symlinks "{{cookiecutter.project_slug}}/.cicd-tools"
_installer_update_legacy_bootstrap "{{cookiecutter.project_slug}}"

_bootstrap_symlinks_template_configuration

log "INFO" "All symlinks have been updated."
log "INFO" "This repository and '${CICD_TOOLS_INSTALL_TARGET_PATH}' have been successfully bootstrapped with version '${CICD_TOOLS_TOOLBOX_VERSION}'."
}

_link_args() {
_bootstrap_args() {
local OPTARG
local OPTIND
local OPTION

while getopts "b:" OPTION; do
while getopts "b:d:" OPTION; do
case "$OPTION" in
b)
CICD_TOOLS_TOOLBOX_VERSION="${OPTARG}"
;;
d)
CICD_TOOLS_INSTALL_TARGET_PATH="${OPTARG}"
;;
\?)
_link_usage
_bootstrap_usage
;;
:)
_link_usage
_bootstrap_usage
;;
*)
_link_usage
_bootstrap_usage
;;
esac
done
shift $((OPTIND - 1))

if [[ -z "${CICD_TOOLS_TOOLBOX_VERSION}" ]]; then
_link_usage
if [[ -z "${CICD_TOOLS_TOOLBOX_VERSION}" ]] ||
[[ -z "${CICD_TOOLS_INSTALL_TARGET_PATH}" ]]; then
_bootstrap_usage
fi

_installer_validate_folder "${CICD_TOOLS_TOOLBOX_ROOT_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}"
_installer_validate_folder "${CICD_TOOLS_INSTALL_TARGET_PATH}"
}

_bootstrap_import_installer_libraries() {
# 1: The toolbox version to use during import.

# shellcheck source=./scripts/libraries/installer.sh
source "$(dirname -- "${BASH_SOURCE[0]}")/libraries/installer.sh"

_installer_import_support_libraries "${1}"
}

_bootstrap_relative_path() {
realpath --relative-to="$(pwd)" "$(git rev-parse --show-toplevel)"
}

_link_symlink_directory_contents() {
_bootstrap_symlink_directory_contents() {
# 1: Source
# 2: Destination

Expand All @@ -64,55 +93,52 @@ _link_symlink_directory_contents() {
mkdir -p "${2}"
pushd "${2}" >> /dev/null

for SOURCE_FILE in "$(_link_relative_path_new)/${1}/"*; do
for SOURCE_FILE in "$(_bootstrap_relative_path)/${1}/"*; do
LINK_NAME="${SOURCE_FILE}"
LINK_SOURCE="$(basename "${SOURCE_FILE}")"
_link_symlink_write "${LINK_NAME}" "${LINK_SOURCE}"
_bootstrap_symlink_write "${LINK_NAME}" "${LINK_SOURCE}"
done
popd >> /dev/null
}

_link_relative_path_new() {
realpath --relative-to="$(pwd)" "$(git rev-parse --show-toplevel)"
}

_link_symlinks() {
_bootstrap_symlinks() {
# 1: Installation Folder

local LINK_NAME
local LINK_SOURCE

log "DEBUG" "SYMLINK > Destination: '${1}': ..."

_link_symlink_directory_contents "${CICD_TOOLS_TOOLBOX_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}/commitizen" "${1}/${CICD_TOOLS_INSTALL_SUB_PATH}/commitizen"
_link_symlink_directory_contents "${CICD_TOOLS_TOOLBOX_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}/libraries" "${1}/${CICD_TOOLS_INSTALL_SUB_PATH}/libraries"
_link_symlink_directory_contents "${CICD_TOOLS_TOOLBOX_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}/pre-commit" "${1}/${CICD_TOOLS_INSTALL_SUB_PATH}/pre-commit"
_link_symlink_directory_contents "${CICD_TOOLS_TOOLBOX_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}/schemas" "${1}/${CICD_TOOLS_INSTALL_SUB_PATH}/schemas"
_bootstrap_symlink_directory_contents "${CICD_TOOLS_TOOLBOX_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}/libraries" "${1}/${CICD_TOOLS_INSTALL_SUB_PATH}/libraries"
_bootstrap_symlink_directory_contents "${CICD_TOOLS_TOOLBOX_PATH}/${CICD_TOOLS_TOOLBOX_VERSION}/schemas" "${1}/${CICD_TOOLS_INSTALL_SUB_PATH}/schemas"

}

_link_symlinks_template() {
_bootstrap_symlinks_template_configuration() {
local SOURCE_FILE
local LINK_NAME
local LINK_SOURCE

log "DEBUG" "SYMLINK > Destination: '{{cookiecutter.project_slug}}/.cicd-tools': ..."

_link_symlink_directory_contents ".cicd-tools/bin" "{{cookiecutter.project_slug}}/.cicd-tools/bin"
_link_symlink_directory_contents ".cicd-tools/configuration" "{{cookiecutter.project_slug}}/.cicd-tools/configuration"
_link_symlink_directory_contents ".cicd-tools/pgp" "{{cookiecutter.project_slug}}/.cicd-tools/pgp"
_bootstrap_symlink_directory_contents ".cicd-tools/configuration" "{{cookiecutter.project_slug}}/.cicd-tools/configuration"
}

_link_symlink_write() {
_bootstrap_symlink_write() {
set -x
ln -sf "${1}" "${2}"
{ set +x; } 2> /dev/null
}

_link_usage() {
log "ERROR" "bootstrap.sh -- bootstrap the CICD-Tools system with the specified toolbox version."
log "ERROR" "USAGE: link.sh -b [TOOLBOX VERSION]"
_bootstrap_usage() {
log "ERROR" "bootstrap.sh -- bootstrap CICD-Tools with a specific toolbox."
log "ERROR" "-------------------------------------------------------------"
log "ERROR" "bootstrap.sh"
log "ERROR" " -b [TOOLBOX VERSION]"
log "ERROR" " -d [PRE-COMMIT REPOSITORY PATH]"
exit 127
}

_bootstrap_import_installer_libraries "0.1.0"

main "$@"
12 changes: 9 additions & 3 deletions scripts/containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

set -eo pipefail

# shellcheck source=./.cicd-tools/boxes/bootstrap/libraries/logging.sh
source "$(dirname -- "${BASH_SOURCE[0]}")/../.cicd-tools/boxes/bootstrap/libraries/logging.sh"

main() {
log "INFO" "Building the CICD-Tools utility container ..."

Expand Down Expand Up @@ -66,4 +63,13 @@ main() {
log "INFO" "Containers successfully built."
}

_containers_import_support_libraries() {
# 1: The toolbox version to use during import.

# shellcheck source=/dev/null
source "$(dirname -- "${BASH_SOURCE[0]}")/../cicd-tools/boxes/${1}/libraries/logging.sh"
}

_containers_import_support_libraries "0.1.0"

main "$@"
46 changes: 33 additions & 13 deletions scripts/install-cookiecutter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

set -eo pipefail

# shellcheck source=./.cicd-tools/boxes/bootstrap/libraries/logging.sh
source "$(dirname -- "${BASH_SOURCE[0]}")/../.cicd-tools/boxes/bootstrap/libraries/logging.sh"

# shellcheck disable=SC2034
CICD_TOOLS_BOOTSTRAP_PATH="${CICD_TOOLS_TOOLBOX_PATH-"$(dirname -- "${BASH_SOURCE[0]}")/../.cicd-tools"}"
# shellcheck disable=SC2034
Expand All @@ -18,29 +15,34 @@ CICD_TOOLS_TEMPLATE_PATH="${CICD_TOOLS_ACTION_PATH-"$(dirname -- "${BASH_SOURCE[

main() {
local CICD_TOOLS_INSTALL_TARGET_PATH
local CICD_TOOLS_TOOLBOX_VERSION

_install_args "$@"

# shellcheck source=./scripts/libraries/installer.sh
source "$(dirname -- "${BASH_SOURCE[0]}")/libraries/installer.sh"
_install_import_installer_libraries "${CICD_TOOLS_TOOLBOX_VERSION}"

_installer_bootstrap

_installer_update_legacy_bootstrap "${CICD_TOOLS_INSTALL_TARGET_PATH}"
_installer_update_legacy_bootstrap "${CICD_TOOLS_INSTALL_TARGET_PATH}/{{cookiecutter.project_slug}}"

_installer_actions
_installer_cookiecutter_symlinks

_installer_line_in_file ".gitignore" '.cicd-tools/boxes'
_installer_line_in_file ".gitignore" '!.cicd-tools/boxes/bootstrap'
_installer_line_in_file ".gitignore" '.cicd-tools/manifest.json'
_installer_line_in_file "{{cookiecutter.project_slug}}/.gitignore" '.cicd-tools/boxes'
_installer_line_in_file "{{cookiecutter.project_slug}}/.gitignore" '!.cicd-tools/boxes/bootstrap'
_installer_line_in_file "{{cookiecutter.project_slug}}/.gitignore" '.cicd-tools/manifest.json'

_installer_poetry_init "."
_installer_poetry_init "." "true"

_installer_initialize_vale "."
_installer_initialize_vale "{{cookiecutter.project_slug}}"

_installer_conditional_recursive_copy ".markdownlint.yml"
_installer_prefixed_copy_file "{{cookiecutter.project_slug}}" ".markdownlint.yml"

_installer_precommit_hooks_update "${CICD_TOOLS_INSTALL_TARGET_PATH}"

log "INFO" "Successfully installed CICD-Tools."
}

Expand All @@ -49,8 +51,11 @@ _install_args() {
local OPTIND
local OPTION

while getopts "d:" OPTION; do
while getopts "b:d:" OPTION; do
case "$OPTION" in
b)
CICD_TOOLS_TOOLBOX_VERSION="${OPTARG}"
;;
d)
CICD_TOOLS_INSTALL_TARGET_PATH="${OPTARG}"
[[ ! -d "${CICD_TOOLS_INSTALL_TARGET_PATH}" ]] && _install_no_target_path
Expand All @@ -68,20 +73,35 @@ _install_args() {
done
shift $((OPTIND - 1))

if [[ -z "${CICD_TOOLS_INSTALL_TARGET_PATH}" ]]; then
if [[ -z "${CICD_TOOLS_INSTALL_TARGET_PATH}" ]] ||
[[ -z "${CICD_TOOLS_TOOLBOX_VERSION}" ]]; then
_install_usage
fi
}

_install_import_installer_libraries() {
# 1: The toolbox version to use during import.

# shellcheck source=./scripts/libraries/installer.sh
source "$(dirname -- "${BASH_SOURCE[0]}")/libraries/installer.sh"

_installer_import_support_libraries "${1}"
}

_install_no_target_path() {
log "ERROR" "The path '${CICD_TOOLS_INSTALL_TARGET_PATH}' does not exist."
exit 127
}

_install_usage() {
log "ERROR" "install-cookiecutter.sh -- install the bootstrapped CICD-Tools system to an existing cookiecutter repository."
log "ERROR" "USAGE: install-cookiecutter.sh -d [DESTINATION PATH]"
log "ERROR" "install-cookiecutter.sh -- install CICD-Tools to an existing cookiecutter repo."
log "ERROR" "-------------------------------------------------------------------------------"
log "ERROR" "install-cookiecutter.sh"
log "ERROR" " -b [TOOLBOX VERSION]"
log "ERROR" " -d [DESTINATION REPOSITORY PATH]"
exit 127
}

_install_import_installer_libraries "0.1.0"

main "$@"
Loading

0 comments on commit b51eac1

Please sign in to comment.