From ccf42d46e4977d16885d8f7eae2f9acf12695402 Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Sat, 8 Jun 2024 13:44:34 +0800 Subject: [PATCH] automataCI: enabled automated release branches implementations There are a number of technologies rely on release branches such as but not limited to NPM and Go. Hence, we have to enable the automation for it. Let's do this. This patch enables automated release branches implementations in automataCI/ directory. Co-authored-by: Shuralyov, Jean Co-authored-by: Galyna, Cory Co-authored-by: (Holloway) Chew, Kean Ho Signed-off-by: (Holloway) Chew, Kean Ho --- CONFIG.toml | 29 +++++ automataCI/_release-lib_unix-any.sh | 131 ++++++++++++++++++++++ automataCI/_release-lib_windows-any.ps1 | 137 ++++++++++++++++++++++++ automataCI/_release-npm_unix-any.sh | 2 +- automataCI/_release-npm_windows-any.ps1 | 2 +- automataCI/release_unix-any.sh | 6 ++ automataCI/release_windows-any.ps1 | 6 ++ automataCI/services/compilers/node.sh | 3 +- automataCI/services/io/fs.ps1 | 59 ++++++++++ automataCI/services/io/fs.sh | 57 ++++++++++ automataCI/services/versioners/git.ps1 | 106 +++++++++++++++++- automataCI/services/versioners/git.sh | 118 +++++++++++++++++++- 12 files changed, 650 insertions(+), 6 deletions(-) create mode 100644 automataCI/_release-lib_unix-any.sh create mode 100644 automataCI/_release-lib_windows-any.ps1 diff --git a/CONFIG.toml b/CONFIG.toml index 7e62446e..604e1ff8 100644 --- a/CONFIG.toml +++ b/CONFIG.toml @@ -150,6 +150,25 @@ PROJECT_CONTACT_WEBSITE = "https://github.com/ChewKeanHo/AutomataCI" PROJECT_SOURCE_URL = "https://github.com/ChewKeanHo/AutomataCI" +# PROJECT_SOURCE_GIT_REMOTE +# The git remote tag for the project release publications. This is used for +# sourcing the upstream git configurations. Unless absolute required, this field +# can be left intact. +# +# Default is: 'origin' +PROJECT_SOURCE_GIT_REMOTE = 'origin' + + +# PROJECT_SOURCE_RELEASE_TAG_LATEST +# The tag label for latest release and also a flag to trigger release branches +# strategies. +# +# Default is: 'latest' +# To enable release branch strategy: fill in the label +# To disable: leave it empty ('') +PROJECT_SOURCE_RELEASE_TAG_LATEST = 'latest' + + # AUTOMATACI_LANG # Overrides AutomataCI to operate in 1 specific language. Otherwise, AutomataCI # shall query the system language settings. Only accepts language code complying @@ -536,6 +555,16 @@ PROJECT_NODE_VERSION = 'v22.2.0' PROJECT_NODE_NPM_REGISTRY = 'https://npm.pkg.github.com' +# PROJECT_NODE_BRANCH_TAG +# This is for technology tagging purposes such as but not limited to release +# branches identification. The value shall always be lowercase, short, and +# directly identify it is Node technology. +# +# Default is: 'npm' +# To disable: set it empty '' +PROJECT_NODE_BRANCH_TAG = 'npm' + + ###################### diff --git a/automataCI/_release-lib_unix-any.sh b/automataCI/_release-lib_unix-any.sh new file mode 100644 index 00000000..2b6b4621 --- /dev/null +++ b/automataCI/_release-lib_unix-any.sh @@ -0,0 +1,131 @@ +#!/bin/sh +# Copyright 2024 (Holloway) Chew, Kean Ho +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +. "${LIBS_AUTOMATACI}/services/io/fs.sh" +. "${LIBS_AUTOMATACI}/services/io/os.sh" +. "${LIBS_AUTOMATACI}/services/io/strings.sh" +. "${LIBS_AUTOMATACI}/services/archive/tar.sh" +. "${LIBS_AUTOMATACI}/services/archive/zip.sh" +. "${LIBS_AUTOMATACI}/services/i18n/translations.sh" +. "${LIBS_AUTOMATACI}/services/versioners/git.sh" + + + + +# initialize +if [ "$PROJECT_PATH_ROOT" = "" ]; then + >&2 printf "[ ERROR ] - Please run me from automataCI/ci.sh.ps1 instead!\n" + return 1 +fi + + + + +RELEASE_Run_LIBS() { + #_target="$1" + + + # validate input + if [ $(STRINGS_Is_Empty "$PROJECT_SOURCE_RELEASE_TAG_LATEST") -eq 0 ]; then + return 0 + fi + + if [ $(FS_Is_Target_A_Library "$1") -ne 0 ]; then + return 0 + fi + + if [ $(STRINGS_Is_Empty "$PROJECT_SOURCE_GIT_REMOTE") -eq 0 ]; then + return 0 + fi + + GIT_Is_Available + if [ $? -ne 0 ]; then + return 0 + fi + + + # execute + ## identify tag + __branch="v${PROJECT_VERSION}" + if [ $(FS_Is_Target_A_NPM "$1") -eq 0 ]; then + if [ $(STRINGS_Is_Empty "$PROJECT_NODE_BRANCH_TAG") -eq 0 ]; then + return 0 + fi + + __branch="${__branch}_${PROJECT_NODE_BRANCH_TAG}" + else + return 0 + fi + + I18N_Publish "git@$__branch" + if [ $(OS_Is_Run_Simulated) -eq 0 ]; then + I18N_Simulate_Publish "$__branch" + return 0 + fi + + ## create workspace directory + __workspace="${PROJECT_PATH_ROOT}/${PROJECT_PATH_TEMP}/release-branch_${__branch}" + GIT_Setup_Workspace_Bare "$PROJECT_SOURCE_GIT_REMOTE" "$__branch" "$__workspace" + if [ $? -ne 0 ]; then + I18N_Publish_Failed + return 1 + fi + + ## unpack package into directory + if [ $(FS_Is_Target_A_TARGZ "$1") -eq 0 ]; then + TAR_Extract_GZ "$__workspace" "$1" + elif [ $(FS_Is_Target_A_TARXZ "$1") -eq 0 ]; then + TAR_Extract_XZ "$__workspace" "$1" + elif [ $(FS_Is_Target_A_ZIP "$1") -eq 0 ]; then + ZIP_Extract "$__workspace" "$1" + else + FS_Copy_File "$1" "${__workspace}" + fi + + if [ $? -ne 0 ]; then + I18N_Publish_Failed + return 1 + fi + + ## commit release + __current_path="$PWD" && cd "$__workspace" + GIT_Autonomous_Commit "$__branch" + ___process=$? + cd "$__current_path" && unset __current_path + if [ $___process -ne 0 ]; then + I18N_Publish_Failed + return 1 + fi + + ## push to upstream + GIT_Push_Specific "$__workspace" \ + "$PROJECT_SOURCE_GIT_REMOTE" \ + "$__branch" \ + "$__branch" + if [ $? -ne 0 ]; then + I18N_Publish_Failed + return 1 + fi + + GIT_Push_Specific "$__workspace" \ + "$PROJECT_SOURCE_GIT_REMOTE" \ + "$__branch" \ + "${PROJECT_SOURCE_RELEASE_TAG_LATEST}_${__branch#*_}" + if [ $? -ne 0 ]; then + I18N_Publish_Failed + return 1 + fi + + + # report status + return 0 +} diff --git a/automataCI/_release-lib_windows-any.ps1 b/automataCI/_release-lib_windows-any.ps1 new file mode 100644 index 00000000..56fe45f1 --- /dev/null +++ b/automataCI/_release-lib_windows-any.ps1 @@ -0,0 +1,137 @@ +# Copyright 2024 (Holloway) Chew, Kean Ho +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\os.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1" +. "${env:LIBS_AUTOMATACI}\services\archive\tar.ps1" +. "${env:LIBS_AUTOMATACI}\services\archive\zip.ps1" +. "${env:LIBS_AUTOMATACI}\services\i18n\translations.ps1" +. "${env:LIBS_AUTOMATACI}\services\versioners\git.ps1" + + + + +# initialize +if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) { + Write-Error "[ ERROR ] - Please run from automataCI\ci.sh.ps1 instead!`n" + return +} + + + + +function RELEASE-Run-LIBS { + param( + [string]$_target + ) + + + # validate input + if ($(STRINGS-Is-Empty "${env:PROJECT_SOURCE_RELEASE_TAG_LATEST}") -eq 0) { + return 0 + } + + $___process = FS-Is-Target-A-Library "${_target}" + if ($___process -ne 0) { + return 0 + } + + if ($(STRINGS-Is-Empty "${env:PROJECT_SOURCE_GIT_REMOTE}") -eq 0) { + return 0 + } + + $___process = GIT-Is-Available + if ($___process -ne 0) { + return 0 + } + + + # execute + ## identify tag + $__branch = "v${env:PROJECT_VERSION}" + if ($(FS-Is-Target-A-NPM "${_target}") -eq 0) { + if ($(STRINGS-Is-Empty "${env:PROJECT_NODE_BRANCH_TAG}") -eq 0) { + return 0 + } + + $__branch = "${__branch}_${env:PROJECT_NODE_BRANCH_TAG}" + } else { + return 0 + } + + $null = I18N-Publish "git@${__branch}" + if ($(OS-Is-Run-Simulated) -eq 0) { + $null = I18N-Simulate-Publish "${__branch}" + return 0 + } + + ## create workspace directory + $__workspace = "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_TEMP}\release-branch_${_branch}" + $___process = GIT-Setup-Workspace-Bare ` + "${env:PROJECT_SOURCE_GIT_REMOTE}" ` + "${__branch}" ` + "${__workspace}" + if ($___process -ne 0) { + $null = I18N-Publish-Failed + return 1 + } + + ## unpack package into directory + if ($(FS-Is-Target-A-TARGZ "$1") -eq 0) { + $___process = TAR-Extract-GZ "${__workspace}" "${_target}" + } elseif ($(FS-Is-Target-A-TARXZ "$1") -eq 0) { + $___process = TAR-Extract-XZ "${__workspace}" "${_target}" + } elseif ($(FS-Is-Target-A-ZIP "$1") -eq 0) { + $___process = ZIP-Extract "${__workspace}" "${_target}" + } else { + $___process = FS-Copy-File "${_target}" "${__workspace}" + } + + if ($___process -ne 0) { + $null = I18N-Publish-Failed + return 1 + } + + ## commit release + $__current_path = Get-Location + $null = Set-Location -Path "${__workspace}" + $___process = GIT-Autonomous-Commit "${__branch}" + $null = Set-Location -Path "${__current_path}" + $null = Remove-Variable -Name __current_path + if ($___process -ne 0) { + $null = I18N-Publish-Failed + return 1 + } + + ## push to upstream + $___process = GIT-Push-Specific "${__workspace}" ` + "${env:PROJECT_SOURCE_GIT_REMOTE}" ` + "${__branch}" + "${__branch}" + if ($___process -ne 0) { + $null = I18N-Publish-Failed + return 1 + } + + $___process = GIT-Push-Specific "${__workspace}" ` + "${env:PROJECT_SOURCE_GIT_REMOTE}" ` + "${__branch}" + "${env:PROJECT_SOURCE_RELEASE_TAG_LATEST}_$($__branch -replace "^.*_", '')" + if ($___process -ne 0) { + $null = I18N-Publish-Failed + return 1 + } + + + # report status + return 0 +} diff --git a/automataCI/_release-npm_unix-any.sh b/automataCI/_release-npm_unix-any.sh index 771263b6..d3090853 100644 --- a/automataCI/_release-npm_unix-any.sh +++ b/automataCI/_release-npm_unix-any.sh @@ -49,7 +49,7 @@ RELEASE_Run_NPM() { I18N_Check_Login "NPM" NODE_NPM_Check_Login if [ $? -eq 0 ]; then - I18N_Publish "$1" + I18N_Publish "NPM" if [ $(OS_Is_Run_Simulated) -eq 0 ]; then I18N_Simulate_Publish "$1" else diff --git a/automataCI/_release-npm_windows-any.ps1 b/automataCI/_release-npm_windows-any.ps1 index be16bf19..0d620d8b 100644 --- a/automataCI/_release-npm_windows-any.ps1 +++ b/automataCI/_release-npm_windows-any.ps1 @@ -50,7 +50,7 @@ function RELEASE-Run-NPM { $null = I18N-Check-Login "NPM" $___process = NODE-NPM-Check-Login if ($___process -eq 0) { - $null = I18N-Publish "${_target}" + $null = I18N-Publish "NPM" if ($(OS-Is-Run-Simulated) -ne 0) { $null = I18N-Simulate-Publish "${_target}" } else { diff --git a/automataCI/release_unix-any.sh b/automataCI/release_unix-any.sh index ce493196..8aeef6ab 100644 --- a/automataCI/release_unix-any.sh +++ b/automataCI/release_unix-any.sh @@ -32,6 +32,7 @@ fi . "${LIBS_AUTOMATACI}/_release-deb_unix-any.sh" . "${LIBS_AUTOMATACI}/_release-docker_unix-any.sh" . "${LIBS_AUTOMATACI}/_release-homebrew_unix-any.sh" +. "${LIBS_AUTOMATACI}/_release-lib_unix-any.sh" . "${LIBS_AUTOMATACI}/_release-npm_unix-any.sh" . "${LIBS_AUTOMATACI}/_release-pypi_unix-any.sh" . "${LIBS_AUTOMATACI}/_release-rpm_unix-any.sh" @@ -123,6 +124,11 @@ for TARGET in "${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}"/*; do return 1 fi + RELEASE_Run_LIBS "$TARGET" + if [ $? -ne 0 ]; then + return 1 + fi + RELEASE_Run_HOMEBREW "$TARGET" "$HOMEBREW_REPO" if [ $? -ne 0 ]; then return 1 diff --git a/automataCI/release_windows-any.ps1 b/automataCI/release_windows-any.ps1 index 19bfa646..a1674399 100644 --- a/automataCI/release_windows-any.ps1 +++ b/automataCI/release_windows-any.ps1 @@ -31,6 +31,7 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) { . "${env:LIBS_AUTOMATACI}\_release-deb_windows-any.ps1" . "${env:LIBS_AUTOMATACI}\_release-docker_windows-any.ps1" . "${env:LIBS_AUTOMATACI}\_release-homebrew_windows-any.ps1" +. "${env:LIBS_AUTOMATACI}\_release-lib_windows-any.ps1" . "${env:LIBS_AUTOMATACI}\_release-npm_windows-any.ps1" . "${env:LIBS_AUTOMATACI}\_release-pypi_windows-any.ps1" . "${env:LIBS_AUTOMATACI}\_release-rpm_windows-any.ps1" @@ -131,6 +132,11 @@ if (Test-Path -PathType Container -Path "${PACKAGE_DIRECTORY}") { return 1 } + $___process = RELEASE-Run-LIBS "$TARGET" + if ($___process -ne 0) { + return 1 + } + $___process = RELEASE-Run-NPM "$TARGET" if ($___process -ne 0) { return 1 diff --git a/automataCI/services/compilers/node.sh b/automataCI/services/compilers/node.sh index 18407b4b..582d58c6 100644 --- a/automataCI/services/compilers/node.sh +++ b/automataCI/services/compilers/node.sh @@ -199,8 +199,7 @@ NODE_NPM_Is_Valid() { # execute - FS_Is_Target_A_NPM "$1" - if [ $? -ne 0 ]; then + if [ $(FS_Is_Target_A_NPM "$1") -ne 0 ]; then return 1 fi diff --git a/automataCI/services/io/fs.ps1 b/automataCI/services/io/fs.ps1 index 82d9d0d5..b12736d0 100644 --- a/automataCI/services/io/fs.ps1 +++ b/automataCI/services/io/fs.ps1 @@ -578,6 +578,46 @@ function FS-Is-Target-A-Source { +function FS-Is-Target-A-TARGZ { + param ( + [string]$___target + ) + + + # execute + if (($("${___target}" -replace '^.*.tar.gz') -ne "${___target}") -or + ($("${___target}" -replace '^.*.tgz') -ne "${___target}")) { + return 0 + } + + + # report status + return 1 +} + + + + +function FS-Is-Target-A-TARXZ { + param ( + [string]$___target + ) + + + # execute + if (($("${___target}" -replace '^.*.tar.xz') -ne "${___target}") -or + ($("${___target}" -replace '^.*.txz') -ne "${___target}")) { + return 0 + } + + + # report status + return 1 +} + + + + function FS-Is-Target-A-WASM { param ( [string]$___target @@ -646,6 +686,25 @@ function FS-Is-Target-Exist { +function FS-Is-Target-A-ZIP { + param ( + [string]$___target + ) + + + # execute + if ($("${___target}" -replace '^.*.zip') -ne "${___target}") { + return 0 + } + + + # report status + return 1 +} + + + + function FS-List-All { param ( [string]$___target diff --git a/automataCI/services/io/fs.sh b/automataCI/services/io/fs.sh index 0e12c067..d043cc3c 100644 --- a/automataCI/services/io/fs.sh +++ b/automataCI/services/io/fs.sh @@ -534,6 +534,44 @@ FS_Is_Target_A_Source() { +FS_Is_Target_A_TARGZ() { + #___target="$1" + + + # execute + if [ "${1#*.tar.gz}" != "$1" ] || [ "${1#*.tgz}" != "$1" ]; then + printf -- "0" + return 0 + fi + + + # report status + printf -- "1" + return 1 +} + + + + +FS_Is_Target_A_TARXZ() { + #___target="$1" + + + # execute + if [ "${1#*.tar.xz}" != "$1" ] || [ "${1#*.txz}" != "$1" ]; then + printf -- "0" + return 0 + fi + + + # report status + printf -- "1" + return 1 +} + + + + FS_Is_Target_A_WASM() { #___target="$1" @@ -577,6 +615,25 @@ FS_Is_Target_A_WASM_JS() { +FS_Is_Target_A_ZIP() { + #___target="$1" + + + # execute + if [ "${1#*.zip}" != "$1" ]; then + printf -- "0" + return 0 + fi + + + # report status + printf -- "1" + return 1 +} + + + + FS_Is_Target_Exist() { #___target="$1" diff --git a/automataCI/services/versioners/git.ps1 b/automataCI/services/versioners/git.ps1 index 4bbe961c..2b0b7bc5 100644 --- a/automataCI/services/versioners/git.ps1 +++ b/automataCI/services/versioners/git.ps1 @@ -1,4 +1,4 @@ -# Copyright 2023 (Holloway) Chew, Kean Ho +# Copyright 2023 (Holloway) Chew, Kean Ho # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy @@ -475,6 +475,47 @@ function GIT-Push { +function GIT-Push-Specific { + param( + [string]$___workspace, + [string]$___remote, + [string]$___source, + [string]$___target + ) + + + # validate input + if (($(STRINGS-Is-Empty "${___workspace}") -eq 0) -or + ($(STRINGS-Is-Empty "${___remote}") -eq 0) -or + ($(STRINGS-Is-Empty "${___source}") -eq 0) -or + ($(STRINGS-Is-Empty "${___target}") -eq 0)) { + return 1 + } + + $___process = GIT-Is-Available + if ($___process -ne 0) { + return 1 + } + + + # execute + $___current_path = Get-Location + $null = Set-Location -Path "${___workspace}" + $___process = OS-Exec "git" "push -f `"${___remote}`" `"${___source}`":`"${___target}`"" + $null = Set-Location -Path "${___current_path}" + $null = Remove-Variable -Name ___current_path + if ($___process -ne 0) { + return 1 + } + + + # report status + return 0 +} + + + + function GIT-Remove-Worktree { param ( [string]$___destination @@ -541,3 +582,66 @@ function GIT-Setup-Worktree { # report status return 0 } + + + + +function GIT-Setup-Workspace-Bare { + param( + [string]$___remote, + [string]$___branch, + [string]$___destination + ) + + + # validate input + if (($(STRINGS-Is-Empty "${___remote}") -eq 0) -or + ($(STRINGS-Is-Empty "${___branch}") -eq 0) -or + ($(STRINGS-Is-Empty "${___destination}") -eq 0)) { + return 1 + } + + $___process = GIT-Is-Available + if ($___process -ne 0) { + return 1 + } + + + # execute + $___url = "$(GIT-Get-Remote-URL "${___remote}")" + if ($(STRINGS-Is-Empty "${___url}") -eq 0) { + return 1 + } + + $null = FS-Remake-Directory "${___destination}" + $___current_path = Get-Location + $null = Set-Location -Path "${___workspace}" + + $___process = OS-Exec "git" "init" + if ($___process -ne 0) { + $null = Set-Location -Path "${___current_path}" + $null = Remove-Variable -Name ___current_path + return 1 + } + + $___process = OS-Exec "git" "remote add `"${___remote}`" `"${___url}`"" + if ($___process -ne 0) { + $null = Set-Location -Path "${___current_path}" + $null = Remove-Variable -Name ___current_path + return 1 + } + + $___process = OS-Exec "git" "checkout --orphan `"${___branch}`"" + if ($___process -ne 0) { + $null = Set-Location -Path "${___current_path}" + $null = Remove-Variable -Name ___current_path + return 1 + } + + $null = Set-Location -Path "${___current_path}" + $null = Remove-Variable -Name ___current_path + + + # report status + return 0 +} diff --git a/automataCI/services/versioners/git.sh b/automataCI/services/versioners/git.sh index 5568c4a5..ccc031c3 100644 --- a/automataCI/services/versioners/git.sh +++ b/automataCI/services/versioners/git.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright 2023 (Holloway) Chew, Kean Ho +# Copyright 2023 (Holloway) Chew, Kean Ho # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of @@ -336,6 +336,29 @@ GIT_Get_Latest_Commit_ID() { +GIT_Get_Remote_URL() { + #___remote="$1" + + # validate input + if [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then + return 1 + fi + + + # execute + printf -- "%s" "$(git remote get-url "$1")" + if [ $? -ne 0 ]; then + return 1 + fi + + + # report status + return 0 +} + + + + GIT_Get_Root_Directory() { # validate input GIT_Is_Available @@ -475,6 +498,44 @@ GIT_Push() { +GIT_Push_Specific() { + #___workspace="$1" + #___remote="$2" + #___source="$3" + #___target="$4" + + + # validate input + if [ $(STRINGS_Is_Empty "$1") -eq 0 ] || + [ $(STRINGS_Is_Empty "$2") -eq 0 ] || + [ $(STRINGS_Is_Empty "$3") -eq 0 ] || + [ $(STRINGS_Is_Empty "$4") -eq 0 ]; then + return 1 + fi + + GIT_Is_Available + if [ $? -ne 0 ]; then + return 1 + fi + + + # execute + ___current_path="$PWD" && cd "$1" + git push -f "$2" "$3":"$4" + ___process=$? + cd "$___current_path" && unset ___current_path + if [ $? -ne 0 ]; then + return 1 + fi + + + # report status + return 0 +} + + + + GIT_Remove_Worktree() { #___destination="$1" @@ -536,3 +597,58 @@ GIT_Setup_Worktree() { # report status return 0 } + + + + +GIT_Setup_Workspace_Bare() { + #___remote="$1" + #___branch="$2" + #___destination="$3" + + + # validate input + if [ $(STRINGS_Is_Empty "$1") -eq 0 ] || + [ $(STRINGS_Is_Empty "$2") -eq 0 ] || + [ $(STRINGS_Is_Empty "$3") -eq 0 ]; then + return 1 + fi + + GIT_Is_Available + if [ $? -ne 0 ]; then + return 1 + fi + + + # execute + ___url="$(GIT_Get_Remote_URL "$1")" + if [ $(STRINGS_Is_Empty "$___url") -eq 0 ]; then + return 1 + fi + + FS_Remake_Directory "$3" + ___current_path="$PWD" && cd "$3" + git init &> /dev/null + if [ $? -ne 0 ]; then + cd "$___current_path" && unset ___current_path + return 1 + fi + + git remote add "$1" "$___url" + if [ $? -ne 0 ]; then + cd "$___current_path" && unset ___current_path + return 1 + fi + + git checkout --orphan "$2" + if [ $? -ne 0 ]; then + cd "$___current_path" && unset ___current_path + return 1 + fi + + cd "$___current_path" && unset ___current_path + + + # report status + return 0 +}