From 160895f5e28d65834e35268af35782d0dbbf3c69 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Mon, 30 Dec 2024 22:25:17 +0200 Subject: [PATCH] Add reworked CI/CD 1/2 [build] --- .github/build/bootstrap.bash | 11 + .../{deb-mod.sh => build-deb-module.bash} | 77 +++--- .../build/{deb.sh => build-deb-package.bash} | 137 +++++----- .../{rpm-mod.sh => build-rpm-module.bash} | 114 ++++----- .github/build/build-rpm-package.bash | 237 ++++++++++++++++++ .github/build/environment.bash | 44 ++++ .github/build/{funcs.sh => functions.bash} | 163 ++++++++---- .github/build/init.sh | 29 --- .github/build/rpm.sh | 237 ------------------ .github/build/vars.sh | 43 ---- .../webmin.dev-deploy-webmin-package.yml | 6 +- 11 files changed, 570 insertions(+), 528 deletions(-) create mode 100755 .github/build/bootstrap.bash rename .github/build/{deb-mod.sh => build-deb-module.bash} (59%) mode change 100644 => 100755 rename .github/build/{deb.sh => build-deb-package.bash} (50%) rename .github/build/{rpm-mod.sh => build-rpm-module.bash} (52%) mode change 100644 => 100755 create mode 100755 .github/build/build-rpm-package.bash create mode 100755 .github/build/environment.bash rename .github/build/{funcs.sh => functions.bash} (57%) delete mode 100644 .github/build/init.sh delete mode 100755 .github/build/rpm.sh delete mode 100755 .github/build/vars.sh diff --git a/.github/build/bootstrap.bash b/.github/build/bootstrap.bash new file mode 100755 index 000000000..f06ef56ff --- /dev/null +++ b/.github/build/bootstrap.bash @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# shellcheck disable=SC1091 +# bootstrap.bash +# Copyright Ilia Ross +# Bootstrap the build process + +# Source general build functions +source "./functions.bash" || exit 1 + +# Source build variables +source ./environment.bash || exit 1 diff --git a/.github/build/deb-mod.sh b/.github/build/build-deb-module.bash old mode 100644 new mode 100755 similarity index 59% rename from .github/build/deb-mod.sh rename to .github/build/build-deb-module.bash index 308fdb51c..ac5665c87 --- a/.github/build/deb-mod.sh +++ b/.github/build/build-deb-module.bash @@ -1,36 +1,31 @@ #!/usr/bin/env bash +# shellcheck disable=SC2034 +# build-deb-module.bash +# Copyright Ilia Ross # -# Automatically builds and updates repo metadata for Webmin modules. -# Pulls latest changes from GitHub, detects release version based -# on what's available in the repo. -# -# (DEB) +# Automatically builds DEB Webmin module pulls changes from GitHub, creates +# testing builds from the latest code with English-only support, production +# builds from the latest tag, uploads them to the pre-configured repository, +# updates the repository metadata, and interacts with the environment using +# bootstrap # # Usage: -# # Build all modules with production versions -# ./deb-mod.sh # -# # Build all modules with development versions and debug -# ./deb-mod.sh --testing --debug +# Build testing module with in verbose mode +# ./build-deb-module.bash virtualmin-nginx --testing --verbose # -# # Build specific module with version and release -# ./deb-mod.sh virtualmin-nginx 2.36 2 +# Build specific module with version and release +# ./build-deb-module.bash virtualmin-nginx 2.36 2 # # shellcheck disable=SC1091 -# Source build variables -source ./vars.sh || exit 1 - -# Source build init -source ./init.sh || exit 1 - -# Source general build functions -source ./funcs.sh || exit 1 +# Bootstrap build environment +source ./bootstrap.bash || exit 1 # Build module func build_module() { # Always return back to root directory - cd "$root" || exit 1 + cd "$ROOT_DIR" || exit 1 # Define variables local last_commit_date @@ -38,9 +33,8 @@ build_module() { local verorig="" local module=$1 local rel - local relval local devel=0 - local root_module="$root/$module" + local root_module="$ROOT_DIR/$module" # Print build actual date date=$(get_current_date) @@ -53,7 +47,7 @@ build_module() { # Pull or clone module repository remove_dir "$root_module" - cmd=$(make_module_repo_cmd "$module") + cmd=$(make_module_repo_cmd "$module" "$MODULES_REPO_URL") eval "$cmd" rs=$? @@ -67,10 +61,8 @@ build_module() { fi if [[ "'$3'" != *"--"* ]] && [[ -n "$3" ]]; then rel=$3 - relval="-$3" else rel=1 - relval="" fi if [ -z "$ver" ]; then ver=$(get_module_version) @@ -92,12 +84,12 @@ build_module() { echo "Pre-clean up .." # Make sure directories exist make_dir "$root_module/tmp" - make_dir "$root_repos" + make_dir "$ROOT_REPOS" # Purge old files purge_dir "$root_module/tmp" if [ "$module" != "" ]; then - rm -f "$root_repos/$module-latest"* + rm -f "$ROOT_REPOS/$module-latest"* fi postcmd $? echo @@ -109,8 +101,10 @@ build_module() { echo "Building packages .." ( # XXXX Update actual module testing version dynamically - cd "$root" || exit 1 - cmd="$root/build-deps/makemoduledeb.pl --release $rel --deb-depends --licence 'GPLv3' --email 'ilia@virtualmin.dev' --allow-overwrite --target-dir $root_module/tmp $module $verbosity_level" + cd "$ROOT_DIR" || exit 1 + cmd="$ROOT_DIR/build-deps/makemoduledeb.pl --release $rel --deb-depends \ + --licence 'GPLv3' --email '$BUILDER_MODULE_EMAIL' --allow-overwrite \ + --target-dir $root_module/tmp $module $VERBOSITY_LEVEL" eval "$cmd" postcmd $? ) @@ -118,10 +112,12 @@ build_module() { echo echo "Preparing built files for upload .." # Move DEB to repos - cmd="find $root_module/tmp -name webmin-${module}*$verorig*\.deb -exec mv '{}' $root_repos \; $verbosity_level" + cmd="find $root_module/tmp -name webmin-${module}*$verorig*\.deb -exec mv '{}' \ + $ROOT_REPOS \; $VERBOSITY_LEVEL" eval "$cmd" if [ "$devel" -eq 1 ]; then - cmd="mv -f $root_repos/*${module}*$verorig*\.deb $root_repos/${module}_${ver}-${rel}_all.deb $verbosity_level" + cmd="mv -f $ROOT_REPOS/*${module}*$verorig*\.deb \ + $ROOT_REPOS/${module}_${ver}-${rel}_all.deb $VERBOSITY_LEVEL" eval "$cmd" fi postcmd $? @@ -129,7 +125,7 @@ build_module() { # Adjust module filename echo "Adjusting module filename .." - adjust_module_filename "$root_repos" "deb" + adjust_module_filename "$ROOT_REPOS" "deb" postcmd $? echo @@ -140,14 +136,13 @@ build_module() { # Main if [ -n "$1" ] && [[ "'$1'" != *"--"* ]]; then - build_module $@ - cloud_upload_list_upload=("$root_repos/*$1*") + MODULES_REPO_URL="$VIRTUALMIN_ORG_AUTH_URL" + build_module "$@" + cloud_upload_list_upload=("$ROOT_REPOS/*$1*") + cloud_upload cloud_upload_list_upload + cloud_repo_sign_and_update else - for module in "${webmin_modules[@]}"; do - build_module $module $@ - done - cloud_upload_list_upload=("$root_repos/*") + # Error otherwise + echo "Error: No module specified" + exit 1 fi - -cloud_upload cloud_upload_list_upload -cloud_repo_sign_and_update diff --git a/.github/build/deb.sh b/.github/build/build-deb-package.bash similarity index 50% rename from .github/build/deb.sh rename to .github/build/build-deb-package.bash index fd88d5f02..8a47db728 100755 --- a/.github/build/deb.sh +++ b/.github/build/build-deb-package.bash @@ -1,41 +1,34 @@ #!/usr/bin/env bash +# shellcheck disable=SC2034 +# build-deb-package.bash +# Copyright Ilia Ross # -# Copyright @iliajie -# -# Automatically builds and updates a repo metadata. -# Pulls latest changes from GitHub, detects release -# version based on what's available in the repo -# -# (Debian) +# Automatically builds DEB packages of Webmin and Usermin with the latest +# Authentic Theme, pulls changes from GitHub, creates testing builds from the +# latest code with English-only support, production builds from the latest tag, +# uploads them to the pre-configured repository, updates the repository +# metadata, and interacts with the environment using bootstrap # # Usage: # -# # Pull and build production versions -# # of both Webmin and Usermin -# ./deb.sh +# Pull and build production versions of both Webmin and Usermin +# ./build-deb-package.bash # -# # Pull and build devel versions -# # of both Webmin and Usermin -# ./deb.sh --testing +# Pull and build testing versions of both Webmin and Usermin +# ./build-deb-package.bash --testing # -# # Pull and build production Webmin version 2.101, forcing -# # release version 3, displaying detailed output -# ./deb.sh webmin 2.101 3 --debug +# Pull and build production Webmin version 2.101, forcing +# release version 3, displaying verbose output +# ./build-deb-package.bash webmin 2.101 3 --testing # -# # Pull and build production Usermin version 2.000, -# # automatically setting release version to minimal -# ./deb.sh usermin 2.000 +# Pull and build production Usermin version 2.000, +# automatically setting release version +# ./build-deb-package.bash usermin 2.000 # # shellcheck disable=SC1091 -# Source build variables -source ./vars.sh || exit 1 - -# Source build init -source ./init.sh || exit 1 - -# Source general build functions -source ./funcs.sh || exit 1 +# Bootstrap build environment +source ./bootstrap.bash || exit 1 # Build product func build_prod() { @@ -47,14 +40,14 @@ build_prod() { fi # Always return back to root directory - cd "$root" || exit 1 + cd "$ROOT_DIR" || exit 1 # Define root - local ver="" local prod=$1 + ROOT_PROD="$ROOT_DIR/$prod" + local root_apt="$ROOT_PROD/deb" + local ver="" local devel=0 - root_prod="$root/$prod" - root_apt="$root_prod/deb" # Print build actual date date=$(get_current_date) @@ -64,29 +57,33 @@ build_prod() { echo " build start date: $date " echo " package format: DEB " echo " product: $prod " - (make_prod_repos "$root_prod") & + (make_prod_repos "$ROOT_PROD" "$prod") & spinner " package output version:" # Pull main project first to get the latest tag - cd "$root_prod" || exit 1 - cmd="git pull $verbosity_level" + cd "$ROOT_PROD" || exit 1 + cmd="git pull $VERBOSITY_LEVEL" eval "$cmd" rs1=$? # Clean and try again if [ "$rs1" != "0" ]; then - cmd="git checkout \"*\" $verbosity_level && git clean -f -d $verbosity_level && git pull $verbosity_level" + cmd="git checkout \"*\" $VERBOSITY_LEVEL && \ + git clean -f -d $VERBOSITY_LEVEL && \ + git pull $VERBOSITY_LEVEL" eval "$cmd" rs1=$? fi # Descend to theme dir cd "authentic-theme" || exit 1 - cmd="git pull $verbosity_level" + cmd="git pull $VERBOSITY_LEVEL" eval "$cmd" rs2=$? # Clean and try again if [ "$rs2" != "0" ]; then - cmd="git checkout \"*\" $verbosity_level && git clean -f -d $verbosity_level && git pull $verbosity_level" + cmd="git checkout \"*\" $VERBOSITY_LEVEL && \ + git clean -f -d $VERBOSITY_LEVEL && \ + git pull $VERBOSITY_LEVEL" eval "$cmd" rs2=$? fi @@ -100,7 +97,7 @@ build_prod() { date_version=$(get_latest_commit_date_version) # Handle other params - cd "$root_prod" || exit 1 + cd "$ROOT_PROD" || exit 1 if [[ "'$2'" != *"--"* ]]; then ver=$2 fi @@ -120,7 +117,7 @@ build_prod() { # Set actual product version echo "${ver}" >"version" fi - printf "$ver-$rel\n" + printf "%s-%s\n" "$ver" "$rel" echo "************************************************************************" echo "Pulling latest changes.." @@ -131,35 +128,35 @@ build_prod() { echo "Pre-clean up .." # Make sure directories exist - make_dir "$root_repos/" + make_dir "$ROOT_REPOS/" make_dir "$root_apt/" - make_dir "$root_prod/newkey/deb/" - make_dir "$root_prod/umodules/" - make_dir "$root_prod/minimal/" - make_dir "$root_prod/tarballs/" + make_dir "$ROOT_PROD/newkey/deb/" + make_dir "$ROOT_PROD/umodules/" + make_dir "$ROOT_PROD/minimal/" + make_dir "$ROOT_PROD/tarballs/" # Re-create legacy link - remove_dir "$root/webadmin" - ln -s "$root/webmin" "$root/webadmin" + remove_dir "$ROOT_DIR/webadmin" + ln -s "$ROOT_DIR/webmin" "$ROOT_DIR/webadmin" # Purge old files - purge_dir "$root_prod/newkey/deb" - purge_dir "$root_prod/umodules" - purge_dir "$root_prod/minimal" - purge_dir "$root_prod/tarballs" + purge_dir "$ROOT_PROD/newkey/deb" + purge_dir "$ROOT_PROD/umodules" + purge_dir "$ROOT_PROD/minimal" + purge_dir "$ROOT_PROD/tarballs" if [ "$prod" != "" ]; then - rm -f "$root_repos/$prod-"* - rm -f "$root_repos/${prod}_"* + rm -f "$ROOT_REPOS/$prod-"* + rm -f "$ROOT_REPOS/${prod}_"* fi postcmd $? echo # Descend to project dir - cd "$root_prod" || exit 1 + cd "$ROOT_PROD" || exit 1 if [ "$english_only" = "1" ]; then echo "Cleaning languages .." - cmd="./bin/language-manager --mode=clean --yes $verbosity_level_with_input" + cmd="./bin/language-manager --mode=clean --yes $VERBOSITY_LEVEL_WITH_INPUT" eval "$cmd" postcmd $? echo @@ -167,7 +164,8 @@ build_prod() { # Force restore build directory if [ ! -f "lang/ja" ]; then echo "Restoring languages .." - cmd="git checkout \"*\" $verbosity_level && git clean -f -d $verbosity_level && git pull $verbosity_level" + cmd="git checkout \"*\" $VERBOSITY_LEVEL && git clean -f -d \ + $VERBOSITY_LEVEL && git pull $VERBOSITY_LEVEL" eval "$cmd" postcmd $? echo @@ -176,40 +174,43 @@ build_prod() { echo "Pre-building package .." eval "$cmd" - cmd="./makedist.pl \"${ver}${relval}\" $verbosity_level" + cmd="./makedist.pl \"${ver}${relval}\" $VERBOSITY_LEVEL" eval "$cmd" postcmd $? echo echo "Building package .." if [ "$relval" == "" ]; then - cmd="./makedebian.pl \"$ver\" $verbosity_level" + cmd="./makedebian.pl \"$ver\" $VERBOSITY_LEVEL" else - cmd="./makedebian.pl \"$ver\" \"$rel\" $verbosity_level" + cmd="./makedebian.pl \"$ver\" \"$rel\" $VERBOSITY_LEVEL" fi eval "$cmd" postcmd $? echo - cd "$root" || exit 1 + cd "$ROOT_DIR" || exit 1 echo "Preparing built files for upload .." - cmd="cp -f $root_prod/tarballs/${prod}-${ver}*\.tar.gz $root_repos/${prod}-$ver.tar.gz $verbosity_level" + cmd="cp -f $ROOT_PROD/tarballs/${prod}-${ver}*\.tar.gz \ + $ROOT_REPOS/${prod}-$ver.tar.gz $VERBOSITY_LEVEL" eval "$cmd" - cmd="find $root_apt -name ${prod}_${ver}${relval}*\.deb -exec mv '{}' $root_repos \; $verbosity_level" + cmd="find $root_apt -name ${prod}_${ver}${relval}*\.deb -exec mv '{}' \ + $ROOT_REPOS \; $VERBOSITY_LEVEL" eval "$cmd" - cmd="mv -f $root_repos/${prod}_${ver}${relval}*\.deb $root_repos/${prod}_${ver}-${rel}_all.deb $verbosity_level" + cmd="mv -f $ROOT_REPOS/${prod}_${ver}${relval}*\.deb \ + $ROOT_REPOS/${prod}_${ver}-${rel}_all.deb $VERBOSITY_LEVEL" eval "$cmd" postcmd $? } # Main -if [ -n "$1" ] && [[ "'$1'" != *"--"* ]]; then - build_prod $@ - cloud_upload_list_upload=("$root_repos/$1*") +if [ -n "$1" ] && [[ "$1" != --* ]]; then + build_prod "$@" + cloud_upload_list_upload=("$ROOT_REPOS/$1*") else - build_prod webmin $@ - build_prod usermin $@ - cloud_upload_list_upload=("$root_repos/*") + build_prod webmin "$@" + build_prod usermin "$@" + cloud_upload_list_upload=("$ROOT_REPOS/"*) fi cloud_upload cloud_upload_list_upload diff --git a/.github/build/rpm-mod.sh b/.github/build/build-rpm-module.bash old mode 100644 new mode 100755 similarity index 52% rename from .github/build/rpm-mod.sh rename to .github/build/build-rpm-module.bash index e97b74148..093d17469 --- a/.github/build/rpm-mod.sh +++ b/.github/build/build-rpm-module.bash @@ -1,36 +1,31 @@ #!/usr/bin/env bash +# shellcheck disable=SC2034 +# build-rpm-module.bash +# Copyright Ilia Ross # -# Automatically builds and updates repo metadata for Webmin modules. -# Pulls latest changes from GitHub, detects release version based -# on what's available in the repo. -# -# (RPM) +# Automatically builds DEB Webmin module pulls changes from GitHub, creates +# testing builds from the latest code with English-only support, production +# builds from the latest tag, uploads them to the pre-configured repository, +# updates the repository metadata, and interacts with the environment using +# bootstrap # # Usage: -# # Build all modules with production versions -# ./rpm-mod.sh # -# # Build all modules with development versions and debug -# ./rpm-mod.sh --testing --debug +# Build testing module with in verbose mode +# ./build-rpm-module.bash virtualmin-nginx --testing --verbose # -# # Build specific module with version and release -# ./rpm-mod.sh virtualmin-nginx 2.36 3 +# Build specific module with version and release +# ./build-rpm-module.bash virtualmin-nginx 2.36 2 # # shellcheck disable=SC1091 -# Source build variables -source ./vars.sh || exit 1 - -# Source build init -source ./init.sh || exit 1 - -# Source general build functions -source ./funcs.sh || exit 1 +# Bootstrap build environment +source ./bootstrap.bash || exit 1 # Build module func build_module() { # Always return back to root directory - cd "$root" || exit 1 + cd "$ROOT_DIR" || exit 1 # Define variables local last_commit_date @@ -40,7 +35,7 @@ build_module() { local rel local epoch local devel=0 - local root_module="$root/$module" + local root_module="$ROOT_DIR/$module" # Print build actual date date=$(get_current_date) @@ -53,7 +48,7 @@ build_module() { # Pull or clone module repository remove_dir "$root_module" - cmd=$(make_module_repo_cmd "$module") + cmd=$(make_module_repo_cmd "$module" "$MODULES_REPO_URL") eval "$cmd" rs=$? @@ -93,23 +88,23 @@ build_module() { echo "Pre-clean up .." # Make sure directories exist make_dir "$root_module/tmp" - make_dir "$root/newkey/rpm/" - make_dir "$root/umodules/" - make_dir "$root/minimal/" - make_dir "$root/tarballs/" - make_dir "$root_build/BUILD/" - make_dir "$root_build/BUILDROOT/" - make_dir "$root_build/RPMS/" - make_dir "$root_rpms" - make_dir "$root_build/SOURCES/" - make_dir "$root_build/SPECS/" - make_dir "$root_build/SRPMS/" - make_dir "$root_repos" + make_dir "$ROOT_DIR/newkey/rpm/" + make_dir "$ROOT_DIR/umodules/" + make_dir "$ROOT_DIR/minimal/" + make_dir "$ROOT_DIR/tarballs/" + make_dir "$ROOT_BUILD/BUILD/" + make_dir "$ROOT_BUILD/BUILDROOT/" + make_dir "$ROOT_BUILD/RPMS/" + make_dir "$ROOT_RPMS" + make_dir "$ROOT_BUILD/SOURCES/" + make_dir "$ROOT_BUILD/SPECS/" + make_dir "$ROOT_BUILD/SRPMS/" + make_dir "$ROOT_REPOS" # Purge old files purge_dir "$root_module/tmp" if [ "$module" != "" ]; then - rm -f "$root_repos/$module-latest"* + rm -f "$ROOT_REPOS/$module-latest"* fi postcmd $? echo @@ -121,8 +116,10 @@ build_module() { echo "Building packages.." ( # XXXX Update actual module testing version dynamically - cd "$root" || exit 1 - cmd="$root/build-deps/makemodulerpm.pl $epoch--release $rel --rpm-depends --licence 'GPLv3' --allow-overwrite --rpm-dir $root_build --target-dir $root_module/tmp $module $verbosity_level" + cd "$ROOT_DIR" || exit 1 + cmd="$ROOT_DIR/build-deps/makemodulerpm.pl $epoch--release \ + $rel --rpm-depends --licence 'GPLv3' --allow-overwrite --rpm-dir \ + $ROOT_BUILD --target-dir $root_module/tmp $module $VERBOSITY_LEVEL" eval "$cmd" postcmd $? ) @@ -130,10 +127,12 @@ build_module() { echo echo "Preparing built files for upload .." # Move RPM to repos - cmd="find $root_rpms -name wbm-$module*$verorig*\.rpm -exec mv '{}' $root_repos \; $verbosity_level" + cmd="find $ROOT_RPMS -name wbm-$module*$verorig*\.rpm -exec mv '{}' \ + $ROOT_REPOS \; $VERBOSITY_LEVEL" eval "$cmd" if [ "$devel" -eq 1 ]; then - cmd="mv -f $root_repos/wbm-$module*$verorig*\.rpm $root_repos/${module}-$ver-$rel.noarch.rpm $verbosity_level" + cmd="mv -f $ROOT_REPOS/wbm-$module*$verorig*\.rpm \ + $ROOT_REPOS/${module}-$ver-$rel.noarch.rpm $VERBOSITY_LEVEL" eval "$cmd" fi postcmd $? @@ -141,37 +140,32 @@ build_module() { # Adjust module filename echo "Adjusting module filename .." - adjust_module_filename "$root_repos" "rpm" + adjust_module_filename "$ROOT_REPOS" "rpm" postcmd $? echo echo "Post-clean up .." remove_dir "$root_module" # Purge old files - purge_dir "$root_prod/newkey/rpm" - purge_dir "$root_prod/umodules" - purge_dir "$root_prod/minimal" - purge_dir "$root_prod/tarballs" - purge_dir "$root_build/BUILD" - purge_dir "$root_build/BUILDROOT" - purge_dir "$root_build/RPMS" - purge_dir "$root_build/SOURCES" - purge_dir "$root_build/SPECS" - purge_dir "$root_build/SRPMS" - remove_dir "$root_repos/repodata" + purge_dir "$ROOT_BUILD/BUILD" + purge_dir "$ROOT_BUILD/BUILDROOT" + purge_dir "$ROOT_BUILD/RPMS" + purge_dir "$ROOT_BUILD/SOURCES" + purge_dir "$ROOT_BUILD/SPECS" + purge_dir "$ROOT_BUILD/SRPMS" + remove_dir "$ROOT_REPOS/repodata" postcmd $? } # Main if [ -n "$1" ] && [[ "'$1'" != *"--"* ]]; then - build_module $@ - cloud_upload_list_upload=("$root_repos/*$1*") + MODULES_REPO_URL="$VIRTUALMIN_ORG_AUTH_URL" + build_module "$@" + cloud_upload_list_upload=("$ROOT_REPOS/*$1*") + cloud_upload cloud_upload_list_upload + cloud_repo_sign_and_update else - for module in "${webmin_modules[@]}"; do - build_module $module $@ - done - cloud_upload_list_upload=("$root_repos/*") + # Error otherwise + echo "Error: No module specified" + exit 1 fi - -cloud_upload cloud_upload_list_upload -cloud_repo_sign_and_update diff --git a/.github/build/build-rpm-package.bash b/.github/build/build-rpm-package.bash new file mode 100755 index 000000000..37b6cab7a --- /dev/null +++ b/.github/build/build-rpm-package.bash @@ -0,0 +1,237 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034 +# build-rpm-package.bash +# Copyright Ilia Ross +# +# Automatically builds RPM packages of Webmin and Usermin with the latest +# Authentic Theme, pulls changes from GitHub, creates testing builds from the +# latest code with English-only support, production builds from the latest tag, +# uploads them to the pre-configured repository, updates the repository +# metadata, and interacts with the environment using bootstrap +# +# Usage: +# +# Pull and build production versions of both Webmin and Usermin +# ./build-rpm-package.bash +# +# Pull and build testing versions of both Webmin and Usermin +# ./build-rpm-package.bash --testing +# +# Pull and build production Webmin version 2.101, forcing +# release version 3, displaying verbose output +# ./build-rpm-package.bash webmin 2.101 3 --testing +# +# Pull and build production Usermin version 2.000, +# automatically setting release version +# ./build-rpm-package.bash usermin 2.000 +# + +# shellcheck disable=SC1091 +# Bootstrap build environment +source ./bootstrap.bash || exit 1 + +# Build product func +build_prod() { + + # Pack with English only in devel builds + local english_only=0 + if [[ "'$*'" == *"--testing"* ]]; then + english_only=1 + fi + + # Always return back to root directory + cd "$ROOT_DIR" || exit 1 + + # Define root + local ver="" + local prod=$1 + local devel=0 + ROOT_PROD="$ROOT_DIR/$prod" + + # Print build actual date + date=$(get_current_date) + + # Print opening header + echo "************************************************************************" + echo " build start date: $date " + echo " package format: RPM " + echo " product: $prod " + (make_prod_repos "$ROOT_PROD" "$prod") & + spinner " package output version:" + + # Pull main project first to get the latest tag + cd "$ROOT_PROD" || exit 1 + cmd="git pull $VERBOSITY_LEVEL" + eval "$cmd" + rs1=$? + # Clean and try again + if [ "$rs1" != "0" ]; then + cmd="git checkout \"*\" $VERBOSITY_LEVEL && git clean -f -d \ + $VERBOSITY_LEVEL && git pull $VERBOSITY_LEVEL" + eval "$cmd" + rs1=$? + fi + + # Pull theme to theme dir + cd "authentic-theme" || exit 1 + cmd="git pull $VERBOSITY_LEVEL" + eval "$cmd" + rs2=$? + # Clean and try again + if [ "$rs2" != "0" ]; then + cmd="git checkout \"*\" $VERBOSITY_LEVEL && git clean -f -d \ + $VERBOSITY_LEVEL && git pull $VERBOSITY_LEVEL" + eval "$cmd" + rs2=$? + fi + if [ "$rs1" != "0" ] || [ "$rs2" != "0" ]; then + rs=1 + else + rs=0 + fi + + # Build number + date_version=$(get_latest_commit_date_version) + + # Handle other params + cd "$ROOT_PROD" || exit 1 + if [[ "'$2'" != *"--"* ]]; then + ver=$2 + fi + if [[ "'$3'" != *"--"* ]] && [[ -n "$3" ]]; then + rel=$3 + else + rel=1 + fi + if [ -z "$ver" ]; then + ver=$(get_current_repo_tag) + fi + if [[ "'$*'" == *"--testing"* ]]; then + devel=1 + ver="$ver.$date_version" + # Set actual product version + echo "${ver}" >"version" + fi + + printf "%s-%s\n" "$ver" "$rel" + echo "************************************************************************" + + echo "Pulling latest changes.." + # We need to pull first to get the latest tag, + # so here we only report an error if any + postcmd $rs + echo + + echo "Pre-clean up .." + # Make sure directories exist + make_dir "$ROOT_PROD/newkey/rpm/" + make_dir "$ROOT_PROD/umodules/" + make_dir "$ROOT_PROD/minimal/" + make_dir "$ROOT_PROD/tarballs/" + make_dir "$ROOT_BUILD/BUILD/" + make_dir "$ROOT_BUILD/BUILDROOT/" + make_dir "$ROOT_BUILD/RPMS/" + make_dir "$ROOT_BUILD/SOURCES/" + make_dir "$ROOT_BUILD/SPECS/" + make_dir "$ROOT_BUILD/SRPMS/" + make_dir "$ROOT_REPOS/" + + # Re-create legacy link + remove_dir "$ROOT_DIR/webadmin" + ln -s "$ROOT_DIR/webmin" "$ROOT_DIR/webadmin" + + # Purge old files + purge_dir "$ROOT_PROD/newkey/rpm" + purge_dir "$ROOT_PROD/umodules" + purge_dir "$ROOT_PROD/minimal" + purge_dir "$ROOT_PROD/tarballs" + purge_dir "$ROOT_BUILD/BUILD" + purge_dir "$ROOT_BUILD/BUILDROOT" + purge_dir "$ROOT_BUILD/RPMS" + purge_dir "$ROOT_BUILD/SOURCES" + purge_dir "$ROOT_BUILD/SPECS" + purge_dir "$ROOT_BUILD/SRPMS" + remove_dir "$ROOT_REPOS/repodata" + if [ "$prod" != "" ]; then + rm -f "$ROOT_REPOS/$prod-"* + rm -f "$ROOT_REPOS/${prod}_"* + fi + postcmd $? + make_dir "$ROOT_BUILD/RPMS/noarch" + echo + + # Descend to project dir + cd "$ROOT_PROD" || exit 1 + + if [ "$english_only" = "1" ]; then + echo "Cleaning languages .." + cmd="./bin/language-manager --mode=clean --yes \ + $VERBOSITY_LEVEL_WITH_INPUT" + eval "$cmd" + postcmd $? + echo + else + # Force restore build directory + if [ ! -f "lang/ja" ]; then + echo "Restoring languages .." + cmd="git checkout \"*\" $VERBOSITY_LEVEL && git clean -f -d \ + $VERBOSITY_LEVEL && git pull $VERBOSITY_LEVEL" + eval "$cmd" + postcmd $? + echo + fi + fi + echo "Pre-building package .." + eval "$cmd" + if [ "$rel" = "1" ]; then + args="$ver" + else + args="$ver-$rel" + fi + + cmd="./makedist.pl \"$args\" $VERBOSITY_LEVEL" + eval "$cmd" + postcmd $? + echo + + echo "Building package .." + cmd="./makerpm.pl \"$ver\" \"$rel\" $VERBOSITY_LEVEL" + eval "$cmd" + postcmd $? + echo + + cd "$ROOT_DIR" || exit 1 + echo "Preparing built files for upload .." + cmd="cp -f $ROOT_PROD/tarballs/$prod-$ver*\.tar.gz \ + $ROOT_REPOS/${prod}-$ver.tar.gz $VERBOSITY_LEVEL" + eval "$cmd" + cmd="find $ROOT_RPMS -name $prod-$ver-$rel*\.rpm -exec mv '{}' \ + $ROOT_REPOS \; $VERBOSITY_LEVEL" + eval "$cmd" + # cmd="mv -f $ROOT_REPOS/$prod-$ver-$rel*\.rpm \ + # $ROOT_REPOS/${prod}-$ver-$rel.noarch.rpm $VERBOSITY_LEVEL" # file name is already always the same + # eval "$cmd" + postcmd $? + echo + + echo "Post-clean up .." + cd "$ROOT_BUILD" || exit 1 + for dir in *; do + cmd="rm -rf \"$dir/*\" $VERBOSITY_LEVEL" + eval "$cmd" + done + postcmd $? +} + +# Main +if [ -n "$1" ] && [[ "$1" != --* ]]; then + build_prod "$@" + cloud_upload_list_upload=("$ROOT_REPOS/$1*") +else + build_prod webmin "$@" + build_prod usermin "$@" + cloud_upload_list_upload=("$ROOT_REPOS/"*) +fi + +cloud_upload cloud_upload_list_upload +cloud_repo_sign_and_update diff --git a/.github/build/environment.bash b/.github/build/environment.bash new file mode 100755 index 000000000..7020d3bae --- /dev/null +++ b/.github/build/environment.bash @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034 +# environment.bash +# Copyright Ilia Ross +# Configures environment variables for the build process + +# Builder email +BUILDER_PACKAGE_EMAIL="${ENV_BUILD__BUILDER_EMAIL:-ilia@webmin.dev}" +BUILDER_MODULE_EMAIL="${ENV_BUILD__BUILDER_EMAIL:-ilia@virtualmin.dev}" + +# Set defaults +ROOT_DIR="${ENV_BUILD__ROOT:-$HOME}" +ROOT_REPOS="${ENV_BUILD__ROOT_REPOS:-$ROOT_DIR/repo}" +ROOT_BUILD="${ENV_BUILD__ROOT_BUILD:-$ROOT_DIR/rpmbuild}" +ROOT_RPMS="${ENV_BUILD__ROOT_RPMS:-$ROOT_BUILD/RPMS/noarch}" + +# Create symlinks for Perl +PERL_SOURCE="/usr/bin/perl" +PERL_TARGET="/usr/local/bin/perl" +ln -fs "$PERL_SOURCE" "$PERL_TARGET" + +# GitHub private repos access token +GITHUB_TOKEN="${ENV_BUILD__GITHUB_TOKEN}" + +# Cloud upload config +CLOUD_UPLOAD_SSH_USER="${ENV_BUILD__CLOUD_UPLOAD_SSH_USER:-webmin.dev}" +CLOUD_UPLOAD_SSH_HOST="${ENV_BUILD__CLOUD_UPLOAD_SSH_HOST:-webmin.dev}" +CLOUD_UPLOAD_SSH_DIR="${ENV_BUILD__CLOUD_UPLOAD_SSH_DIR:-~/domains/download.webmin.dev/public_html}" +CLOUD_UPLOAD_GPG_PASSPHRASE="${WEBMIN_DEV__GPG_PH}" + +# Define verbosity level +VERBOSITY_LEVEL=' >/dev/null 2>&1 -# -# General build functions -# -# +# functions.bash +# Copyright Ilia Ross +# Build functions for the build process + +# Set up SSH keys on the build machine +setup_ssh() { + + # If SSH keys are already set up, skip this step + if [ -f "$HOME/.ssh/id_rsa" ] && [ -f "$HOME/.ssh/id_rsa.pub" ]; then + return 0 + fi + + # Create and set permissions on SSH directory + mkdir -p "$HOME/.ssh" + chmod 700 "$HOME/.ssh" + + if [[ -n "${WEBMIN_DEV__SSH_PRV_KEY:-}" ]] && + [[ -n "${WEBMIN_DEV__SSH_PUB_KEY:-}" ]]; then + echo "Setting up development SSH keys .." + + # Generate new pair with right permissions + cmd="ssh-keygen -t rsa -q -f \"$HOME/.ssh/id_rsa\" -N \"\"$VERBOSITY_LEVEL" + eval "$cmd" + postcmd $? + echo + + # Import SSH keys from secrets to be able to connect to the remote host + echo "$WEBMIN_DEV__SSH_PRV_KEY" > "$HOME/.ssh/id_rsa" + echo "$WEBMIN_DEV__SSH_PUB_KEY" > "$HOME/.ssh/id_rsa.pub" + + elif [[ -n "${WEBMIN_PROD__SSH_PRV_KEY:-}" ]] && + [[ -n "${WEBMIN_PROD__SSH_PUB_KEY:-}" ]]; then + echo "Setting up production SSH keys .." + + # Generate new pair with right permissions + cmd="ssh-keygen -t rsa -q -f \"$HOME/.ssh/id_rsa\" -N \"\"$VERBOSITY_LEVEL" + eval "$cmd" + postcmd $? + + # Import SSH keys from secrets to be able to connect to the remote host + echo "$WEBMIN_PROD__SSH_PRV_KEY" > "$HOME/.ssh/id_rsa" + echo "$WEBMIN_PROD__SSH_PUB_KEY" > "$HOME/.ssh/id_rsa.pub" + return 0 + fi +} # Upload to cloud # Usage: -# cloud_upload_list_delete=("$cloud_upload_ssh_dir/repodata") -# cloud_upload_list_upload=("$root_repos/*" "$root_repos/repodata") +# cloud_upload_list_delete=("$CLOUD_UPLOAD_SSH_DIR/repodata") +# cloud_upload_list_upload=("$ROOT_REPOS/*" "$ROOT_REPOS/repodata") # cloud_upload cloud_upload_list_upload cloud_upload_list_delete cloud_upload() { - # Print new block only if definded + # Print new block only if defined local ssh_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" if [ -n "$1" ]; then echo fi + + # Setup SSH keys on the build machine + setup_ssh + # Delete files on remote if needed if [ -n "$2" ]; then - echo "Deleting given files in $cloud_upload_ssh_host .." + echo "Deleting given files in $CLOUD_UPLOAD_SSH_HOST .." local -n arr_del=$2 local err=0 for d in "${arr_del[@]}"; do if [ -n "$d" ]; then - local cmd1="ssh $ssh_args $cloud_upload_ssh_user@$cloud_upload_ssh_host \"rm -rf $d\" $verbosity_level" + local cmd1="ssh $ssh_args $CLOUD_UPLOAD_SSH_USER@\ + $CLOUD_UPLOAD_SSH_HOST \"rm -rf $d\" $VERBOSITY_LEVEL" eval "$cmd1" + # shellcheck disable=SC2181 if [ "$?" != "0" ]; then err=1 fi @@ -37,13 +82,15 @@ cloud_upload() { # Upload files to remote if [ -n "$1" ]; then - echo "Uploading built files to $cloud_upload_ssh_host .." + echo "Uploading built files to $CLOUD_UPLOAD_SSH_HOST .." local -n arr_upl=$1 local err=0 for u in "${arr_upl[@]}"; do if [ -n "$u" ]; then - local cmd2="scp $ssh_args -r $u $cloud_upload_ssh_user@$cloud_upload_ssh_host:$cloud_upload_ssh_dir/ $verbosity_level" + local cmd2="scp $ssh_args -r $u $CLOUD_UPLOAD_SSH_USER@\ + $CLOUD_UPLOAD_SSH_HOST:$CLOUD_UPLOAD_SSH_DIR/ $VERBOSITY_LEVEL" eval "$cmd2" + # shellcheck disable=SC2181 if [ "$?" != "0" ]; then err=1 fi @@ -56,10 +103,15 @@ cloud_upload() { # Sign and update repos metadata in remote cloud_repo_sign_and_update() { - echo "Signing and updating repos metadata in $cloud_upload_ssh_host .." + # Setup SSH keys on the build machine + setup_ssh + # Sign and update repos metadata in remote + echo "Signing and updating repos metadata in $CLOUD_UPLOAD_SSH_HOST .." local ssh_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" - local remote_cmd="cd ~/.scripts && ./update-repo-packages-signature.bash $cloud_upload_gpg_passphrase" - local cmd1="ssh $ssh_args $cloud_upload_ssh_user@$cloud_upload_ssh_host \"$remote_cmd\" $verbosity_level" + local remote_cmd="cd ~/.scripts && ./update-repo-packages-signature.bash \ + $CLOUD_UPLOAD_GPG_PASSPHRASE" + local cmd1="ssh $ssh_args $CLOUD_UPLOAD_SSH_USER@\ + $CLOUD_UPLOAD_SSH_HOST \"$remote_cmd\" $VERBOSITY_LEVEL" eval "$cmd1" postcmd $? echo @@ -77,9 +129,14 @@ postcmd() { # Get max number from array max() { - local -n arr_nums=$1 - IFS=$'\n' - echo "${arr_nums[*]}" | sort -nr | head -n1 + local max="$1" + shift + for value in "$@"; do + if [[ "$value" -gt "$max" ]]; then + max="$value" + fi + done + echo "$max" } # Mkdir and children dirs @@ -105,19 +162,21 @@ remove_dir() { # Get latest tag version get_current_repo_tag() { - cd "$root_prod" || exit 1 + # shellcheck disable=SC2153 + cd "$ROOT_PROD" || exit 1 tg=$(git rev-list --tags --max-count=1) ds=$(git describe --tags "$tg") - echo "$ds" | sed 's/v//' + ds="${ds/v/}" + echo "$ds" } get_module_version() { - local root_prod="$1" local version="" # Check if module.info exists and extract version if [ -f "module.info" ]; then - version=$(grep -E '^version=[0-9]+(\.[0-9]+)*' module.info | head -n 1 | cut -d'=' -f2) + version=$(grep -E '^version=[0-9]+(\.[0-9]+)*' module.info | \ + head -n 1 | cut -d'=' -f2) version=$(echo "$version" | sed -E 's/^([0-9]+\.[0-9]+(\.[0-9]+)?).*/\1/') fi @@ -132,7 +191,7 @@ get_module_version() { # Get latest commit date get_current_date() { - echo $(date +'%Y-%m-%d %H:%M:%S %z') + date +'%Y-%m-%d %H:%M:%S %z' } # Get latest commit date version @@ -143,31 +202,35 @@ get_latest_commit_date_version() { local highest_version theme_version=$(git log -n1 --pretty='format:%cd' --date=format:'%Y%m%d%H%M') - cd "$root_prod" || exit 1 + cd "$ROOT_PROD" || exit 1 prod_version=$(git log -n1 --pretty='format:%cd' --date=format:'%Y%m%d%H%M') max_prod=("$theme_version" "$prod_version") - highest_version=$(max max_prod) + highest_version=$(max "${max_prod[@]}") echo "$highest_version" } # Pull project repo and theme make_prod_repos() { + local root_prod="$1" + local prod="$2" + local cmd; # Webmin or Usermin - if [ ! -d "$1" ]; then + if [ ! -d "$root_prod" ]; then local repo="webmin/$prod.git" - cmd="git clone https://github.com/$repo $verbosity_level" + cmd="git clone $GIT_BASE_URL/$repo $VERBOSITY_LEVEL" eval "$cmd" if [ ! -d "webmin" ]; then - cmd="git clone --depth 1 https://github.com/webmin/webmin $verbosity_level" + cmd="git clone --depth 1 $WEBMIN_REPO \ + $VERBOSITY_LEVEL" eval "$cmd" fi fi # Theme - theme="authentic-theme" - if [ ! -d "$1/$theme" ]; then - cd "$1" || exit 1 + local theme="authentic-theme" + if [ ! -d "$root_prod/$theme" ]; then + cd "$root_prod" || exit 1 local repo="webmin/$theme.git" - cmd="git clone --depth 1 https://github.com/$repo $verbosity_level" + cmd="git clone --depth 1 $GIT_BASE_URL/$repo $VERBOSITY_LEVEL" eval "$cmd" fi } @@ -175,8 +238,9 @@ make_prod_repos() { # Make module repo make_module_repo_cmd() { local module="$1" - printf "git clone --depth 1 https://%s@github.com/virtualmin/%s.git %s" \ - "$github_token" "$module" "$verbosity_level" + local target="$2" + printf "git clone --depth 1 $target/%s.git %s" \ + "$module" "$VERBOSITY_LEVEL" } # Get last commit date from repo @@ -191,22 +255,24 @@ get_last_commit_date() { # Get required build scripts from Webmin repo make_module_build_deps() { # Create directory for build dependencies if it doesn't exist - if [ ! -d "$root/build-deps" ]; then - mkdir -p "$root/build-deps" + if [ ! -d "$ROOT_DIR/build-deps" ]; then + mkdir -p "$ROOT_DIR/build-deps" fi # Download required scripts from Webmin repo if they don't exist - if [ ! -f "$root/build-deps/makemoduledeb.pl" ] || \ - [ ! -f "$root/build-deps/makemodulerpm.pl" ] || \ - [ ! -f "$root/build-deps/create-module.pl" ]; then + if [ ! -f "$ROOT_DIR/build-deps/makemoduledeb.pl" ] || \ + [ ! -f "$ROOT_DIR/build-deps/makemodulerpm.pl" ] || \ + [ ! -f "$ROOT_DIR/build-deps/create-module.pl" ]; then echo "Downloading build dependencies .." # Create temporary directory - local temp_dir=$(mktemp -d) + local temp_dir + temp_dir=$(mktemp -d) cd "$temp_dir" || exit 1 # Clone Webmin repository (minimal depth) - cmd="git clone --depth 1 --filter=blob:none --sparse https://github.com/webmin/webmin.git $verbosity_level" + cmd="git clone --depth 1 --filter=blob:none --sparse \ + $WEBMIN_REPO.git $VERBOSITY_LEVEL" eval "$cmd" postcmd $? echo @@ -214,13 +280,14 @@ make_module_build_deps() { cd webmin || exit 1 # Copy required files to build-deps directory - cp makemoduledeb.pl makemodulerpm.pl create-module.pl "$root/build-deps/" + cp makemoduledeb.pl makemodulerpm.pl create-module.pl \ + "$ROOT_DIR/build-deps/" # Make scripts executable - chmod +x "$root/build-deps/"*.pl + chmod +x "$ROOT_DIR/build-deps/"*.pl # Clean up - cd "$root" || exit 1 + cd "$ROOT_DIR" || exit 1 remove_dir "$temp_dir" fi } @@ -230,6 +297,7 @@ adjust_module_filename() { local repo_dir="$1" local package_type="$2" local failed=0 + local temp_file # Create a secure temporary file temp_file=$(mktemp) || { echo "Failed to create temporary file"; return 1; } @@ -271,7 +339,8 @@ adjust_module_filename() { esac # Perform rename and check for failure - if ! eval "mv \"$file\" \"$dir_name/$new_name\" $verbosity_level_with_input"; then + if ! eval "mv \"$file\" \"$dir_name/$new_name\" \ + $VERBOSITY_LEVEL_WITH_INPUT"; then failed=1 fi done < "$temp_file" @@ -288,7 +357,7 @@ spinner() { local pid=$! local spin='-\|/' local i=0 - printf "$msg " + printf "%s " "$msg" while kill -0 $pid 2>/dev/null; do (( i = (i + 1) % 4 )) # No spinner if not an interactive shell diff --git a/.github/build/init.sh b/.github/build/init.sh deleted file mode 100644 index 308084025..000000000 --- a/.github/build/init.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright @iliajie -# -# Build init -# -# - -# Set up SSH dev keys -if [ -n "$WEBMIN_DEV__SSH_PRV_KEY" ] && [ -n "$WEBMIN_DEV__SSH_PUB_KEY" ]; then - # Generate new pair with right permissions - cmd="ssh-keygen -t rsa -q -f \"$HOME/.ssh/id_rsa\" -N \"\"$verbosity_level" - eval "$cmd" - # Import SSH keys from secrets to be able to connect to the remote host - echo "$WEBMIN_DEV__SSH_PRV_KEY" > "$HOME/.ssh/id_rsa" - echo "$WEBMIN_DEV__SSH_PUB_KEY" > "$HOME/.ssh/id_rsa.pub" - -# Set up SSH production keys -elif [ -n "$WEBMIN_PROD__SSH_PRV_KEY" ] && [ -n "$WEBMIN_PROD__SSH_PUB_KEY" ]; then - # Generate new pair with right permissions - cmd="ssh-keygen -t rsa -q -f \"$HOME/.ssh/id_rsa\" -N \"\"$verbosity_level" - eval "$cmd" - # Import SSH keys from secrets to be able to connect to the remote host - echo "$WEBMIN_PROD__SSH_PRV_KEY" > "$HOME/.ssh/id_rsa" - echo "$WEBMIN_PROD__SSH_PUB_KEY" > "$HOME/.ssh/id_rsa.pub" -fi - -# Create symlink to Perl -ln -fs /usr/bin/perl /usr/local/bin/perl diff --git a/.github/build/rpm.sh b/.github/build/rpm.sh deleted file mode 100755 index ce73a2efe..000000000 --- a/.github/build/rpm.sh +++ /dev/null @@ -1,237 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright @iliajie -# -# Automatically builds and updates a repo metadata. -# Pulls latest changes from GitHub, detects release -# version based on what's available in the repo -# -# (RHEL) -# -# Usage: -# -# # Pull and build production versions -# # of both Webmin and Usermin -# ./rpm.sh -# -# # Pull and build devel versions -# # of both Webmin and Usermin -# ./rpm.sh --testing -# -# # Pull and build production Webmin version 2.101, forcing -# # release version 3, displaying detailed output -# ./rpm.sh webmin 2.101 3 --debug -# -# # Pull and build production Usermin version 2.000, -# # automatically setting release version to minimal -# ./rpm.sh usermin 2.000 -# - -# shellcheck disable=SC1091 -# Source build variables -source ./vars.sh || exit 1 - -# Source build init -source ./init.sh || exit 1 - -# Source general build functions -source ./funcs.sh || exit 1 - -# Build product func -build_prod() { - - # Pack with English only in devel builds - local english_only=0 - if [[ "'$*'" == *"--testing"* ]]; then - english_only=1 - fi - - # Always return back to root directory - cd "$root" || exit 1 - - # Define root - local ver="" - local prod=$1 - local devel=0 - root_prod="$root/$prod" - - # Print build actual date - date=$(get_current_date) - - # Print opening header - echo "************************************************************************" - echo " build start date: $date " - echo " package format: RPM " - echo " product: $prod " - (make_prod_repos "$root_prod") & - spinner " package output version:" - - # Pull main project first to get the latest tag - cd "$root_prod" || exit 1 - cmd="git pull $verbosity_level" - eval "$cmd" - rs1=$? - # Clean and try again - if [ "$rs1" != "0" ]; then - cmd="git checkout \"*\" $verbosity_level && git clean -f -d $verbosity_level && git pull $verbosity_level" - eval "$cmd" - rs1=$? - fi - - # Pull theme to theme dir - cd "authentic-theme" || exit 1 - cmd="git pull $verbosity_level" - eval "$cmd" - rs2=$? - # Clean and try again - if [ "$rs2" != "0" ]; then - cmd="git checkout \"*\" $verbosity_level && git clean -f -d $verbosity_level && git pull $verbosity_level" - eval "$cmd" - rs2=$? - fi - if [ "$rs1" != "0" ] || [ "$rs2" != "0" ]; then - rs=1 - else - rs=0 - fi - - # Build number - date_version=$(get_latest_commit_date_version) - - # Handle other params - cd "$root_prod" || exit 1 - if [[ "'$2'" != *"--"* ]]; then - ver=$2 - fi - if [[ "'$3'" != *"--"* ]] && [[ -n "$3" ]]; then - rel=$3 - else - rel=1 - fi - if [ -z "$ver" ]; then - ver=$(get_current_repo_tag) - fi - if [[ "'$*'" == *"--testing"* ]]; then - devel=1 - ver="$ver.$date_version" - # Set actual product version - echo "${ver}" >"version" - fi - - printf "$ver-$rel\n" - echo "************************************************************************" - - echo "Pulling latest changes.." - # We need to pull first to get the latest tag, - # so here we only report an error if any - postcmd $rs - echo - - echo "Pre-clean up .." - # Make sure directories exist - make_dir "$root_prod/newkey/rpm/" - make_dir "$root_prod/umodules/" - make_dir "$root_prod/minimal/" - make_dir "$root_prod/tarballs/" - make_dir "$root_build/BUILD/" - make_dir "$root_build/BUILDROOT/" - make_dir "$root_build/RPMS/" - make_dir "$root_build/SOURCES/" - make_dir "$root_build/SPECS/" - make_dir "$root_build/SRPMS/" - make_dir "$root_repos/" - - # Re-create legacy link - remove_dir "$root/webadmin" - ln -s "$root/webmin" "$root/webadmin" - - # Purge old files - purge_dir "$root_prod/newkey/rpm" - purge_dir "$root_prod/umodules" - purge_dir "$root_prod/minimal" - purge_dir "$root_prod/tarballs" - purge_dir "$root_build/BUILD" - purge_dir "$root_build/BUILDROOT" - purge_dir "$root_build/RPMS" - purge_dir "$root_build/SOURCES" - purge_dir "$root_build/SPECS" - purge_dir "$root_build/SRPMS" - remove_dir "$root_repos/repodata" - if [ "$prod" != "" ]; then - rm -f "$root_repos/$prod-"* - rm -f "$root_repos/${prod}_"* - fi - postcmd $? - make_dir "$root_build/RPMS/noarch" - echo - - # Descend to project dir - cd "$root_prod" || exit 1 - - if [ "$english_only" = "1" ]; then - echo "Cleaning languages .." - cmd="./bin/language-manager --mode=clean --yes $verbosity_level_with_input" - eval "$cmd" - postcmd $? - echo - else - # Force restore build directory - if [ ! -f "lang/ja" ]; then - echo "Restoring languages .." - cmd="git checkout \"*\" $verbosity_level && git clean -f -d $verbosity_level && git pull $verbosity_level" - eval "$cmd" - postcmd $? - echo - fi - fi - echo "Pre-building package .." - eval "$cmd" - if [ "$rel" = "1" ]; then - args="$ver" - else - args="$ver-$rel" - fi - - cmd="./makedist.pl \"$args\" $verbosity_level" - eval "$cmd" - postcmd $? - echo - - echo "Building package .." - cmd="./makerpm.pl \"$ver\" \"$rel\" $verbosity_level" - eval "$cmd" - postcmd $? - echo - - cd "$root" || exit 1 - echo "Preparing built files for upload .." - cmd="cp -f $root_prod/tarballs/$prod-$ver*\.tar.gz $root_repos/${prod}-$ver.tar.gz $verbosity_level" - eval "$cmd" - cmd="find $root_rpms -name $prod-$ver-$rel*\.rpm -exec mv '{}' $root_repos \; $verbosity_level" - eval "$cmd" - # cmd="mv -f $root_repos/$prod-$ver-$rel*\.rpm $root_repos/${prod}-$ver-$rel.noarch.rpm $verbosity_level" # file name is the same - # eval "$cmd" - postcmd $? - echo - - echo "Post-clean up .." - cd "$root_build" || exit 1 - for dir in *; do - cmd="rm -rf \"$dir/*\" $verbosity_level" - eval "$cmd" - done - postcmd $? -} - -# Main -if [ -n "$1" ] && [[ "'$1'" != *"--"* ]]; then - build_prod $@ - cloud_upload_list_upload=("$root_repos/$1*") -else - build_prod webmin $@ - build_prod usermin $@ - cloud_upload_list_upload=("$root_repos/*") -fi - -cloud_upload cloud_upload_list_upload -cloud_repo_sign_and_update diff --git a/.github/build/vars.sh b/.github/build/vars.sh deleted file mode 100755 index 7e2541b9d..000000000 --- a/.github/build/vars.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright @iliajie -# -# Build variables -# -# - -# Set defaults -root="${ENV_BUILD__ROOT:-$HOME}" -root_repos="${ENV_BUILD__ROOT_REPOS:-$root/repo}" -root_build="${ENV_BUILD__ROOT_BUILD:-$root/rpmbuild}" -root_rpms="${ENV_BUILD__ROOT_RPMS:-$root_build/RPMS/noarch}" - -# GitHub private repos access token -github_token="${ENV_BUILD__GITHUB_TOKEN}" - -# Cloud upload config -cloud_upload_ssh_user="${ENV_BUILD__CLOUD_UPLOAD_SSH_USER:-webmin.dev}" -cloud_upload_ssh_host="${ENV_BUILD__CLOUD_UPLOAD_SSH_HOST:-webmin.dev}" -cloud_upload_ssh_dir="${ENV_BUILD__CLOUD_UPLOAD_SSH_DIR:-~/domains/download.webmin.dev/public_html}" -cloud_upload_gpg_passphrase="${WEBMIN_DEV__GPG_PH}" - -# Define verbosity level -verbosity_level=' >/dev/null 2>&1