Skip to content

Commit 9db05d0

Browse files
committed
feat: consolidate exports to single location
1 parent 685032a commit 9db05d0

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/drawio-export.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ on:
3333
default: 'all'
3434
required: false
3535
type: string
36+
consolidate_exported_files_to_single_location:
37+
description: 'If true, all exported files will be consolidated to a single location at the root level (exports/png and exports/svg). If false, exported files will remain in their respective subdirectories.'
38+
default: false
39+
required: false
40+
type: boolean
3641
commit_user:
3742
description: 'Username which should be used for commits by github action'
3843
default: 'github-actions'
@@ -43,6 +48,7 @@ on:
4348
default: 'noreply@github.com'
4449
required: false
4550
type: string
51+
4652
secrets:
4753
GH_APP_ID:
4854
required: true
@@ -109,7 +115,51 @@ jobs:
109115
quality: 95
110116
uncompressed: true
111117

118+
- name: Consolidate exported files to root level
119+
if: ${{ inputs.consolidate_exported_files_to_single_location == true }}
120+
run: |
121+
#!/bin/bash
122+
123+
SEARCH_PATH="drawio"
124+
FINAL_EXPORTS_PATH="exports"
125+
126+
echo "Consolidating exported files into '${FINAL_EXPORTS_PATH}'..."
127+
128+
find "${SEARCH_PATH}" -type d -name "exports" | while read -r nested_dir; do
129+
# For a path like "drawio/subfolder/subsubfolder/exports", this gets the parent
130+
parent_dir=$(dirname "${nested_dir}")
131+
132+
# This extracts the full relative path from the search path,
133+
# e.g., "subfolder/subsubfolder"
134+
relative_path="${parent_dir#${SEARCH_PATH}/}"
135+
136+
echo "Processing exports from: ${relative_path}"
137+
138+
# --- Move PNG files ---
139+
if [ -d "${nested_dir}/png" ] && [ -n "$(ls -A "${nested_dir}/png")" ]; then
140+
# The destination now includes the full relative path
141+
final_png_dest="${FINAL_EXPORTS_PATH}/${relative_path}/png"
142+
sudo mkdir -p "${final_png_dest}"
143+
echo " -> Moving PNGs to ${final_png_dest}/"
144+
sudo mv "${nested_dir}/png"/* "${final_png_dest}/"
145+
fi
146+
147+
# --- Move SVG files ---
148+
if [ -d "${nested_dir}/svg" ] && [ -n "$(ls -A "${nested_dir}/svg")" ]; then
149+
final_svg_dest="${FINAL_EXPORTS_PATH}/${relative_path}/svg"
150+
sudo mkdir -p "${final_svg_dest}"
151+
echo " -> Moving SVGs to ${final_svg_dest}/"
152+
sudo mv "${nested_dir}/svg"/* "${final_svg_dest}/"
153+
fi
154+
155+
echo " -> Cleaning up ${nested_dir}"
156+
sudo rm -rf "${nested_dir}"
157+
done
158+
159+
echo "Consolidation complete!"
160+
112161
- name: Commit Changes
162+
id: commit_changes
113163
run: |
114164
git config --local user.name "${{ inputs.commit_user }}"
115165
git config --local user.email "${{ inputs.commit_email }}"
@@ -122,7 +172,8 @@ jobs:
122172
git diff-index --quiet HEAD || git commit -m "docs: sync draw.io exported files" -a
123173
124174
- name: Push Changes
175+
id: push_changes
125176
uses: ad-m/github-push-action@v0.8.0
126177
with:
127178
github_token: ${{ steps.github_app_token.outputs.token }}
128-
branch: ${{ github.ref }}
179+
branch: ${{ github.ref }}

0 commit comments

Comments
 (0)