Ver Fonte

making the update script also write the version to file

Medowar há 1 semana atrás
pai
commit
dac21eb286
2 ficheiros alterados com 8 adições e 36 exclusões
  1. 1 1
      includes/version.php
  2. 7 35
      scripts/create-update-zip.sh

+ 1 - 1
includes/version.php

@@ -1,3 +1,3 @@
 <?php
 
-define("APP_VERSION", "v1.3.12");
+define("APP_VERSION", "v1.3.13");

+ 7 - 35
scripts/create-update-zip.sh

@@ -21,46 +21,20 @@ is_excluded_path() {
 }
 
 read_current_version() {
-    sed -nE 's/.*define\(["'\'']APP_VERSION["'\''],[[:space:]]*["'\'']([^"'\'']+)["'\'']\).*/\1/p' "$version_file" | head -n 1
+    sed -nE 's/.*define\("APP_VERSION",\s*"([^"]+)"\).*/\1/p' "$version_file" | head -n 1
 }
 
 write_current_version() {
     local version="$1"
 
-    NEW_APP_VERSION="$version" perl -0pi -e '
-        BEGIN { $version = $ENV{"NEW_APP_VERSION"}; $updated = 0; }
-        $updated += s/define\(["'\'']APP_VERSION["'\''],\s*["'\''][^"'\'']+["'\'']\);/define("APP_VERSION", "$version");/g;
-        END { exit($updated > 0 ? 0 : 2); }
-    ' "$version_file" || die "Version string could not be updated in $version_file"
-}
-
-sha256_file() {
-    local file="$1"
-
-    if command -v shasum >/dev/null 2>&1; then
-        shasum -a 256 "$file" | awk '{print $1}'
-    elif command -v sha256sum >/dev/null 2>&1; then
-        sha256sum "$file" | awk '{print $1}'
-    else
-        die "Required command not found: shasum or sha256sum"
-    fi
-}
-
-file_size() {
-    local file="$1"
-
-    if stat -f '%z' "$file" >/dev/null 2>&1; then
-        stat -f '%z' "$file"
-    else
-        stat -c '%s' "$file"
-    fi
+    sed -i -E "s/define\(\"APP_VERSION\", \"[^\"]+\"\);/define(\"APP_VERSION\", \"$version\");/" "$version_file"
+    [[ "$(read_current_version)" == "$version" ]] || die "Version string could not be updated in $version_file"
 }
 
 require_command git
 require_command zip
 require_command sed
-require_command awk
-require_command perl
+require_command sha256sum
 
 repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" || die "Not inside a git repository."
 current_dir="$(pwd -P)"
@@ -100,9 +74,7 @@ trap cleanup EXIT
 
 while IFS= read -r path; do
     [[ -n "$path" ]] || continue
-    if is_excluded_path "$path"; then
-        continue
-    fi
+    is_excluded_path "$path" && continue
     [[ -f "$path" ]] || continue
     printf '%s\n' "$path" >> "$tmp_file_list"
 done < <(git ls-files)
@@ -116,8 +88,8 @@ rm -f "$output_file"
 zip -q -@ "$output_file" < "$tmp_file_list"
 [[ -f "$output_file" ]] || die "ZIP archive was not created."
 
-checksum="$(sha256_file "$output_file")"
-size="$(file_size "$output_file")"
+checksum="$(sha256sum "$output_file" | awk '{print $1}')"
+size="$(stat -c '%s' "$output_file")"
 
 printf 'Update ZIP created\n'
 printf 'Version: %s\n' "$version"