From 67eaba5a5607885ae1f0dc1e99c29f32eeaf7099 Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Sat, 16 Dec 2023 18:19:47 +0800 Subject: [PATCH] automataCI: added i18n feature to release citation function Since we want i18n feature to be applied across all package CI job, we should first deal with release citation function. Hence, let's do this. This patch applies i18n feature to release citation function in automataCI/ directory. Co-authored-by: Galyna, Cory <124406765+corygalyna@users.noreply.github.com> Co-authored-by: (Holloway) Chew, Kean Ho Signed-off-by: (Holloway) Chew, Kean Ho --- automataCI/_package-citation_unix-any.sh | 52 +++++ automataCI/_package-citation_windows-any.ps1 | 52 +++++ automataCI/_release-citation_unix-any.sh | 50 ++--- automataCI/_release-citation_windows-any.ps1 | 54 ++--- automataCI/package_unix-any.sh | 8 + automataCI/package_windows-any.ps1 | 11 +- automataCI/release_unix-any.sh | 11 +- automataCI/release_windows-any.ps1 | 11 +- automataCI/services/compilers/citation.ps1 | 210 +++++++++--------- automataCI/services/compilers/citation.sh | 202 ++++++++--------- .../services/i18n/_status-file-export.ps1 | 50 +++++ .../services/i18n/_status-file-export.sh | 50 +++++ automataCI/services/i18n/status-file.ps1 | 1 + automataCI/services/i18n/status-file.sh | 1 + automataCI/services/io/fs.ps1 | 19 ++ automataCI/services/io/fs.sh | 19 ++ 16 files changed, 512 insertions(+), 289 deletions(-) create mode 100644 automataCI/_package-citation_unix-any.sh create mode 100644 automataCI/_package-citation_windows-any.ps1 create mode 100644 automataCI/services/i18n/_status-file-export.ps1 create mode 100644 automataCI/services/i18n/_status-file-export.sh diff --git a/automataCI/_package-citation_unix-any.sh b/automataCI/_package-citation_unix-any.sh new file mode 100644 index 00000000..7600e4b0 --- /dev/null +++ b/automataCI/_package-citation_unix-any.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# 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 +# 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/time.sh" +. "${LIBS_AUTOMATACI}/services/compilers/citation.sh" + +. "${LIBS_AUTOMATACI}/services/i18n/status-file.sh" + + + + +PACKAGE_Run_CITATION() { + __citation_cff="$1" + + + # assemble citation + I18N_Status_Print_File_Create "$__citation_cff" + CITATION_Build \ + "$__citation_cff" \ + "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/docs/ABSTRACTS.txt" \ + "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/docs/CITATIONS.yml" \ + "$PROJECT_CITATION" \ + "$PROJECT_CITATION_TYPE" \ + "$(TIME_Format_ISO8601_Date "$(TIME_Now)")" \ + "$PROJECT_NAME" \ + "$PROJECT_VERSION" \ + "$PROJECT_LICENSE" \ + "$PROJECT_SOURCE_URL" \ + "$PROJECT_SOURCE_URL" \ + "$PROJECT_STATIC_URL" \ + "$PROJECT_CONTACT_NAME" \ + "$PROJECT_CONTACT_WEBSITE" \ + "$PROJECT_CONTACT_EMAIL" + if [ $? -ne 0 ]; then + I18N_Status_Print_File_Create_Failed + return 1 + fi + + + # report status + return 0 +} diff --git a/automataCI/_package-citation_windows-any.ps1 b/automataCI/_package-citation_windows-any.ps1 new file mode 100644 index 00000000..3662a9fa --- /dev/null +++ b/automataCI/_package-citation_windows-any.ps1 @@ -0,0 +1,52 @@ +# 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 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\time.ps1" +. "${env:LIBS_AUTOMATACI}\services\compilers\citation.ps1" + +. "${env:LIBS_AUTOMATACI}\services\i18n\status-file.ps1" + + + + +function PACKAGE-Run-CITATION { + param( + [string]$__citation_cff + ) + + # execute + $null = I18N-Status-Print-File-Create "${__citation_cff}" + $__process = CITATION-Build ` + "${__citation_cff}" ` + "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\docs\ABSTRACTS.txt" ` + "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\docs\CITATIONS.yml" ` + "${env:PROJECT_CITATION}" ` + "${env:PROJECT_CITATION_TYPE}" ` + "$(TIME-Format-ISO8601-Date "$(TIME-Now)")" ` + "${env:PROJECT_NAME}" ` + "${env:PROJECT_VERSION}" ` + "${env:PROJECT_LICENSE}" ` + "${env:PROJECT_SOURCE_URL}" ` + "${env:PROJECT_SOURCE_URL}" ` + "${env:PROJECT_STATIC_URL}" ` + "${env:PROJECT_CONTACT_NAME}" ` + "${env:PROJECT_CONTACT_WEBSITE}" ` + "${env:PROJECT_CONTACT_EMAIL}" + if ($__process -ne 0) { + $null = I18N-Status-Print-File-Create-Failed + return 1 + } + + + # report status + return 0 +} diff --git a/automataCI/_release-citation_unix-any.sh b/automataCI/_release-citation_unix-any.sh index aac0df81..08c1dd03 100644 --- a/automataCI/_release-citation_unix-any.sh +++ b/automataCI/_release-citation_unix-any.sh @@ -10,49 +10,31 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/io/os.sh" -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/io/fs.sh" -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/io/time.sh" -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/compilers/citation.sh" +. "${LIBS_AUTOMATACI}/services/io/fs.sh" +. "${LIBS_AUTOMATACI}/services/i18n/status-file.sh" -RELEASE::run_citation() { + +RELEASE_Run_CITATION_CFF() { + _target="$1" + + + # validate + if [ $(FS_Is_Target_A_Citation_CFF "$_target") -ne 0 ]; then + return 0 + fi + + # execute - OS::print_status info "generating citation file...\n" - CITATION::build \ - "${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}/CITATION.cff" \ - "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/docs/ABSTRACTS.txt" \ - "${PROJECT_PATH_ROOT}/${PROJECT_PATH_SOURCE}/docs/CITATIONS.yml" \ - "$PROJECT_CITATION" \ - "$PROJECT_CITATION_TYPE" \ - "$(TIME_Format_ISO8601_Date "$(TIME_Now)")" \ - "$PROJECT_NAME" \ - "$PROJECT_VERSION" \ - "$PROJECT_LICENSE" \ - "$PROJECT_SOURCE_URL" \ - "$PROJECT_SOURCE_URL" \ - "$PROJECT_STATIC_URL" \ - "$PROJECT_CONTACT_NAME" \ - "$PROJECT_CONTACT_WEBSITE" \ - "$PROJECT_CONTACT_EMAIL" + I18N_Status_Print_File_Export "CITATION.cff" + FS::copy_file "$_target" "${PROJECT_PATH_ROOT}/CITATION.cff" if [ $? -ne 0 ]; then - OS::print_status error "generate failed.\n" + I18N_Status_Print_File_Export_Failed return 1 fi - if [ -f "${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}/CITATION.cff" ]; then - OS::print_status info "exporting CITATION.cff...\n" - FS::copy_file \ - "${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}/CITATION.cff" \ - "${PROJECT_PATH_ROOT}/CITATION.cff" - if [ $? -ne 0 ]; then - OS::print_status error "export failed.\n" - return 1 - fi - fi - # report status return 0 diff --git a/automataCI/_release-citation_windows-any.ps1 b/automataCI/_release-citation_windows-any.ps1 index f2842fbb..d5bc173c 100644 --- a/automataCI/_release-citation_windows-any.ps1 +++ b/automataCI/_release-citation_windows-any.ps1 @@ -9,48 +9,32 @@ # 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:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\io\os.ps1" -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\io\fs.ps1" -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\io\time.ps1" -. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\compilers\citation.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1" +. "${env:LIBS_AUTOMATACI}\services\i18n\status-file.ps1" -function RELEASE-Run-Citation { - # execute - OS-Print-Status info "generating citation file..." - $__process = CITATION-Build ` - "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_PKG}\CITATION.cff" ` - "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\docs\ABSTRACTS.txt" ` - "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_SOURCE}\docs\CITATIONS.yml" ` - "${env:PROJECT_CITATION}" ` - "${env:PROJECT_CITATION_TYPE}" ` - "$(TIME-Format-ISO8601-Date "$(TIME-Now)")" ` - "${env:PROJECT_NAME}" ` - "${env:PROJECT_VERSION}" ` - "${env:PROJECT_LICENSE}" ` - "${env:PROJECT_SOURCE_URL}" ` - "${env:PROJECT_SOURCE_URL}" ` - "${env:PROJECT_STATIC_URL}" ` - "${env:PROJECT_CONTACT_NAME}" ` - "${env:PROJECT_CONTACT_WEBSITE}" ` - "${env:PROJECT_CONTACT_EMAIL}" - if ($__process -ne 0) { - OS-Print-Status error "generate failed." - return 1 + +function RELEASE-Run-CITATION-CFF { + param( + [string]$_target + ) + + + # validate input + $___process = FS-Is-Target-A-Citation-CFF "${_target}" + if ($___process -ne 0) { + return 0 } - if (Test-Path "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_PKG}\CITATION.cff") { - OS-Print-Status info "exporting CITATION.cff..." - $__process = FS-Copy-File ` - "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_PKG}\CITATION.cff" ` - "${env:PROJECT_PATH_ROOT}\CITATION.cff" - if ($__process -ne 0) { - OS-Print-Status error "export failed." - return 1 - } + # execute + $null = I18N-Status-Print-File-Export "CITATION.cff" + $___process = FS-Copy-File "${_target}" "${env:PROJECT_PATH_ROOT}\CITATION.cff" + if ($___process -ne 0) { + $null = I18N-Status-Print-File-Export-Failed + return 1 } diff --git a/automataCI/package_unix-any.sh b/automataCI/package_unix-any.sh index cb2acdbb..bd8108ea 100644 --- a/automataCI/package_unix-any.sh +++ b/automataCI/package_unix-any.sh @@ -33,6 +33,7 @@ fi . "${LIBS_AUTOMATACI}/_package-cargo_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-changelog_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-chocolatey_unix-any.sh" +. "${LIBS_AUTOMATACI}/_package-citation_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-deb_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-docker_unix-any.sh" . "${LIBS_AUTOMATACI}/_package-flatpak_unix-any.sh" @@ -69,6 +70,13 @@ if [ $? -ne 0 ]; then return 1 fi +FILE_CITATION_CFF="${PROJECT_SKU}-CITATION_${PROJECT_VERSION}.cff" +FILE_CITATION_CFF="${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}/${FILE_CITATION_CFF}" +PACKAGE_Run_CITATION "$FILE_CITATION_CFF" +if [ $? -ne 0 ]; then + return 1 +fi + I18N_Status_Print_Newline diff --git a/automataCI/package_windows-any.ps1 b/automataCI/package_windows-any.ps1 index 27399c68..bf211de8 100644 --- a/automataCI/package_windows-any.ps1 +++ b/automataCI/package_windows-any.ps1 @@ -29,6 +29,7 @@ if (-not (Test-Path -Path $env:PROJECT_PATH_ROOT)) { . "${env:LIBS_AUTOMATACI}\services\i18n\status-sync.ps1" . "${env:LIBS_AUTOMATACI}\_package-changelog_windows-any.ps1" +. "${env:LIBS_AUTOMATACI}\_package-citation_windows-any.ps1" @@ -48,7 +49,15 @@ $FILE_CHANGELOG_MD = "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_PKG}\${FILE_CH $FILE_CHANGELOG_DEB = "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_TEMP}\deb\changelog.gz" $__process = Package-Run-CHANGELOG "$FILE_CHANGELOG_MD" "$FILE_CHANGELOG_DEB" if ($__process -ne 0) { - exit 1 + return 1 +} + + +$FILE_CITATION_CFF = "${env:PROJECT_SKU}-CITATION_${env:PROJECT_VERSION}.cff" +$FILE_CITATION_CFF = "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_PKG}\${FILE_CITATION_CFF}" +$__process = Package-Run-CITATION "$FILE_CITATION_CFF" +if ($__process -ne 0) { + return 1 } diff --git a/automataCI/release_unix-any.sh b/automataCI/release_unix-any.sh index f25b477a..bd75a907 100644 --- a/automataCI/release_unix-any.sh +++ b/automataCI/release_unix-any.sh @@ -120,6 +120,11 @@ for TARGET in "${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}"/*; do return 1 fi + RELEASE_Run_CITATION_CFF "$TARGET" + if [ $? -ne 0 ]; then + return 1 + fi + RELEASE::run_homebrew "$TARGET" "$HOMEBREW_REPO" if [ $? -ne 0 ]; then return 1 @@ -140,12 +145,6 @@ for TARGET in "${PROJECT_PATH_ROOT}/${PROJECT_PATH_PKG}"/*; do done -RELEASE::run_citation -if [ $? -ne 0 ]; then - return 1 -fi - - RELEASE::run_checksum_seal "$STATIC_REPO" if [ $? -ne 0 ]; then return 1 diff --git a/automataCI/release_windows-any.ps1 b/automataCI/release_windows-any.ps1 index 6b68b590..2cfbdb53 100644 --- a/automataCI/release_windows-any.ps1 +++ b/automataCI/release_windows-any.ps1 @@ -123,6 +123,11 @@ if (Test-Path -PathType Container -Path "${PACKAGE_DIRECTORY}") { return 1 } + $__process = RELEASE-Run-CITATION-CFF "$TARGET" + if ($__process -ne 0) { + return 1 + } + $__process = RELEASE-Run-Homebrew "$TARGET" "$HOMEBREW_REPO" if ($__process -ne 0) { return 1 @@ -144,12 +149,6 @@ if (Test-Path -PathType Container -Path "${PACKAGE_DIRECTORY}") { } -$__process = RELEASE-Run-Citation -if ($__process -ne 0) { - return 1 -} - - $__process = RELEASE-Run-Checksum-Seal "$STATIC_REPO" if ($__process -ne 0) { return 1 diff --git a/automataCI/services/compilers/citation.ps1 b/automataCI/services/compilers/citation.ps1 index 37208942..bb3132e2 100644 --- a/automataCI/services/compilers/citation.ps1 +++ b/automataCI/services/compilers/citation.ps1 @@ -9,213 +9,209 @@ # 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:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\io\fs.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1" +. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1" function CITATION-Build { param( - [string]$__filepath, - [string]$__abstract_filepath, - [string]$__citation_filepath, - [string]$__cff_version, - [string]$__type, - [string]$__date, - [string]$__title, - [string]$__version, - [string]$__license, - [string]$__repo, - [string]$__repo_code, - [string]$__repo_artifact, - [string]$__contact_name, - [string]$__contact_website, - [string]$__contact_email + [string]$___filepath, + [string]$___abstract_filepath, + [string]$___citation_filepath, + [string]$___cff_version, + [string]$___type, + [string]$___date, + [string]$___title, + [string]$___version, + [string]$___license, + [string]$___repo, + [string]$___repo_code, + [string]$___repo_artifact, + [string]$___contact_name, + [string]$___contact_website, + [string]$___contact_email ) # validate input - if ([string]::IsNullOrEmpty($__cff_version)) { + if ($(STRINGS-Is-Empty "${___cff_version}") -eq 0) { return 0 # requested to be disabled } - if ([string]::IsNullOrEmpty($__filepath) -or - [string]::IsNullOrEmpty($__title) -or - [string]::IsNullOrEmpty($__type)) { + if (($(STRINGS-Is-Empty "${___filepath}") -eq 0) -or + ($(STRINGS-Is-Empty "${___title}") -eq 0) -or + ($(STRINGS-Is-Empty "${___type}") -eq 0)) { return 1 } - if ([string]::IsNullOrEmpty($__citation_filepath) -or - (-not (Test-Path -Path "${__citation_filepath}"))) { + if ($(STRINGS-Is-Empty "${___citation_filepath}") -eq 0) { + return 1 + } + + $___process = FS-Is-File "${___citation_filepath}" + if ($___process -ne 0) { return 1 } # execute - $null = FS-Remove-Silently "${__filepath}" - $null = FS-Make-Housing-Directory "${__filepath}" - $__process = FS-Write-File "${__filepath}" @" + $null = FS-Remove-Silently "${___filepath}" + $null = FS-Make-Housing-Directory "${___filepath}" + $___process = FS-Write-File "${___filepath}" @" # WARNING: auto-generated by AutomataCI -cff-version: `"${__cff_version}`" -type: `"${__type}`" +cff-version: `"${___cff_version}`" +type: `"${___type}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } - ## date - if (-not [string]::IsNullOrEmpty($__date)) { - $__process = FS-Append-File "${__filepath}" @" -date-released: `"${__date}`" + if ($(STRINGS-Is-Empty "${___date}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +date-released: `"${___date}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## title - if (-not [string]::IsNullOrEmpty($__title)) { - $__process = FS-Append-File "${__filepath}" @" -title: `"${__title}`" + if ($(STRINGS-Is-Empty "${___title}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +title: `"${___title}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## version - if (-not [string]::IsNullOrEmpty($__version)) { - $__process = FS-Append-File "${__filepath}" @" -version: `"${__version}`" + if ($(STRINGS-Is-Empty "${___version}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +version: `"${___version}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## license - if (-not [string]::IsNullOrEmpty($__license)) { - $__process = FS-Append-File "${__filepath}" @" -license: `"${__license}`" + if ($(STRINGS-Is-Empty "${___license}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +license: `"${___license}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## repository - if (-not [string]::IsNullOrEmpty($__repo)) { - $__process = FS-Append-File "${__filepath}" @" -repository: `"${__repo}`" + if ($(STRINGS-Is-Empty "${___repo}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +repository: `"${___repo}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## repository-code - if (-not [string]::IsNullOrEmpty($__repo_code)) { - $__process = FS-Append-File "${__filepath}" @" -repository-code: `"${__repo_code}`" + if ($(STRINGS-Is-Empty "${___repo_code}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +repository-code: `"${___repo_code}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## repository-artifact - if (-not [string]::IsNullOrEmpty($__version)) { - $__process = FS-Append-File "${__filepath}" @" -repository-artifact: `"${__repo_artifact}`" + if ($(STRINGS-Is-Empty "${___repo_artifact}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +repository-artifact: `"${___repo_artifact}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## url - if (-not [string]::IsNullOrEmpty($__contact_website)) { - $__process = FS-Append-File "${__filepath}" @" -url: `"${__contact_website}`" + if ($(STRINGS-Is-Empty "${___contact_website}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" +url: `"${___contact_website}`" "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } } - ## contact - if ((-not [string]::IsNullOrEmpty($__contact_name)) -and - ((-not [string]::IsNullOrEmpty($__contact_website)) -or - (-not [string]::IsNullOrEmpty($__contact_email)))) { - $__process = FS-Append-File "${__filepath}" @" + if ($(STRINGS-Is-Empty "${___contact_name}") -ne 0) { + if (($(STRINGS-Is-Empty "${___contact_website}") -ne 0) -or + ($(STRINGS-Is-Empty "${___contact_email}") -ne 0)) { + $___process = FS-Append-File "${___filepath}" @" contact: - - affiliation: `"${__contact_name}`" + - affiliation: `"${___contact_name}`" "@ - if ($__process -ne 0) { - return 1 - } + if ($___process -ne 0) { + return 1 + } - if (-not [string]::IsNullOrEmpty($__contact_email)) { - $__process = FS-Append-File "${__filepath}" @" - email: `"${__contact_email}`" + if ($(STRINGS-Is-Empty "${___contact_email}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" + email: `"${___contact_email}`" "@ - if ($__process -ne 0) { - return 1 + if ($___process -ne 0) { + return 1 + } } - } - if (-not [string]::IsNullOrEmpty($__contact_website)) { - $__process = FS-Append-File "${__filepath}" @" + if ($(STRINGS-Is-Empty "${___contact_website}") -ne 0) { + $___process = FS-Append-File "${___filepath}" @" website: `"${__contact_website}`" "@ - if ($__process -ne 0) { - return 1 + if ($___process -ne 0) { + return 1 + } } } } - ## abstract - if (Test-Path -Path "${__abstract_filepath}") { - $__process = FS-Append-File "${__filepath}" @" + $___process = FS-Is-File "${___abstract_filepath}" + if ($___process -eq 0) { + $___process = FS-Append-File "${___filepath}" @" abstract: |- "@ - if ($__process -ne 0) { + if ($___process -ne 0) { return 1 } - foreach ($__line in (Get-Content "${__abstract_filepath}")) { - if ((-not [string]::IsNullOrEmpty($__line)) -and - [string]::IsNullOrEmpty($__line -replace "#.*$")) { + foreach ($___line in (Get-Content "${___abstract_filepath}")) { + if (($(STRINGS-Is-Empty "${___line}") -ne 0) -and + ($(STRINGS-Is-Empty "$($___line -replace "#.*$")") -eq 0)) { continue } - $__line = $__line -replace '#.*' - if (-not [string]::IsNullOrEmpty($__line)) { - $__line = " ${__line}" + $___line = $___line -replace '#.*' + if ($(STRINGS-Is-Empty "${___line}") -ne 0) { + $___line = " ${___line}" } - $__process = FS-Append-File "${__filepath}" "${__line}" - if ($__process -ne 0) { + $___process = FS-Append-File "${___filepath}" "${___line}" + if ($___process -ne 0) { return 1 } } } - ## other citations - foreach ($__line in (Get-Content "${__citation_filepath}")) { - if ((-not [string]::IsNullOrEmpty($__line)) -and - [string]::IsNullOrEmpty($__line -replace "#.*$")) { + foreach ($___line in (Get-Content "${___citation_filepath}")) { + if (($(STRINGS-Is-Empty "${___line}") -ne 0) -and + ($(STRINGS-Is-Empty "$($___line -replace "#.*$")") -eq 0)) { continue } - $__line = $__line -replace '#.*' - if ([string]::IsNullOrEmpty($__line)) { + $___line = $___line -replace '#.*' + if ($(STRINGS-Is-Empty "${___line}") -ne 0) { continue } - $__process = FS-Append-File "${__filepath}" "${__line}" - if ($__process -ne 0) { + $___process = FS-Append-File "${___filepath}" "${___line}" + if ($___process -ne 0) { return 1 } } diff --git a/automataCI/services/compilers/citation.sh b/automataCI/services/compilers/citation.sh index efe96f84..c3134c4a 100644 --- a/automataCI/services/compilers/citation.sh +++ b/automataCI/services/compilers/citation.sh @@ -10,212 +10,214 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. -. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/io/fs.sh" +. "${LIBS_AUTOMATACI}/services/io/fs.sh" +. "${LIBS_AUTOMATACI}/services/io/strings.sh" -CITATION::build() { - __filepath="$1" - __abstract_filepath="$2" - __citation_filepath="$3" - __cff_version="$4" - __type="$5" - __date="$6" - __title="$7" - __version="$8" - __license="$9" - __repo="${10}" - __repo_code="${11}" - __repo_artifact="${12}" - __contact_name="${13}" - __contact_website="${14}" - __contact_email="${15}" +CITATION_Build() { + ___filepath="$1" + ___abstract_filepath="$2" + ___citation_filepath="$3" + ___cff_version="$4" + ___type="$5" + ___date="$6" + ___title="$7" + ___version="$8" + ___license="$9" + ___repo="${10}" + ___repo_code="${11}" + ___repo_artifact="${12}" + ___contact_name="${13}" + ___contact_website="${14}" + ___contact_email="${15}" # validate input - if [ -z "$__cff_version" ]; then + if [ $(STRINGS_Is_Empty "$___cff_version") -eq 0 ]; then return 0 # requested to be disabled fi - if [ -z "$__filepath" ] || [ -z "$__title" ] || [ -z "$__type" ]; then + if [ $(STRINGS_Is_Empty "$___filepath") -eq 0 ] || + [ $(STRINGS_Is_Empty "$___title") -eq 0 ] || + [ $(STRINGS_Is_Empty "$___type") -eq 0 ]; then return 1 fi - if [ -z "$__citation_filepath" ] || [ ! -f "$__citation_filepath" ]; then + if [ $(STRINGS_Is_Empty "$___citation_filepath") -eq 0 ]; then + return 1 + fi + + FS::is_file "$___citation_filepath" + if [ $? -ne 0 ]; then return 1 fi # execute - FS::remove_silently "$__filepath" - FS::make_housing_directory "$__filepath" - FS::write_file "$__filepath" "\ + FS::remove_silently "$___filepath" + FS::make_housing_directory "$___filepath" + FS::write_file "$___filepath" "\ # WARNING: auto-generated by AutomataCI -cff-version: \"${__cff_version}\" -type: \"${__type}\" +cff-version: \"${___cff_version}\" +type: \"${___type}\" " if [ $? -ne 0 ]; then return 1 fi - ## date - if [ ! -z "$__date" ]; then - FS::append_file "$__filepath" "\ -date-released: \"${__date}\" + if [ $(STRINGS_Is_Empty "$___date") -ne 0 ]; then + FS::append_file "$___filepath" "\ +date-released: \"${___date}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## title - if [ ! -z "$__title" ]; then - FS::append_file "$__filepath" "\ -title: \"${__title}\" + if [ $(STRINGS_Is_Empty "$___title") -ne 0 ]; then + FS::append_file "$___filepath" "\ +title: \"${___title}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## version - if [ ! -z "$__version" ]; then - FS::append_file "$__filepath" "\ -version: \"${__version}\" + if [ $(STRINGS_Is_Empty "$___version") -ne 0 ]; then + FS::append_file "$___filepath" "\ +version: \"${___version}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## license - if [ ! -z "$__license" ]; then - FS::append_file "$__filepath" "\ -license: \"${__license}\" + if [ $(STRINGS_Is_Empty "$___license") -ne 0 ]; then + FS::append_file "$___filepath" "\ +license: \"${___license}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## repository - if [ ! -z "$__repo" ]; then - FS::append_file "$__filepath" "\ -repository: \"${__repo}\" + if [ $(STRINGS_Is_Empty "$___repo") -ne 0 ]; then + FS::append_file "$___filepath" "\ +repository: \"${___repo}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## repository-code - if [ ! -z "$__repo_code" ]; then - FS::append_file "$__filepath" "\ -repository-code: \"${__repo_code}\" + if [ $(STRINGS_Is_Empty "$___repo_code") -ne 0 ]; then + FS::append_file "$___filepath" "\ +repository-code: \"${___repo_code}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## repository-artifact - if [ ! -z "$__repo_artifact" ]; then - FS::append_file "$__filepath" "\ -repository-artifact: \"${__repo_artifact}\" + if [ $(STRINGS_Is_Empty "$___repo_artifact") -ne 0 ]; then + FS::append_file "$___filepath" "\ +repository-artifact: \"${___repo_artifact}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## url - if [ ! -z "$__contact_website" ]; then - FS::append_file "$__filepath" "\ -url: \"${__contact_website}\" + if [ $(STRINGS_Is_Empty "$___contact_website") -ne 0 ]; then + FS::append_file "$___filepath" "\ +url: \"${___contact_website}\" " if [ $? -ne 0 ]; then return 1 fi fi - ## contact - if [ ! -z "$__contact_name" ] && - [ ! -z "$__contact_website" -o ! -z "$__contact_email" ]; then - FS::append_file "$__filepath" "\ + if [ $(STRINGS_Is_Empty "$___contact_name") -ne 0 ]; then + if [ $(STRINGS_Is_Empty "$___contact_website") -ne 0 ] || + [ $(STRINGS_Is_Empty "$___contact_email") -ne 0 ]; then + FS::append_file "$___filepath" "\ contact: - - affiliation: \"${__contact_name}\" -" - if [ $? -ne 0 ]; then - return 1 - fi - - if [ ! -z "$__contact_email" ]; then - FS::append_file "$__filepath" "\ - email: \"${__contact_email}\" + - affiliation: \"${___contact_name}\" " if [ $? -ne 0 ]; then return 1 fi - fi - if [ ! -z "$__contact_website" ]; then - FS::append_file "$__filepath" "\ - website: \"${__contact_website}\" + if [ $(STRINGS_Is_Empty "$___contact_email") -ne 0 ]; then + FS::append_file "$___filepath" "\ + email: \"${___contact_email}\" " - if [ $? -ne 0 ]; then - return 1 + if [ $? -ne 0 ]; then + return 1 + fi + fi + + if [ $(STRINGS_Is_Empty "$___contact_website") -ne 0 ]; then + FS::append_file "$___filepath" "\ + website: \"${___contact_website}\" +" + if [ $? -ne 0 ]; then + return 1 + fi fi fi fi - ## abstract - if [ -f "$__abstract_filepath" ]; then - FS::append_file "$__filepath" "\ + FS::is_file "$___abstract_filepath" + if [ $? -eq 0 ]; then + FS::append_file "$___filepath" "\ abstract: |- " - if [ $? -ne 0 ]; then - return 1 - fi + if [ $? -ne 0 ]; then + return 1 + fi - __old_IFS="$IFS" - while IFS="" read -r __line || [ -n "$__line" ]; do - if [ ! -z "$__line" -a -z "${__line%%#*}" ]; then + ___old_IFS="$IFS" + while IFS="" read -r ___line || [ -n "$___line" ]; do + if [ $(STRINGS_Is_Empty "$___line") -ne 0 ] && + [ $(STRINGS_Is_Empty "${___line%%#*}") -eq 0 ]; then continue fi - __line="${__line%%#*}" - if [ ! -z "$__line" ]; then - __line=" ${__line}" + ___line="${___line%%#*}" + if [ $(STRINGS_Is_Empty "$___line") -ne 0 ]; then + ___line=" ${___line}" fi - FS::append_file "$__filepath" "${__line}\n" + FS::append_file "$___filepath" "${___line}\n" if [ $? -ne 0 ]; then return 1 fi - done < "$__abstract_filepath" - IFS="$__old_IFS" && unset __old_IFS + done < "$___abstract_filepath" + IFS="$___old_IFS" && unset ___old_IFS fi - ## other citations - __old_IFS="$IFS" - while IFS="" read -r __line || [ -n "$__line" ]; do - if [ ! -z "$__line" -a -z "${__line%%#*}" ]; then + ___old_IFS="$IFS" + while IFS="" read -r ___line || [ -n "$___line" ]; do + if [ $(STRINGS_Is_Empty "$___line") -ne 0 ] && + [ $(STRINGS_Is_Empty "${___line%%#*}") -eq 0 ]; then continue fi - __line="${__line%%#*}" - if [ -z "$__line" ]; then + ___line="${___line%%#*}" + if [ $(STRINGS_Is_Empty "$___line") -eq 0 ]; then continue fi - FS::append_file "$__filepath" "${__line}\n" + FS::append_file "$___filepath" "${___line}\n" if [ $? -ne 0 ]; then return 1 fi - done < "$__citation_filepath" - IFS="$__old_IFS" && unset __old_IFS + done < "$___citation_filepath" + IFS="$___old_IFS" && unset ___old_IFS # report status diff --git a/automataCI/services/i18n/_status-file-export.ps1 b/automataCI/services/i18n/_status-file-export.ps1 new file mode 100644 index 00000000..7b111cc3 --- /dev/null +++ b/automataCI/services/i18n/_status-file-export.ps1 @@ -0,0 +1,50 @@ +# 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 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\i18n\printer.ps1" + + + + +function I18N-Status-Print-File-Export { + param( + [string]$___subject + ) + + + # execute + switch (${env:AUTOMATACI_LANG}) { + default { + # fallback to default english + $___subject = I18N-Status-Param-Process "${___subject}" + $null = I18N-Status-Print info "exporting ${___subject}`n" + }} + + + # report status + return 0 +} + + + + +function I18N-Status-Print-File-Export-Failed { + # execute + switch (${env:AUTOMATACI_LANG}) { + default { + # fallback to default english + $null = I18N-Status-Print error "export failed.`n`n" + }} + + + # report status + return 0 +} diff --git a/automataCI/services/i18n/_status-file-export.sh b/automataCI/services/i18n/_status-file-export.sh new file mode 100644 index 00000000..4458883f --- /dev/null +++ b/automataCI/services/i18n/_status-file-export.sh @@ -0,0 +1,50 @@ +# 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 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/i18n/printer.sh" + + + + +I18N_Status_Print_File_Export() { + ___subject="$1" + + + # execute + case "$AUTOMATACI_LANG" in + *) + # fallback to default english + ___subject="$(I18N_Status_Param_Process "${___subject}")" + I18N_Status_Print info "exporting ${___subject}\n" + ;; + esac + + + # report status + return 0 +} + + + + +I18N_Status_Print_File_Export_Failed() { + # execute + case "$AUTOMATACI_LANG" in + *) + # fallback to default english + I18N_Status_Print error "export failed.\n\n" + ;; + esac + + + # report status + return 0 +} diff --git a/automataCI/services/i18n/status-file.ps1 b/automataCI/services/i18n/status-file.ps1 index eb8845f4..726eb313 100644 --- a/automataCI/services/i18n/status-file.ps1 +++ b/automataCI/services/i18n/status-file.ps1 @@ -14,6 +14,7 @@ . "${env:LIBS_AUTOMATACI}\services\i18n\_status-file-archive.ps1" . "${env:LIBS_AUTOMATACI}\services\i18n\_status-file-check.ps1" . "${env:LIBS_AUTOMATACI}\services\i18n\_status-file-create.ps1" +. "${env:LIBS_AUTOMATACI}\services\i18n\_status-file-export.ps1" . "${env:LIBS_AUTOMATACI}\services\i18n\_status-file-update.ps1" . "${env:LIBS_AUTOMATACI}\services\i18n\_status-file-validate.ps1" diff --git a/automataCI/services/i18n/status-file.sh b/automataCI/services/i18n/status-file.sh index ce1e8eb1..ff2a296e 100644 --- a/automataCI/services/i18n/status-file.sh +++ b/automataCI/services/i18n/status-file.sh @@ -14,6 +14,7 @@ . "${LIBS_AUTOMATACI}/services/i18n/_status-file-archive.sh" . "${LIBS_AUTOMATACI}/services/i18n/_status-file-check.sh" . "${LIBS_AUTOMATACI}/services/i18n/_status-file-create.sh" +. "${LIBS_AUTOMATACI}/services/i18n/_status-file-export.sh" . "${LIBS_AUTOMATACI}/services/i18n/_status-file-update.sh" . "${LIBS_AUTOMATACI}/services/i18n/_status-file-validate.sh" diff --git a/automataCI/services/io/fs.ps1 b/automataCI/services/io/fs.ps1 index 0fbc7fac..18dc2c5b 100644 --- a/automataCI/services/io/fs.ps1 +++ b/automataCI/services/io/fs.ps1 @@ -243,6 +243,25 @@ function FS-Is-Target-A-Chocolatey { +function FS-Is-Target-A-Citation-CFF { + param ( + [string]$___subject + ) + + + # execute + if ($("${___subject}" -replace '^.*.cff') -ne "${___subject}") { + return 0 + } + + + # report status + return 1 +} + + + + function FS-Is-Target-A-Docs { param ( [string]$__subject diff --git a/automataCI/services/io/fs.sh b/automataCI/services/io/fs.sh index c0935c4c..2049cbc7 100644 --- a/automataCI/services/io/fs.sh +++ b/automataCI/services/io/fs.sh @@ -243,6 +243,25 @@ FS::is_target_a_chocolatey() { +FS_Is_Target_A_Citation_CFF() { + #___target="$1" + + + # execute + if [ "${1#*.cff}" != "$1" ]; then + printf -- "0" + return 0 + fi + + + # report status + printf -- "1" + return 1 +} + + + + FS::is_target_a_docs() { # __target="$1"