Skip to content

Commit

Permalink
automataCI: upgraded from npm to libraries packaging
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Galyna, Cory <[email protected]>
Co-authored-by: (Holloway) Chew, Kean Ho <[email protected]>
Signed-off-by: (Holloway) Chew, Kean Ho <[email protected]>
  • Loading branch information
3 people committed Jun 8, 2024
1 parent 9c72753 commit 5988ca2
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 88 deletions.
27 changes: 27 additions & 0 deletions CONFIG.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi



PACKAGE_Run_NPM() {
PACKAGE_Run_LIB() {
#__line="$1"


Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) {



function PACKAGE-Run-NPM {
function PACKAGE-Run-LIB {
param (
[string]$__line
)
Expand All @@ -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) {
Expand All @@ -50,7 +50,7 @@ function PACKAGE-Run-NPM {
}

$null = I18N-Assemble-Package
$___process = PACKAGE-Assemble-NPM-Content `
$___process = PACKAGE-Assemble-LIB-Content `
"${_target}" `
"${_dest}" `
"${_target_filename}" `
Expand Down
8 changes: 4 additions & 4 deletions automataCI/package_unix-any.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions automataCI/package_windows-any.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -268,9 +268,9 @@ ${__common}|${__log}|PACKAGE-Run-MSI
return 1
}

$__log = "${__log_directory}\npm_${TARGET_FILENAME}_${TARGET_OS}-${TARGET_ARCH}.log"
$__log = "${__log_directory}\lib_${TARGET_FILENAME}_${TARGET_OS}-${TARGET_ARCH}.log"
$___process = FS-Append-File "${__serial_control}" @"
${__common}|${__log}|PACKAGE-Run-NPM
${__common}|${__log}|PACKAGE-Run-LIB
"@
if ($___process -ne 0) {
return 1
Expand Down Expand Up @@ -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}"
Expand Down
189 changes: 189 additions & 0 deletions src/.ci/_package-lib_unix-any.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
# 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" "\
<?xml version='1.0' encoding='utf-8'?>
<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>
<metadata>
<id>${PROJECT_SKU}</id>
<version>${PROJECT_VERSION}</version>
<authors>${PROJECT_CONTACT_NAME}</authors>
<owners>${PROJECT_CONTACT_NAME}</owners>
<projectUrl>${PROJECT_SOURCE_URL}</projectUrl>
<title>${PROJECT_NAME}</title>
<description>${PROJECT_PITCH}</description>
<license>${PROJECT_LICENSE}</license>
<requireLicenseAcceptance>${__acceptance}</requireLicenseAcceptance>
<readme>${PROJECT_README}</readme>
</metadata>
</package>
"
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# 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\i18n\translations.ps1"



Expand All @@ -24,7 +22,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,
Expand All @@ -34,22 +32,6 @@ function PACKAGE-Assemble-NPM-Content {
)


# validate project
if ($(FS-Is-Target-A-NPM "${_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
}


# report status
return 0
}
Loading

0 comments on commit 5988ca2

Please sign in to comment.