Skip to content

Commit 3c0133d

Browse files
committed
feat: Implement support for variations in "release.sh" script
This commit enhances the `release.sh` script to support packaging of workflow variations into a single ZIP file. The updates enable workflows with suffixes such as "-a", "-b", "-c", etc., to be automatically bundled together. This change is necessary due to the introduction of two variations of z-image (z-image-a and z-image-b), which now require inclusion in the same ZIP file.
1 parent 5b552e9 commit 3c0133d

1 file changed

Lines changed: 82 additions & 48 deletions

File tree

files/scripts/release.sh

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# File : release.sh
3-
# Purpose : Release script for the AmazingZImageWorkflow project
3+
# Purpose : Release script for the Amazing Z-Image Workflow project
44
# Author : Martin Rizzo | <martinrizzo@gmail.com>
55
# Date : Dec 12, 2025
66
# Repo : https://github.com/martin-rizzo/AmazingZImageWorkflow
@@ -14,80 +14,114 @@
1414
# Builds a zip file containing specific workflow files and associated images.
1515
#
1616
# Usage:
17-
# build_zip_file <ZIP_FILE> <WORKFLOW>
17+
# build_zip_file ZIP_FILE WORKFLOW
1818
#
1919
# Parameters:
2020
# ZIP_FILE: The path to the output zip file.
2121
# WORKFLOW: The base name of the workflow (e.g., "amazing-z-image").
2222
#
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:
2628
# - "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
3044
#
31-
# Example:
32-
# build_zip_file workflow.zip amazing-z-image
3345
#
3446
build_zip_file() {
3547
local zip_file="$1"
3648
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
3950
local gallery_ext=".jpg"
40-
local filename
4151

4252
# file name suffixes regarding the format of the checkpoint file
4353
local formats=( "_GGUF" "_SAFETENSORS" )
4454

4555
# 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=( )
4758

4859
# 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=( )
6061

61-
# copy temporarily "README.TXT" file from /files directory
62+
# collect the file "LICENSE" and "files/amazing-z-readme.txt"
63+
zip_content+=( LICENSE )
6264
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" )
6867

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
7174

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
7580

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
7986

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
85119

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[@]}"
88122

89-
# # remove temporary files
90-
# rm "${temp_files[@]}"
123+
# remove temporary files
124+
rm "${temp_files_[@]}"
91125
}
92126

93127

0 commit comments

Comments
 (0)