Skip to content

Commit 16c7e22

Browse files
CopilotCyl18
andcommitted
Add slug extraction to PR packer artifact naming
Co-authored-by: Cyl18 <14993992+Cyl18@users.noreply.github.com>
1 parent ff2addc commit 16c7e22

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

.github/workflows/pr-packer.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,46 @@ jobs:
101101
shell: bash
102102
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
103103

104+
- name: Extract slugs for ${{ matrix.version }}
105+
id: extract-slugs
106+
run: |
107+
# Get changed files for this version
108+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
109+
# For manual dispatch, get all files in the version
110+
changed_files=$(find projects/${{ matrix.version }}/assets -name "*.json" 2>/dev/null | head -20)
111+
else
112+
# For PR, get changed files compared to main branch
113+
changed_files=$(git diff --name-only origin/main...HEAD | grep "^projects/${{ matrix.version }}/assets/.*\.json$" || echo "")
114+
fi
115+
116+
# Extract slugs from paths like projects/{version}/assets/{SLUG}/{MOD_DOMAIN}/lang/en_us.json
117+
slugs=$(echo "$changed_files" | grep -E "^projects/${{ matrix.version }}/assets/[^/]+/[^/]+/lang/.*\.json$" | sed -E "s|^projects/${{ matrix.version }}/assets/([^/]+)/.*|\1|" | sort -u)
118+
119+
# Convert to array and limit to 3
120+
slug_array=()
121+
while IFS= read -r slug; do
122+
if [ -n "$slug" ]; then
123+
slug_array+=("$slug")
124+
fi
125+
done <<< "$slugs"
126+
127+
# Format slug suffix
128+
slug_suffix=""
129+
if [ ${#slug_array[@]} -eq 0 ]; then
130+
slug_suffix=""
131+
elif [ ${#slug_array[@]} -le 3 ]; then
132+
slug_suffix="-$(IFS=-; echo "${slug_array[*]}")"
133+
else
134+
slug_suffix="-${slug_array[0]}-${slug_array[1]}-${slug_array[2]}-etc"
135+
fi
136+
137+
echo "slug-suffix=$slug_suffix" >> $GITHUB_OUTPUT
138+
shell: bash
139+
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
140+
104141
- name: Upload Artifact for ${{ matrix.version }}
105142
uses: actions/upload-artifact@v4
106143
with:
107-
name: Minecraft-Mod-Language-Package-${{ matrix.version }}-PR${{ github.event.pull_request.number || 'manual' }}
144+
name: Minecraft-Mod-Language-Package-${{ matrix.version }}-PR${{ github.event.pull_request.number || 'manual' }}${{ steps.extract-slugs.outputs.slug-suffix }}
108145
path: Minecraft-Mod-Language-Package-${{ matrix.version }}/*
109146
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'

0 commit comments

Comments
 (0)