From bdea14aa2702508b45748c25f03fc36302951855 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Fri, 20 Dec 2024 20:47:57 +0800 Subject: [PATCH] chore(scripts): update scripts and delete useless files (#512) Signed-off-by: wuhuizuo Signed-off-by: wuhuizuo --- .../scripts/gen-delivery-image-commands.ts | 7 +-- .../gen-delivery-images-with-config.sh | 53 ------------------- 2 files changed, 4 insertions(+), 56 deletions(-) mode change 100644 => 100755 packages/scripts/gen-delivery-image-commands.ts delete mode 100755 packages/scripts/gen-delivery-images-with-config.sh diff --git a/packages/scripts/gen-delivery-image-commands.ts b/packages/scripts/gen-delivery-image-commands.ts old mode 100644 new mode 100755 index 6e6212ac..f37c0ebf --- a/packages/scripts/gen-delivery-image-commands.ts +++ b/packages/scripts/gen-delivery-image-commands.ts @@ -1,5 +1,6 @@ -import { parse } from "https://deno.land/std@0.194.0/flags/mod.ts"; -import * as yaml from "https://deno.land/std@0.214.0/yaml/mod.ts"; +#!/usr/bin/env -S deno run --allow-read --allow-write +import * as yaml from "jsr:@std/yaml@1.0.5" +import { parseArgs } from "jsr:@std/cli@1.0.9" interface Rule { description?: string; @@ -99,7 +100,7 @@ const { image_url, yaml_file = "./packages/delivery.yaml", outfile = "./delivery-images.sh", -} = parse(Deno.args); +} = parseArgs(Deno.args); // Example usage await generateShellScript(image_url, yaml_file, outfile); diff --git a/packages/scripts/gen-delivery-images-with-config.sh b/packages/scripts/gen-delivery-images-with-config.sh deleted file mode 100755 index 70c6fb9c..00000000 --- a/packages/scripts/gen-delivery-images-with-config.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -RELEASE_SCRIPTS_DIR=$(dirname "$(readlink -f "$0")") -PROJECT_ROOT_DIR=$(realpath "${RELEASE_SCRIPTS_DIR}/../..") - -# Function to copy container image to destination repositories based on rules defined in YAML config -main() { - local image_url_with_tag="$1" - local yaml_file="${2:-${PROJECT_ROOT_DIR}/packages/delivery.yaml}" - local out_file="${3:-${RELEASE_SCRIPTS_DIR}/delivery-images.sh}" - rm -rf "$out_file" - - # Extract image URL and tag - image_url="$(echo "$image_url_with_tag" | cut -d ':' -f1)" - tag=$(echo "$image_url_with_tag" | cut -d ':' -f2) - - # Retrieve rules for the source repository from the YAML config - rule_count=$(yq ".image_copy_rules[\"$image_url\"] | length" "$yaml_file") - if [ "$rule_count" -eq 0 ]; then - echo "🤷 none rules found for image: $image_url" - exit 0 - fi - - # Loop through each rule for the source repository - for ri in $(seq 0 $((rule_count - 1))); do - rule=$(yq ".image_copy_rules[\"$image_url\"][$ri]" "$yaml_file") - description=$(yq '.description' <<< "$rule") - dest_repos=$(yq '.dest_repositories[]' <<< "$rule") - - # Check if the tag matches the tags regex - if yq -e ".tags_regex[] | select(. | test \"$tag\")" 2>&1> /dev/null <<< "$rule" ; then - echo "Matching rule found for image URL '$image_url_with_tag':" - echo " Description: $description" - echo " Source Repository: $image_url" - - # Copy image to destination repositories using crane copy command - for dest_repo in $dest_repos; do - echo " Destination Repository: $dest_repo" - echo "crane copy $image_url_with_tag $dest_repo:$tag" >> "$out_file" - for constant_tag in $(yq '.constant_tags[]' <<< "$rule"); do - echo "crane tag $dest_repo:$tag $constant_tag" >> "$out_file" - done - done - fi - done - - if [ -f "$out_file" ]; then - echo "✅ Generated shell script: $out_file" - fi -} - -main "$@"