From 7ae307b8bbd6abd29854ea2d7717541a0e80fbb4 Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Sat, 8 Jun 2024 17:42:15 +0800 Subject: [PATCH] automataCI: upgraded from npm to libraries packaging Since npm is a library itself, we can proceed to create a libraries CI tasks instead of serving specifically for NPM. That way, other technologies' libraries can share the same production processes for maximum consistencies. Hence, let's do this. This patch upgrades from npm to libraries packaging 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 | 27 +++ ...m_unix-any.sh => _package-lib_unix-any.sh} | 4 +- ...s-any.ps1 => _package-lib_windows-any.ps1} | 4 +- automataCI/package_unix-any.sh | 8 +- automataCI/package_windows-any.ps1 | 10 +- src/.ci/_package-lib_unix-any.sh | 189 ++++++++++++++++++ ...s-any.ps1 => _package-lib_windows-any.ps1} | 25 ++- src/.ci/_package-npm_unix-any.sh | 54 ----- src/.ci/package_unix-any.sh | 2 +- src/.ci/package_windows-any.ps1 | 2 +- 10 files changed, 248 insertions(+), 77 deletions(-) rename automataCI/{_package-npm_unix-any.sh => _package-lib_unix-any.sh} (96%) rename automataCI/{_package-npm_windows-any.ps1 => _package-lib_windows-any.ps1} (96%) create mode 100644 src/.ci/_package-lib_unix-any.sh rename src/.ci/{_package-npm_windows-any.ps1 => _package-lib_windows-any.ps1} (64%) delete mode 100644 src/.ci/_package-npm_unix-any.sh diff --git a/CONFIG.toml b/CONFIG.toml index b6ca9b4..7e69bae 100644 --- a/CONFIG.toml +++ b/CONFIG.toml @@ -169,6 +169,33 @@ PROJECT_SOURCE_GIT_REMOTE = 'origin' PROJECT_SOURCE_RELEASE_TAG_LATEST = 'latest' +# PROJECT_README +# The relative location of the project readme file from $PROJECT_PATH_ROOT +# (repository root directory). +# +# Default is 'README.md' +PROJECT_README = 'README.md' + + +# PROJECT_LICENSE_FILE +# The relative location of the project license file from $PROJECT_PATH_ROOT +# (repository root directory). +# +# Default is 'LICENSE.txt' +PROJECT_LICENSE_FILE = 'LICENSE.txt' + + +# PROJECT_LICENSE_ACCEPTANCE_REQUIRED +# The flag to indicate the license of the project **MUST** be explictly +# accepted. This is used in ecosystem like .NET nupkg where a special UI +# is available to interact with the end-users. +# +# Value is lowercase 'true' or 'false'. +# +# Default is 'true' +PROJECT_LICENSE_ACCEPTANCE_REQUIRED = 'true' + + # AUTOMATACI_LANG # Overrides AutomataCI to operate in 1 specific language. Otherwise, AutomataCI # shall query the system language settings. Only accepts language code complying diff --git a/automataCI/_package-npm_unix-any.sh b/automataCI/_package-lib_unix-any.sh similarity index 96% rename from automataCI/_package-npm_unix-any.sh rename to automataCI/_package-lib_unix-any.sh index ef5c70e..c9b6cbb 100644 --- a/automataCI/_package-npm_unix-any.sh +++ b/automataCI/_package-lib_unix-any.sh @@ -26,7 +26,7 @@ fi -PACKAGE_Run_NPM() { +PACKAGE_Run_LIB() { #__line="$1" @@ -50,7 +50,7 @@ PACKAGE_Run_NPM() { # copy all complimentary files to the workspace - cmd="PACKAGE_Assemble_NPM_Content" + cmd="PACKAGE_Assemble_LIB_Content" I18N_Check_Function "$cmd" OS_Is_Command_Available "$cmd" if [ $? -ne 0 ]; then diff --git a/automataCI/_package-npm_windows-any.ps1 b/automataCI/_package-lib_windows-any.ps1 similarity index 96% rename from automataCI/_package-npm_windows-any.ps1 rename to automataCI/_package-lib_windows-any.ps1 index 8a84999..99c3d45 100644 --- a/automataCI/_package-npm_windows-any.ps1 +++ b/automataCI/_package-lib_windows-any.ps1 @@ -25,7 +25,7 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) { -function PACKAGE-Run-NPM { +function PACKAGE-Run-LIB { param ( [string]$__line ) @@ -41,7 +41,7 @@ function PACKAGE-Run-NPM { # copy all complimentary files to the workspace - $cmd = "PACKAGE-Assemble-NPM-Content" + $cmd = "PACKAGE-Assemble-LIB-Content" $null = I18N-Check-Function "$cmd" $___process = OS-Is-Command-Available "$cmd" if ($___process -ne 0) { diff --git a/automataCI/package_unix-any.sh b/automataCI/package_unix-any.sh index 2e01889..5b16835 100644 --- a/automataCI/package_unix-any.sh +++ b/automataCI/package_unix-any.sh @@ -35,8 +35,8 @@ fi . "${LIBS_AUTOMATACI}/_package-flatpak_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-homebrew_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-ipk_unix-any.sh" +. "${LIBS_AUTOMATACI}/_package-lib_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-msi_unix-any.sh" -. "${LIBS_AUTOMATACI}/_package-npm_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-pdf_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-pypi_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-rpm_unix-any.sh" @@ -253,9 +253,9 @@ ${__common}|${__log}|PACKAGE_Run_MSI return 1 fi - __log="${__log_directory}/npm_${TARGET_FILENAME}_${TARGET_OS}-${TARGET_ARCH}.log" - FS_Append_File "$__serial_control" "\ -${__common}|${__log}|PACKAGE_Run_NPM + __log="${__log_directory}/lib_${TARGET_FILENAME}_${TARGET_OS}-${TARGET_ARCH}.log" + FS_Append_File "$__parallel_control" "\ +${__common}|${__log}|PACKAGE_Run_LIB " if [ $? -ne 0 ]; then return 1 diff --git a/automataCI/package_windows-any.ps1 b/automataCI/package_windows-any.ps1 index e41163c..d80a46d 100644 --- a/automataCI/package_windows-any.ps1 +++ b/automataCI/package_windows-any.ps1 @@ -111,8 +111,8 @@ function SUBROUTINE-Package { $null = . "${env:LIBS_AUTOMATACI}\_package-flatpak_windows-any.ps1" $null = . "${env:LIBS_AUTOMATACI}\_package-homebrew_windows-any.ps1" $null = . "${env:LIBS_AUTOMATACI}\_package-ipk_windows-any.ps1" + $null = . "${env:LIBS_AUTOMATACI}\_package-lib_windows-any.ps1" $null = . "${env:LIBS_AUTOMATACI}\_package-msi_windows-any.ps1" - $null = . "${env:LIBS_AUTOMATACI}\_package-npm_windows-any.ps1" $null = . "${env:LIBS_AUTOMATACI}\_package-pdf_windows-any.ps1" $null = . "${env:LIBS_AUTOMATACI}\_package-pypi_windows-any.ps1" $null = . "${env:LIBS_AUTOMATACI}\_package-rpm_windows-any.ps1" @@ -268,9 +268,9 @@ ${__common}|${__log}|PACKAGE-Run-MSI return 1 } - $__log = "${__log_directory}\npm_${TARGET_FILENAME}_${TARGET_OS}-${TARGET_ARCH}.log" - $___process = FS-Append-File "${__serial_control}" @" -${__common}|${__log}|PACKAGE-Run-NPM + $__log = "${__log_directory}\lib_${TARGET_FILENAME}_${TARGET_OS}-${TARGET_ARCH}.log" + $___process = FS-Append-File "${__paralllel_control}" @" +${__common}|${__log}|PACKAGE-Run-LIB "@ if ($___process -ne 0) { return 1 @@ -306,7 +306,7 @@ ${__common}|${__log}|PACKAGE-Run-RPM $null = I18N-Sync-Run $___process = FS-Is-File "${__parallel_control}" if ($___process -eq 0) { - $___process = SYNC-Exec-Parallel ` + $___process = SYNC-Exec-Parellel ` ${function:SUBROUTINE-Package}.ToString() ` "${__parallel_control}" ` "${__control_directory}" diff --git a/src/.ci/_package-lib_unix-any.sh b/src/.ci/_package-lib_unix-any.sh new file mode 100644 index 0000000..0cd73de --- /dev/null +++ b/src/.ci/_package-lib_unix-any.sh @@ -0,0 +1,189 @@ +#!/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/strings.sh" +. "${LIBS_AUTOMATACI}/services/archive/tar.sh" +. "${LIBS_AUTOMATACI}/services/archive/zip.sh" +. "${LIBS_AUTOMATACI}/services/i18n/translations.sh" + + + + +# initialize +if [ "$PROJECT_PATH_ROOT" = "" ]; then + >&2 printf "[ ERROR ] - Please run from automataCI/ci.sh.ps1 instead!\n" + return 1 +fi + + + + +PACKAGE_Assemble_LIB_Content() { + _target="$1" + _directory="$2" + _target_name="$3" + _target_os="$4" + _target_arch="$5" + + + # validate project + if [ $(FS_Is_Target_A_LIB "$_target") -ne 0 ]; then + return 10 # not applicable + fi + + + # execute + ## copy over known archived files + if [ $(FS_Is_Target_A_NPM "$_target") -eq 0 ]; then + __dest="lib${PROJECT_SKU}-NPM_${PROJECT_VERSION}_js-js.tgz" + __dest="${_directory}/${__dest}" + I18N_Copy "$_target" "$__dest" + FS_Copy_File "$_target" "$__dest" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + return 0 + elif [ $(FS_Is_Target_A_TARGZ "$_target") -eq 0 ]; then + __dest="lib${PROJECT_SKU}_${PROJECT_VERSION}_${_target_os}-${target_arch}.tar.gz" + __dest="${_directory}/${__dest}" + I18N_Copy "$_target" "$__dest" + FS_Copy_File "$_target" "$__dest" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + return 0 + elif [ $(FS_Is_Target_A_TARXZ "$_target") -eq 0 ]; then + __dest="lib${PROJECT_SKU}_${PROJECT_VERSION}_${_target_os}-${target_arch}.tar.xz" + __dest="${_directory}/${__dest}" + I18N_Copy "$_target" "$__dest" + FS_Copy_File "$_target" "$__dest" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + return 0 + elif [ $(FS_Is_Target_A_ZIP "$_target") -eq 0 ]; then + __dest="lib${PROJECT_SKU}_${PROJECT_VERSION}_${_target_os}-${target_arch}.zip" + __dest="${_directory}/${__dest}" + I18N_Copy "$_target" "$__dest" + FS_Copy_File "$_target" "$__dest" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + return 0 + fi + + ## assume standalone library file - manually package into .tar.xz, .zip, and .nupkg + __workspace="${PROJECT_PATH_ROOT}/${PROJECT_PATH_TEMP}/package-${_target_name}" + FS_Remake_Directory "$__workspace" + I18N_Copy "$_target" "$__workspace" + FS_Copy_File "$_target" "$__workspace" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + __source="${PROJECT_PATH_ROOT}/${PROJECT_README}" + I18N_Copy "$__source" "$__workspace" + FS_Copy_File "$__source" "$__workspace" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + __source="${PROJECT_PATH_ROOT}/${PROJECT_LICENSE_FILE}" + I18N_Copy "$__source" "$__workspace" + FS_Copy_File "$__source" "$__workspace" + if [ $? -ne 0 ]; then + I18N_Copy_Failed + return 1 + fi + + __current_path="$PWD" && cd "$__workspace" + ## package tar.xz + __dest="lib${PROJECT_SKU}_${PROJECT_VERSION}_${_target_os}-${_target_arch}.tar.xz" + I18N_Create_Package "$__dest" + __dest="${_directory}/${__dest}" + TAR_Create_XZ "$__dest" "." + if [ $? -ne 0 ]; then + I18N_Create_Failed + cd "$__current_path" && unset __current_path + return 1 + fi + + ## package zip + __dest="lib${PROJECT_SKU}_${PROJECT_VERSION}_${_target_os}-${_target_arch}.zip" + I18N_Create_Package "$__dest" + __dest="${_directory}/${__dest}" + ZIP_Create "$__dest" "." + if [ $? -ne 0 ]; then + I18N_Create_Failed + cd "$__current_path" && unset __current_path + return 1 + fi + + ## package nupkg + __dest="./Package.nuspec" + __acceptance="false" + if [ $(STRINGS_To_Lowercase "$PROJECT_LICENSE_ACCEPTANCE_REQUIRED") = "true" ]; then + __acceptance="true" + fi + + I18N_Create "$__dest" + FS_Write_File "$__dest" "\ + + + + ${PROJECT_SKU} + ${PROJECT_VERSION} + ${PROJECT_CONTACT_NAME} + ${PROJECT_CONTACT_NAME} + ${PROJECT_SOURCE_URL} + ${PROJECT_NAME} + ${PROJECT_PITCH} + ${PROJECT_LICENSE} + ${__acceptance} + ${PROJECT_README} + + +" + if [ $? -ne 0 ]; then + I18N_Create_Failed + cd "$__current_path" && unset __current_path + return 1 + fi + + __dest="lib${PROJECT_SKU}_${PROJECT_VERSION}_${_target_os}-${_target_arch}.nupkg" + I18N_Create_Package "$__dest" + __dest="${_directory}/${__dest}" + ZIP_Create "$__dest" "." + if [ $? -ne 0 ]; then + I18N_Create_Failed + cd "$__current_path" && unset __current_path + return 1 + fi + + ## done - clean up + cd "$__current_path" && unset __current_path + + + # report status + return 0 +} diff --git a/src/.ci/_package-npm_windows-any.ps1 b/src/.ci/_package-lib_windows-any.ps1 similarity index 64% rename from src/.ci/_package-npm_windows-any.ps1 rename to src/.ci/_package-lib_windows-any.ps1 index 0504243..0610c46 100644 --- a/src/.ci/_package-npm_windows-any.ps1 +++ b/src/.ci/_package-lib_windows-any.ps1 @@ -10,6 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. . "${env:LIBS_AUTOMATACI}\services\io\fs.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" @@ -24,7 +27,7 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) { -function PACKAGE-Assemble-NPM-Content { +function PACKAGE-Assemble-LIB-Content { param ( [string]$_target, [string]$_directory, @@ -35,18 +38,24 @@ function PACKAGE-Assemble-NPM-Content { # validate project - if ($(FS-Is-Target-A-NPM "${_target}") -ne 0) { + if ($(FS-Is-Target-A-Library "${_target}") -ne 0) { return 10 # not applicable } # execute - $__dest = "${_directory}\lib${env:PROJECT_SKU}-npm_${env:PROJECT_VERSION}_js-js.tgz" - $null = I18N-Copy "${_target}" "${__dest}" - $___process = FS-Copy-File "${_target}" "${__dest}" - if ($___process -ne 0) { - $null = I18N-Copy-Failed - return 1 + ## copy over known archived files + if ($(FS-Is-Target-A-NPM "${_target}") -eq 0) { + $__dest = "lib${env:PROJECT_SKU}-NPM_${env:PROJECT_VERSION}_js-js.tgz" + $__dest = "${_directory}\${__dest}" + $null = I18N-Copy "${_target}" "${__dest}" + $___process = FS-Copy-File "${_target}" "${__dest}" + if ($___process -ne 0) { + $null = I18N-Copy-Failed + return 1 + } + + return 0 } diff --git a/src/.ci/_package-npm_unix-any.sh b/src/.ci/_package-npm_unix-any.sh deleted file mode 100644 index d3c40cd..0000000 --- a/src/.ci/_package-npm_unix-any.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/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/i18n/translations.sh" - - - - -# initialize -if [ "$PROJECT_PATH_ROOT" = "" ]; then - >&2 printf "[ ERROR ] - Please run from automataCI/ci.sh.ps1 instead!\n" - return 1 -fi - - - - -PACKAGE_Assemble_NPM_Content() { - _target="$1" - _directory="$2" - _target_name="$3" - _target_os="$4" - _target_arch="$5" - - - # validate project - if [ $(FS_Is_Target_A_NPM "$_target") -ne 0 ]; then - return 10 # not applicable - fi - - - # execute - __dest="${_directory}/lib${PROJECT_SKU}-npm_${PROJECT_VERSION}_js-js.tgz" - I18N_Copy "$_target" "$__dest" - FS_Copy_File "$_target" "$__dest" - if [ $? -ne 0 ]; then - I18N_Copy_Failed - return 1 - fi - - - # report status - return 0 -} diff --git a/src/.ci/package_unix-any.sh b/src/.ci/package_unix-any.sh index 83a6d86..e81727d 100644 --- a/src/.ci/package_unix-any.sh +++ b/src/.ci/package_unix-any.sh @@ -28,8 +28,8 @@ fi . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-flatpak_unix-any.sh" . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-homebrew_unix-any.sh" . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-ipk_unix-any.sh" +. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-lib_unix-any.sh" . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-msi_unix-any.sh" -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-npm_unix-any.sh" . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-pdf_unix-any.sh" . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-pypi_unix-any.sh" . "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/${PROJECT_PATH_CI}/_package-rpm_unix-any.sh" diff --git a/src/.ci/package_windows-any.ps1 b/src/.ci/package_windows-any.ps1 index dfb0de3..6423336 100644 --- a/src/.ci/package_windows-any.ps1 +++ b/src/.ci/package_windows-any.ps1 @@ -27,8 +27,8 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) { . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-flatpak_windows-any.ps1" . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-homebrew_windows-any.ps1" . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-ipk_windows-any.ps1" +. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-lib_windows-any.ps1" . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-msi_windows-any.ps1" -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-npm_windows-any.ps1" . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-pdf_windows-any.ps1" . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-pypi_windows-any.ps1" . "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\${env:PROJECT_PATH_CI}\_package-rpm_windows-any.ps1"