nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 136 lines 4.0 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell --pure -i bash -p curl cacert nix-update jq gnused git 3 4set -euo pipefail 5 6SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 7 8get_latest_version() { 9 local repo="$1" 10 curl -sfS ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/$repo/releases/latest | jq -r .tag_name 11} 12 13download_and_extract_source() { 14 local repo="$1" 15 local version="$2" 16 local temp_dir=$(mktemp -d) 17 18 curl -sfSL "https://github.com/$repo/archive/$version.tar.gz" | tar -xz -C "$temp_dir" 19 20 echo $temp_dir 21} 22 23check_plugin_in_pom() { 24 local pom_file="$1" 25 local plugin_name="$2" 26 if [[ -f "$pom_file" ]]; then 27 grep -q "<artifactId>$plugin_name</artifactId>" "$pom_file" 2>/dev/null 28 else 29 return 1 30 fi 31} 32 33remove_plugin_from_pom() { 34 local pom_file="$1" 35 local plugin_name="$2" 36 37 if [[ ! -f "$pom_file" ]]; then 38 echo "Error: $pom_file does not exist" >&2 39 return 1 40 fi 41 42 awk -v plugin="$plugin_name" ' 43 /<plugin>/ { 44 plugin_block = $0 "\n" 45 in_plugin = 1 46 skip = 0 47 next 48 } 49 in_plugin && /<\/plugin>/ { 50 plugin_block = plugin_block $0 "\n" 51 if (!skip) { 52 printf "%s", plugin_block 53 } 54 in_plugin = 0 55 plugin_block = "" 56 next 57 } 58 in_plugin { 59 plugin_block = plugin_block $0 "\n" 60 if (/<artifactId>/ && index($0, plugin) > 0) { 61 skip = 1 62 } 63 next 64 } 65 !in_plugin { print } 66 ' "$pom_file" > "$pom_file.tmp" && mv "$pom_file.tmp" "$pom_file" 67 68 echo "Removed plugin blocks with artifactId '$plugin_name' from $pom_file" 69} 70 71update_patch() { 72 local source_dir="$1" 73 local plugin_name="$2" 74 local patch_file="$3" 75 76 if [[ ! -d "$source_dir" ]]; then 77 echo "Source directory $source_dir does not exist!" 78 exit 1 79 fi 80 81 local temp_dir=$(mktemp -d) 82 local plugin_found=false 83 local patch_content="" 84 85 echo "Checking for $plugin_name in pom.xml files..." 86 87 # Find all pom.xml files that contain the specified plugin 88 while IFS= read -r -d '' pom_file; do 89 if check_plugin_in_pom "$pom_file" "$plugin_name"; then 90 plugin_found=true 91 echo "Found $plugin_name in: $pom_file" 92 93 # Generate patch content for this file 94 local relative_path=$(echo "$pom_file" | sed "s|^$source_dir/||") 95 local temp_original="$temp_dir/original_$(basename "$pom_file")" 96 local temp_patched="$temp_dir/patched_$(basename "$pom_file")" 97 98 cp "$pom_file" "$temp_original" 99 cp "$pom_file" "$temp_patched" 100 101 remove_plugin_from_pom "$temp_patched" "$plugin_name" 102 103 # Generate diff for this file 104 if ! cmp -s "$temp_original" "$temp_patched"; then 105 local file_diff=$(diff -u "$temp_original" "$temp_patched" | sed "s|$temp_original|a/$relative_path|g; s|$temp_patched|b/$relative_path|g" | sed '1,2s/\t.*$//') 106 if [[ -n "$file_diff" ]]; then 107 patch_content+='diff --git a/'"$relative_path"' b/'"$relative_path"''$'\n' 108 patch_content+="$file_diff"$'\n' 109 fi 110 fi 111 fi 112 done < <(find "$source_dir" -name "pom.xml" -print0 | sort -z) 113 114 if [[ "$plugin_found" == "true" && -n "$patch_content" ]]; then 115 echo "Updating $patch_file..." 116 echo "$patch_content" > "$SCRIPT_DIR/$patch_file" 117 echo "Patch updated successfully!" 118 rm -rf "$temp_dir" 119 else 120 echo "No $plugin_name found on any pom.xml file. Patch not updated." 121 rm -rf "$temp_dir" 122 exit 1 123 fi 124} 125 126echo "Updating forge-mtg package..." 127 128version=$(get_latest_version "Card-Forge/forge") 129 130source_dir=$(download_and_extract_source "Card-Forge/forge" $version)/forge-$version 131 132update_patch "$source_dir" "launch4j-maven-plugin" "no-launch4j.patch" 133 134rm -rf "$(dirname "$source_dir")" 135 136nix-update --version-regex=forge-'(.*)' forge-mtg