deploy: some fixes, and delete old unused static regen scripts

This commit is contained in:
E. S. 2025-05-18 00:42:00 +03:00
parent e926c5e8c8
commit 6e3a5c59d2
5 changed files with 4 additions and 128 deletions

View File

@ -6,6 +6,7 @@ die() {
}
set -e
set -x
if ! command -v yq >/dev/null 2>&1; then
die "yq is not installed. Please install yq to parse YAML files."

View File

@ -1,37 +0,0 @@
#!/bin/sh
die() {
>&2 echo "error: $*"
exit 1
}
set -e
if ! command -v yq >/dev/null 2>&1; then
die "yq is not installed. Please install yq to parse YAML files."
fi
PHP="$(which php)"
SCRIPT_DIR=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)
APP_DIR="$(realpath "$SCRIPT_DIR/../")"
OUTPUT_ROOT_DIR=
while [ $# -gt 0 ]; do
case $1 in
-o) OUTPUT_ROOT_DIR="$2"; shift ;;
-h) usage ;;
*) die "unexpected argument: $1" ;;
esac
shift
done
[ -z "$OUTPUT_ROOT_DIR" ] && die "you must specify output directory"
PROJECTS=$("$SCRIPT_DIR"/util/get_projects.sh "$APP_DIR/config.yaml")
for project in $PROJECTS; do
"$SCRIPT_DIR"/util/build_css.sh -i "$APP_DIR/public/$project/scss" -o "$OUTPUT_ROOT_DIR/public/$project/dist-css" || die "build_css failed"
"$SCRIPT_DIR"/util/build_js.sh -i "$APP_DIR/public/common/js" -o "$OUTPUT_ROOT_DIR/public/$project/dist-js" || die "build_js failed"
$PHP "$SCRIPT_DIR"/util/gen_runtime_config.php \
--app-root "$OUTPUT_ROOT_DIR" \
--commit-hash "$(git rev-parse HEAD)" \
> "$OUTPUT_ROOT_DIR/config-runtime.php" || die "gen_runtime_config failed"
done

View File

@ -6,6 +6,7 @@ die() {
}
set -e
set -x
PHP="$(which php)"
SCRIPT_DIR=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)

View File

@ -54,6 +54,8 @@ if [ -z "$PREV_COMMIT" ]; then
exit 0
fi
cd "$APP_DIR"
# Check if common files have changed
common_changed=$(git diff --name-only "$PREV_COMMIT" "$CURR_COMMIT" -- "$APP_DIR/public/common")
if [ -n "$common_changed" ]; then

View File

@ -1,91 +0,0 @@
#!/usr/bin/env php
<?php
require __DIR__.'/../../src/init.php';
global $config;
// Check if yaml extension is available
if (!function_exists('yaml_parse_file')) {
fwrite(STDERR, "error: yaml extension is not installed. Please install php-yaml extension.\n");
exit(1);
}
$commit_hash = null;
$app_root = null;
for ($i = 1; $i < $argc; $i++) {
switch ($argv[$i]) {
case '--commit-hash':
$commit_hash = $argv[++$i] ?? usage('missing value for --commit-hash');
break;
case '--app-root':
$app_root = $argv[++$i] ?? usage('missing value for --app-root');
break;
default:
usage("unknown option {$argv[$i]}");
}
}
if (is_null($commit_hash) || is_null($app_root))
usage();
$hashes = [
'commit_hash' => $commit_hash,
'assets' => []
];
foreach ($config['projects'] as $project) {
foreach (['js', 'css'] as $type) {
$dist_dir = $app_root.'/public/'.$project.'/dist-'.$type;
$entries = glob_recursive($dist_dir.'/*.'.$type);
if (empty($entries)) {
fwrite(STDERR, "warning: no files found in $dist_dir\n");
continue;
}
foreach ($entries as $file) {
$hashes['assets'][$project][$type.'/'.basename($file)] = [
'integrity' => []
];
foreach (\engine\skin\FeaturedSkin::RESOURCE_INTEGRITY_HASHES as $hash_type) {
$hashes['assets'][$project][$type.'/'.basename($file)]['integrity'][$hash_type] = base64_encode(hash_file($hash_type, $file, true));
}
}
}
}
echo "<?php\n\n";
echo "return ".var_export($hashes, true).";\n";
function usage(string $msg = ''): never {
if ($msg !== '')
fwrite(STDERR, "error: {$msg}\n");
$script = $GLOBALS['argv'][0];
fwrite(STDERR, "usage: {$script} --commit-hash HASH --app-root APP_ROOT\n");
exit(1);
}
function glob_escape(string $pattern): string {
if (str_contains($pattern, '[') || str_contains($pattern, ']')) {
$placeholder = uniqid();
$replaces = [$placeholder.'[', $placeholder.']', ];
$pattern = str_replace( ['[', ']'], $replaces, $pattern);
$pattern = str_replace( $replaces, ['[[]', '[]]'], $pattern);
}
return $pattern;
}
/**
* Does not support flag GLOB_BRACE
*
* @param string $pattern
* @param int $flags
* @return array
*/
function glob_recursive(string $pattern, int $flags = 0): array {
$files = glob(glob_escape($pattern), $flags);
foreach (glob(glob_escape(dirname($pattern)).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}