Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Homebrew generates first character directory on release #314

Open
hollowaykeanho opened this issue Mar 31, 2024 · 4 comments
Open
Assignees
Labels
Done and Pending Release Completed and staging for next release. Enhancement Case is about improving an existing feature/aspect.

Comments

@hollowaykeanho
Copy link
Member

Description

right now, the formula is not directory oriented (possibly for quick performance search). Hence, it's better to align with the upstream implementations.

Expected Behavior

Homebrew release shall generate first character directory housing the formula.

Current Behavior

Homebrew release does not generate first character directory housing the formula.

Associated Data Files

No response

@hollowaykeanho hollowaykeanho added the Enhancement Case is about improving an existing feature/aspect. label Mar 31, 2024
@hollowaykeanho hollowaykeanho self-assigned this Mar 31, 2024
@github-project-automation github-project-automation bot moved this to Buckets in AutomataCI Mar 31, 2024
@hollowaykeanho
Copy link
Member Author

Fix:

diff --git a/automataCI/services/publishers/homebrew.ps1 b/automataCI/services/publishers/homebrew.ps1
index 8a44dab..2d1b0a5 100644
--- a/automataCI/services/publishers/homebrew.ps1
+++ b/automataCI/services/publishers/homebrew.ps1
@@ -64,10 +64,9 @@ function HOMEBREW-Publish {
 
 
        # execute
-       $null = FS-Make-Directory "${___destination}"
-       $___process = FS-Copy-File `
-               "${___target}" `
-               "${___destination}\$(Split-Path -Leaf -Path "${___target}")"
+       $___dest = "${___destination}\$($___target.Substring(0,1))\$(FS-Get-File "${___target}")"
+       $null = FS-Make-Housing-Directory "${___dest}"
+       $___process = FS-Copy-File "${___target}" "${___dest}"
        if ($___process -ne 0) {
                return 1
        }
diff --git a/automataCI/services/publishers/homebrew.sh b/automataCI/services/publishers/homebrew.sh
index ba34251..9d1eba0 100644
--- a/automataCI/services/publishers/homebrew.sh
+++ b/automataCI/services/publishers/homebrew.sh
@@ -60,8 +60,9 @@ HOMEBREW_Publish() {
 
 
         # execute
-        FS_Make_Housing_Directory "$2"
-        FS_Copy_File "$1" "$2"
+        ___dest="${2}/$(printf -- %.1s "$1")/$(FS_Get_File "$1")"
+        FS_Make_Housing_Directory "$___dest"
+        FS_Copy_File "$1" "$___dest"
         if [ $? -ne 0 ]; then
                 return 1
         fi

@hollowaykeanho hollowaykeanho moved this from Buckets to v2.2.0 in AutomataCI Mar 31, 2024
@hollowaykeanho
Copy link
Member Author

Actual fix:

diff --git a/automataCI/_release-homebrew_unix-any.sh b/automataCI/_release-homebrew_unix-any.sh
index 627210a..42bbe2c 100644
--- a/automataCI/_release-homebrew_unix-any.sh
+++ b/automataCI/_release-homebrew_unix-any.sh
@@ -47,7 +47,9 @@ RELEASE_Run_HOMEBREW() {
 
 
         # execute
-        HOMEBREW_Publish "$1" "${2}/Formula/${PROJECT_SKU}.rb"
+        HOMEBREW_Publish \
+                "$1" \
+                "${2}/Formula/$(printf -- "%.1s" "${PROJECT_SKU}")/${PROJECT_SKU}.rb"
         if [ $? -ne 0 ]; then
                 I18N_Export_Failed
                 return 1
diff --git a/automataCI/_release-homebrew_windows-any.ps1 b/automataCI/_release-homebrew_windows-any.ps1
index 30c4871..0e0b21c 100644
--- a/automataCI/_release-homebrew_windows-any.ps1
+++ b/automataCI/_release-homebrew_windows-any.ps1
@@ -49,7 +49,9 @@ function RELEASE-Run-HOMEBREW {
 
 
        # execute
-       $___process = HOMEBREW-Publish "${___target}" "${___repo}/Formula/${env:PROJECT_SKU}.rb"
+       $___process = HOMEBREW-Publish `
+               "${___target}" `
+               "${___repo}\Formula\$(${env:PROJECT_SKU}.Substring(0,1))\${env:PROJECT_SKU}.rb"
        if ($___process -ne 0) {
                $null = I18N-Export-Failed
                return 1
diff --git a/automataCI/services/publishers/homebrew.ps1 b/automataCI/services/publishers/homebrew.ps1
index 2d1b0a5..2541bad 100644
--- a/automataCI/services/publishers/homebrew.ps1
+++ b/automataCI/services/publishers/homebrew.ps1
@@ -64,9 +64,8 @@ function HOMEBREW-Publish {
 
 
        # execute
-       $___dest = "${___destination}\$($___target.Substring(0,1))\$(FS-Get-File "${___target}")"
-       $null = FS-Make-Housing-Directory "${___dest}"
-       $___process = FS-Copy-File "${___target}" "${___dest}"
+       $null = FS-Make-Housing-Directory "${___destination}"
+       $___process = FS-Copy-File "${___target}" "${___destination}"
        if ($___process -ne 0) {
                return 1
        }
diff --git a/automataCI/services/publishers/homebrew.sh b/automataCI/services/publishers/homebrew.sh
index 9d1eba0..ba34251 100644
--- a/automataCI/services/publishers/homebrew.sh
+++ b/automataCI/services/publishers/homebrew.sh
@@ -60,9 +60,8 @@ HOMEBREW_Publish() {
 
 
         # execute
-        ___dest="${2}/$(printf -- %.1s "$1")/$(FS_Get_File "$1")"
-        FS_Make_Housing_Directory "$___dest"
-        FS_Copy_File "$1" "$___dest"
+        FS_Make_Housing_Directory "$2"
+        FS_Copy_File "$1" "$2"
         if [ $? -ne 0 ]; then
                 return 1
         fi

@hollowaykeanho
Copy link
Member Author

More precise fixes:

diff --git a/automataCI/services/io/strings.ps1 b/automataCI/services/io/strings.ps1
index 1b4d5d4..0def61a 100644
--- a/automataCI/services/io/strings.ps1
+++ b/automataCI/services/io/strings.ps1
@@ -196,3 +196,46 @@ function STRINGS-To-Uppercase {
        # execute
        return $___content.ToUpper()
 }
+
+
+
+
+function STRINGS-To-Uppercase-First-Char {
+       param(
+               [string]$___content
+       )
+
+
+       # valdiate input
+       if ([string]::IsNullOrEmpty($___content)) {
+               return ""
+       }
+
+
+       # execute
+       $___buffer = ""
+       $___resevoir = $___content
+       $___trigger = $true
+       while ($___resevoir -ne "") {
+               ## extract character
+               $___char = $___resevoir.Substring(0, 1)
+               if ($___char -eq "``") {
+                       $___char = $___resevoir.Substring(0, 2)
+               }
+               $___resevoir = $___resevoir -replace "^${___char}", ""
+
+               ## process characters
+               if (($___char -eq " ") -or ($___char -eq "`n")) {
+                       $___trigger = $true
+               } else {
+                       $___char = $___char.ToUpper()
+                       $___trigger = $false
+               }
+
+               $___buffer += $___char
+       }
+
+
+       # report status
+       return $___buffer
+}
diff --git a/automataCI/services/io/strings.sh b/automataCI/services/io/strings.sh
index ed16a95..b3f486a 100644
--- a/automataCI/services/io/strings.sh
+++ b/automataCI/services/io/strings.sh
@@ -200,3 +200,46 @@ STRINGS_To_Uppercase() {
         # report status
         return 0
 }
+
+
+
+
+STRINGS_To_Uppercase_First_Char() {
+        #___content="$1"
+
+
+        # validate input
+        if [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then
+                printf -- ""
+                return 1
+        fi
+
+
+        # execute
+        ___buffer=""
+        ___resevoir="$1"
+        ___trigger=0
+        while [ -n "$___resevoir" ]; do
+                ## extract character
+                ___char="$(printf -- "%.1s" "$___resevoir")"
+                if [ "$___char" = '\' ]; then
+                        ___char="$(printf -- "%.2s" "$___resevoir")"
+                fi
+                ___resevoir="${___resevoir#*${___char}}"
+
+                ## process character
+                if [ "$___char" = " " ] || [ "$___char" = "\n" ]; then
+                        ___trigger=0
+                elif [ $___trigger -eq 0 ]; then
+                        ___char="$(printf -- "%s" "$___char" | tr '[:lower:]' '[:upper:]')"
+                        ___trigger=1
+                fi
+
+                ___buffer="${___buffer}${___char}"
+        done
+
+
+        # report status
+        printf -- "%b" "$___buffer"
+        return 0
+}
diff --git a/src/.ci/_package-homebrew_unix-any.sh b/src/.ci/_package-homebrew_unix-any.sh
index f99caec..beeef14 100644
--- a/src/.ci/_package-homebrew_unix-any.sh
+++ b/src/.ci/_package-homebrew_unix-any.sh
@@ -21,6 +21,7 @@ if [ "$PROJECT_PATH_ROOT" = "" ]; then
 fi
 
 . "${LIBS_AUTOMATACI}/services/io/fs.sh"
+. "${LIBS_AUTOMATACI}/services/io/strings.sh"
 . "${LIBS_AUTOMATACI}/services/i18n/translations.sh"
 
 
@@ -56,17 +57,18 @@ PACKAGE_Assemble_HOMEBREW_Content() {
         ___dest="${_directory}/formula.rb"
         I18N_Create "$___dest"
         FS_Write_File "$___dest" "\
-class ${PROJECT_SKU_TITLECASE} < Formula
+class $(STRINGS_To_Uppercase_First_Char "$PROJECT_SKU") < Formula
   desc \"${PROJECT_PITCH}\"
   homepage \"${PROJECT_CONTACT_WEBSITE}\"
   license \"${PROJECT_LICENSE}\"
-  url \"${PROJECT_HOMEBREW_SOURCE_URL}/${PROJECT_VERSION}/{{ TARGET_PACKAGE }}\"
+  url \"${PROJECT_HOMEBREW_SOURCE_URL}/{{ TARGET_PACKAGE }}\"
   sha256 \"{{ TARGET_SHASUM }}\"
 
 
   def install
     chmod 0755, \"bin/${PROJECT_SKU_TITLECASE}\"
-    bin.install \"bin/${PROJECT_SKU_TITLECASE}\"
+    libexec.install \"bin/${PROJECT_SKU_TITLECASE}\"
+    bin.install_symlink libexec/\"${PROJECT_SKU_TITLECASE}\" => \"${PROJECT_SKU_TITLECASE}\"
   end
 
   test do
diff --git a/src/.ci/_package-homebrew_windows-any.ps1 b/src/.ci/_package-homebrew_windows-any.ps1
index bbd5206..676aeba 100644
--- a/src/.ci/_package-homebrew_windows-any.ps1
+++ b/src/.ci/_package-homebrew_windows-any.ps1
@@ -20,6 +20,7 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) {
 }
 
 . "${env:LIBS_AUTOMATACI}\services\io\fs.ps1"
+. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1"
 . "${env:LIBS_AUTOMATACI}\services\i18n\translations.ps1"
 
 
@@ -57,17 +58,18 @@ function PACKAGE-Assemble-HOMEBREW-Content {
        $___dest = "${_directory}\formula.rb"
        $null = I18N-Create "${___dest}"
        $___process = FS-Write-File "${___dest}" @"
-class ${env:PROJECT_SKU_TITLECASE} < Formula
+class $(STRINGS-To-Uppercase-First-Char "${env:PROJECT_SKU_TITLECASE}") < Formula
   desc "${env:PROJECT_PITCH}"
   homepage "${env:PROJECT_CONTACT_WEBSITE}"
   license "${env:PROJECT_LICENSE}"
-  url "${env:PROJECT_HOMEBREW_SOURCE_URL}/${env:PROJECT_VERSION}/{{ TARGET_PACKAGE }}"
+  url "${env:PROJECT_HOMEBREW_SOURCE_URL}/{{ TARGET_PACKAGE }}"
   sha256 "{{ TARGET_SHASUM }}"
 
 
   def install
     chmod 0755, "bin/${env:PROJECT_SKU_TITLECASE}"
-    bin.install "bin/${env:PROJECT_SKU_TITLECASE}"
+    libexec.install "bin/${env:PROJECT_SKU_TITLECASE}"
+    bin.install_symlink libexec/"${env:PROJECT_SKU_TITLECASE}" => "${env:PROJECT_SKU_TITLECASE}"
   end
 
   test do

@hollowaykeanho hollowaykeanho added the In Progress Someone is working on the case. label May 21, 2024
@hollowaykeanho
Copy link
Member Author

Implemented in 3ad2fc1

@hollowaykeanho hollowaykeanho added Done and Pending Release Completed and staging for next release. and removed In Progress Someone is working on the case. labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Done and Pending Release Completed and staging for next release. Enhancement Case is about improving an existing feature/aspect.
Projects
Status: v3.0.0
Development

No branches or pull requests

1 participant