Skip to content

Commit 640a367

Browse files
authored
Improvements
1 parent c4888dc commit 640a367

File tree

2 files changed

+106
-41
lines changed

2 files changed

+106
-41
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Auto Compress All Assets
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
trigger:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Auto Compress Models
14+
env:
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
run: |
17+
curl -X POST \
18+
-H "Accept: application/vnd.github+json" \
19+
-H "Authorization: Bearer $GH_TOKEN" \
20+
https://api.github.com/repos/${{ github.repository }}/actions/workflows/auto-zip-release.yml/dispatches \
21+
-d '{
22+
"ref": "main",
23+
"inputs": {
24+
"branch": "",
25+
"name": "items",
26+
"path_to_zip": "assets/minecraft/items"
27+
}
28+
}'
29+
- name: Auto Compress Models
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
curl -X POST \
34+
-H "Accept: application/vnd.github+json" \
35+
-H "Authorization: Bearer $GH_TOKEN" \
36+
https://api.github.com/repos/${{ github.repository }}/actions/workflows/auto-zip-release.yml/dispatches \
37+
-d '{
38+
"ref": "main",
39+
"inputs": {
40+
"branch": "",
41+
"name": "models",
42+
"path_to_zip": "assets/minecraft/models"
43+
}
44+
}'
45+
- name: Auto Compress Blockstates
46+
env:
47+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: |
49+
curl -X POST \
50+
-H "Accept: application/vnd.github+json" \
51+
-H "Authorization: Bearer $GH_TOKEN" \
52+
https://api.github.com/repos/${{ github.repository }}/actions/workflows/auto-zip-release.yml/dispatches \
53+
-d '{
54+
"ref": "main",
55+
"inputs": {
56+
"branch": "",
57+
"name": "blockstates",
58+
"path_to_zip": "assets/minecraft/blockstates"
59+
}
60+
}'
Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
name: Auto Zip Release for External Branches
1+
name: Compress Assets
22

33
on:
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
@@ -26,7 +24,7 @@ jobs:
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: |
@@ -73,7 +71,7 @@ jobs:
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
@@ -88,9 +86,12 @@ jobs:
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

Comments
 (0)