1- name : Auto Zip Release for External Branches
1+ name : Compress Assets
22
33on :
4- schedule :
5- - cron : " 0 0 * * *"
64 workflow_dispatch :
75 inputs :
86 branch :
97 description : " Specific branch name to process"
108 required : false
119 default : " "
12- tag_suffix :
13- description : " Suffix for the release tag "
14- required : false
15- default : " - models"
10+ name :
11+ description : " Base name for tag suffix and zip file "
12+ required : true
13+ default : " models"
1614 path_to_zip :
1715 description : " Path inside the repo to include in ZIP (e.g., assets/minecraft/models)"
1816 required : false
2624 - name : Checkout this repository
2725 uses : actions/checkout@v4
2826
29- # Fetch branch list if no specific branch
27+ # Fetch all branches if no specific branch
3028 - name : Fetch all branches from the remote repository
3129 if : ${{ github.event.inputs.branch == '' }}
3230 run : |
7371 exit 0
7472
7573 - name : Create output folder
76- run : mkdir zips
74+ run : mkdir -p zips
7775
7876 # Prepare list of branches to process
7977 - name : Prepare branch list to process
8886 - name : Process each branch
8987 env :
9088 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91- TAG_SUFFIX : ${{ github.event.inputs.tag_suffix }}
89+ NAME : ${{ github.event.inputs.name }}
9290 PATH_TO_ZIP : ${{ github.event.inputs.path_to_zip }}
9391 run : |
92+ TAG_SUFFIX="-$NAME"
93+ ZIP_NAME="$NAME.zip"
94+
9495 while read -r branch; do
9596 if [ -z "$branch" ]; then
9697 continue
@@ -102,29 +103,17 @@ jobs:
102103 echo "========= Processing branch: $branch ========="
103104 echo "Release tag: $TAG"
104105 echo "Path to zip: $PATH_TO_ZIP"
106+ echo "Zip file name: $ZIP_NAME"
105107
106- # Check if release exists
107- RELEASE_INFO=$(curl -s -H "Accept: application/vnd.github+json" \
108- -H "Authorization: token $GH_TOKEN" \
109- https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG)
110-
111- RELEASE_ID=$(echo "$RELEASE_INFO" | jq -r '.id // empty')
112-
113- if [ -n "$RELEASE_ID" ]; then
114- echo "Release with tag '$TAG' already exists. Skipping."
115- continue
116- fi
117-
118- # Clone repo
119108 echo "Cloning branch..."
120109 git clone --depth 1 --branch "$branch" \
121110 https://github.com/InventivetalentDev/minecraft-assets.git \
122111 "tmp-$branch"
123112
124113 if [ -d "tmp-$branch/$PATH_TO_ZIP" ]; then
125114 echo "Creating ZIP archive..."
126- (cd "tmp-$branch" && zip -r "../zips/archive.zip " "$PATH_TO_ZIP")
127- echo "ZIP created: zips/archive.zip "
115+ (cd "tmp-$branch" && zip -r "../zips/$ZIP_NAME " "$PATH_TO_ZIP")
116+ echo "ZIP created: zips/$ZIP_NAME "
128117 else
129118 echo "Directory '$PATH_TO_ZIP' not found in branch $branch. Skipping."
130119 rm -rf "tmp-$branch"
@@ -133,30 +122,46 @@ jobs:
133122
134123 rm -rf "tmp-$branch"
135124
136- # Create release
137- echo "Creating release with tag '$TAG'..."
138- RELEASE_RESPONSE=$(curl -s -X POST \
139- -H "Accept: application/vnd.github+json" \
125+ RELEASE_INFO=$(curl -s -H "Accept: application/vnd.github+json" \
140126 -H "Authorization: token $GH_TOKEN" \
141- https://api.github.com/repos/${{ github.repository }}/releases \
142- -d "{\"tag_name\":\"$TAG\",\"name\":\"Models for $branch\",\"body\":\"Auto-generated release for branch $branch.\",\"draft\":false,\"prerelease\":false}")
143-
144- UPLOAD_URL=$(echo "$RELEASE_RESPONSE" | jq -r '.upload_url' | sed 's/{?name,label}//')
127+ https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG)
145128
146- if [ -z "$UPLOAD_URL" ] || [ "$UPLOAD_URL" = "null" ]; then
147- echo "ERROR: Failed to create release for branch $branch"
148- echo "$RELEASE_RESPONSE"
149- continue
129+ RELEASE_ID=$(echo "$RELEASE_INFO" | jq -r '.id // empty')
130+ UPLOAD_URL=$(echo "$RELEASE_INFO" | jq -r '.upload_url' | sed 's/{?name,label}//')
131+
132+ if [ -z "$RELEASE_ID" ]; then
133+ echo "Release with tag '$TAG' not found, creating..."
134+ RELEASE_RESPONSE=$(curl -s -X POST \
135+ -H "Accept: application/vnd.github+json" \
136+ -H "Authorization: token $GH_TOKEN" \
137+ https://api.github.com/repos/${{ github.repository }}/releases \
138+ -d "{\"tag_name\":\"$TAG\",\"name\":\"Models for $branch\",\"body\":\"Auto-generated release for branch $branch.\",\"draft\":false,\"prerelease\":false}")
139+
140+ RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id // empty')
141+ UPLOAD_URL=$(echo "$RELEASE_RESPONSE" | jq -r '.upload_url' | sed 's/{?name,label}//')
142+
143+ if [ -z "$RELEASE_ID" ]; then
144+ echo "ERROR: Failed to create release for branch $branch"
145+ echo "$RELEASE_RESPONSE"
146+ continue
147+ fi
148+ else
149+ echo "Release with tag '$TAG' found, attaching asset..."
150+ ASSETS=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $GH_TOKEN" https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets)
151+ ASSET_ID=$(echo "$ASSETS" | jq -r ".[] | select(.name==\"$ZIP_NAME\") | .id // empty")
152+ if [ -n "$ASSET_ID" ]; then
153+ echo "Deleting existing asset $ZIP_NAME with id $ASSET_ID"
154+ curl -s -X DELETE -H "Authorization: token $GH_TOKEN" https://api.github.com/repos/${{ github.repository }}/releases/assets/$ASSET_ID
155+ fi
150156 fi
151157
152- # Upload ZIP
153158 echo "Uploading ZIP..."
154159 curl -s -X POST \
155160 -H "Authorization: token $GH_TOKEN" \
156161 -H "Content-Type: application/zip" \
157- --data-binary @"zips/archive.zip " \
158- "$UPLOAD_URL?name=archive.zip "
162+ --data-binary @"zips/$ZIP_NAME " \
163+ "$UPLOAD_URL?name=$ZIP_NAME "
159164
160- echo "Release created successfully for branch $branch."
165+ echo "Release processed successfully for branch $branch."
161166 echo "-----------------------------------"
162167 done < branches_to_process.txt
0 commit comments