|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # File : release.sh |
3 | | -# Purpose : Release script for the AmazingZImageWorkflow project |
| 3 | +# Purpose : Release script for the Amazing Z-Image Workflow project |
4 | 4 | # Author : Martin Rizzo | <martinrizzo@gmail.com> |
5 | 5 | # Date : Dec 12, 2025 |
6 | 6 | # Repo : https://github.com/martin-rizzo/AmazingZImageWorkflow |
|
14 | 14 | # Builds a zip file containing specific workflow files and associated images. |
15 | 15 | # |
16 | 16 | # Usage: |
17 | | -# build_zip_file <ZIP_FILE> <WORKFLOW> |
| 17 | +# build_zip_file ZIP_FILE WORKFLOW |
18 | 18 | # |
19 | 19 | # Parameters: |
20 | 20 | # ZIP_FILE: The path to the output zip file. |
21 | 21 | # WORKFLOW: The base name of the workflow (e.g., "amazing-z-image"). |
22 | 22 | # |
23 | | -# The function collects the following files: |
24 | | -# - "${workflow}_GGUF.json" |
25 | | -# - "${workflow}_SAFETENSORS.json" |
| 23 | +# This function collects several types of files and organizes them into a single |
| 24 | +# zip archive. It includes general files like LICENSE, README.TXT, and various |
| 25 | +# workflows and galleries with different suffixes and potential variations. |
| 26 | +# |
| 27 | +# Specifically, it looks for: |
26 | 28 | # - "LICENSE" |
27 | | -# - The file "files/amazing-z-readme.txt (renamed to "README.TXT") |
28 | | -# - The file "${workflow}_styles.txt" (renamed to "styles.txt") |
29 | | -# - All files matching "${workflow}_styles*.jpg" (renamed to "styles*.jpg") |
| 29 | +# - "files/amazing-z-readme.txt" (renamed to "README.TXT") |
| 30 | +# - Workflow files : "${WORKFLOW}<V>_<FORMAT>.json" |
| 31 | +# - Gallery description files: "${WORKFLOW}<V>_gallery.txt" (renamed to "gallery<V>.txt") |
| 32 | +# - And gallery image files : "${WORKFLOW}<V>_gallery<N>.jpg" (renamed to "gallery<V><N>.jpg") |
| 33 | +# where: |
| 34 | +# <FORMAT> can be "_GGUF" or "_SAFETENSORS" |
| 35 | +# <V> is a variant (e.g., "-a", "-b") |
| 36 | +# <N> is an integer representing different gallery images (e.g. 1, 2, 3, etc.) |
| 37 | +# |
| 38 | +# The function creates temporary copies of certain files (like README.TXT and |
| 39 | +# gallery files) with appropriate names to archive them within the final zip. |
| 40 | +# After creating the zip file, it removes those temporary copies. |
| 41 | +# |
| 42 | +# Example usage: |
| 43 | +# build_zip_file workflow.zip amazing-z-image |
30 | 44 | # |
31 | | -# Example: |
32 | | -# build_zip_file workflow.zip amazing-z-image |
33 | 45 | # |
34 | 46 | build_zip_file() { |
35 | 47 | local zip_file="$1" |
36 | 48 | local workflow="$2" |
37 | | - local temp_files=() #< to keep track of temporary files |
38 | | - local gallery="${workflow}_styles" |
| 49 | + local temp_files_=() #< to keep track of temporary files |
39 | 50 | local gallery_ext=".jpg" |
40 | | - local filename |
41 | 51 |
|
42 | 52 | # file name suffixes regarding the format of the checkpoint file |
43 | 53 | local formats=( "_GGUF" "_SAFETENSORS" ) |
44 | 54 |
|
45 | 55 | # file name suffixes relating to different variants of the same workflow |
46 | | - local variations=( "" "-a" "-b" "-c" "-d" "-e" "-f" ) |
| 56 | + local possible_variations=( "" "-a" "-b" "-c" "-d" "-e" "-f" ) |
| 57 | + local found_variations=( ) |
47 | 58 |
|
48 | 59 | # in this array, we collect all the files that are part of the release package |
49 | | - local zip_content=( |
50 | | - "LICENSE" |
51 | | - ) |
52 | | - |
53 | | - # loop through all variations that the workflow can have (adding the available suffixes) |
54 | | - for variation in "${variations[@]}"; do |
55 | | - for format in "${formats[@]}"; do |
56 | | - filename="${workflow}${variation}${format}.json" |
57 | | - [[ -f "$filename" ]] && zip_content+=( "${filename}" ) |
58 | | - done |
59 | | - done |
| 60 | + local zip_content=( ) |
60 | 61 |
|
61 | | - # copy temporarily "README.TXT" file from /files directory |
| 62 | + # collect the file "LICENSE" and "files/amazing-z-readme.txt" |
| 63 | + zip_content+=( LICENSE ) |
62 | 64 | cp "files/amazing-z-readme.txt" "README.TXT" |
63 | | - temp_files+=( "README.TXT" ) |
64 | | - |
65 | | - # copy "styles.txt" file |
66 | | - cp "${gallery}.txt" "styles.txt" |
67 | | - temp_files+=( "styles.txt" ) |
| 65 | + zip_content+=( "README.TXT" ) |
| 66 | + temp_files_+=( "README.TXT" ) |
68 | 67 |
|
69 | | - echo "release.sh is under development." #< placeholder until the function is implemented properly |
70 | | - exit 1 |
| 68 | + # loop through all possible variations that the workflow can have, |
| 69 | + for variation in "${possible_variations[@]}"; do |
| 70 | + local found= |
| 71 | + for format in "${formats[@]}"; do |
| 72 | + local workflow_file="${workflow}${variation}${format}.json" |
| 73 | + [[ ! -f "$workflow_file" ]] && continue |
71 | 74 |
|
72 | | - # # collect gallery images renaming them to "styles1.jpg", "styles2.jpg", etc. |
73 | | - # for file in "${gallery}"*"${gallery_ext}"; do |
74 | | - # [[ -f "$file" ]] || continue #< ensure it's a valid file |
| 75 | + # if the workflow file exists, then add it to the zip content |
| 76 | + # and mark the variation as found |
| 77 | + zip_content+=( "${workflow_file}" ) |
| 78 | + found=true |
| 79 | + done |
75 | 80 |
|
76 | | - # # extract the numeric suffix from the filename |
77 | | - # index=${file#"$gallery"} |
78 | | - # index=${index%"$gallery_ext"} |
| 81 | + # if variation was found, then add it to the list |
| 82 | + if [[ $found == true ]]; then |
| 83 | + found_variations+=( "${variation}" ) |
| 84 | + fi |
| 85 | + done |
79 | 86 |
|
80 | | - # # create temporary image file (e.g., "styles1.jpg") |
81 | | - # image="styles${index}.jpg" |
82 | | - # cp "$file" "$image" |
83 | | - # temp_files+=( "$image" ) |
84 | | - # done |
| 87 | + # for each found variation, creates the temporary gallery files |
| 88 | + # ${variation} is empty string in workflows that don't have variations |
| 89 | + for variation in "${found_variations[@]}"; do |
| 90 | + |
| 91 | + # ${va} is ${variation} but without prefix '-' |
| 92 | + #local va="${variation#-}" |
| 93 | + #[[ -n "${va}" ]] && va="${va}_" |
| 94 | + local va="${variation}" |
| 95 | + |
| 96 | + # check if the file "${workflow}_gallery.txt" exists |
| 97 | + gallery_file="${workflow}${variation}_gallery.txt" |
| 98 | + new_file="gallery${va}.txt" |
| 99 | + [[ ! -f "$gallery_file" ]] && continue |
| 100 | + |
| 101 | + # create the file "$gallery${va}.txt" and add it to the zip content |
| 102 | + cp "$gallery_file" "$new_file" |
| 103 | + zip_content+=( "$new_file" ) |
| 104 | + temp_files_+=( "$new_file" ) |
| 105 | + |
| 106 | + # search for files that match "${workflow}_gallery<N>.jpg" pattern, |
| 107 | + # where N is a number between 0 and 9 and {gallery_ext} is always ".jpg" |
| 108 | + for idx in {0..9}; do |
| 109 | + gallery_file="${workflow}${variation}_gallery${idx}${gallery_ext}" |
| 110 | + new_file="gallery${va}${idx}${gallery_ext}" |
| 111 | + [[ ! -f "$gallery_file" ]] && continue |
| 112 | + |
| 113 | + # create the file "$gallery${va}<N>.jpg" and add it to the zip content |
| 114 | + cp "$gallery_file" "$new_file" |
| 115 | + zip_content+=( "$new_file" ) |
| 116 | + temp_files_+=( "$new_file" ) |
| 117 | + done |
| 118 | + done |
85 | 119 |
|
86 | | - # # create the zip archive with the collected files |
87 | | - # zip -j "$zip_file" "${zip_content[@]}" "${temp_files[@]}" |
| 120 | + # create the zip archive with the collected files |
| 121 | + zip -j "$zip_file" "${zip_content[@]}" |
88 | 122 |
|
89 | | - # # remove temporary files |
90 | | - # rm "${temp_files[@]}" |
| 123 | + # remove temporary files |
| 124 | + rm "${temp_files_[@]}" |
91 | 125 | } |
92 | 126 |
|
93 | 127 |
|
|
0 commit comments