Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 119 additions & 3 deletions .github/workflows/drawio-export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ on:
default: "."
required: false
type: string
drawio_png_format_export_path:
description: 'Path where png files should be exported (relative to drawio_path)'
type: string
required: false
default: "export"
drawio_svg_format_export_path:
description: 'Path where svg files should be exported (relative to drawio_path). If empty, no svg files will be exported.'
default: "export/svg"
required: false
type: string
drawio_export_as_png:
description: 'Export drawio files as png'
default: true
required: false
type: boolean
drawio_export_as_svg:
description: 'Export drawio files as svg'
default: false
required: false
type: boolean
drawio_action_mode:
description: 'Action mode to use for drawio-export-action (default: "all")'
default: 'all'
required: false
type: string
consolidate_exported_files_to_single_location:
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.'
default: false
required: false
type: boolean
commit_user:
description: 'Username which should be used for commits by github action'
default: 'github-actions'
Expand All @@ -19,6 +49,12 @@ on:
required: false
type: string

secrets:
GH_APP_ID:
required: true
GH_APP_PRIVATE_KEY:
required: true

concurrency:
group: drawio-export-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -27,25 +63,104 @@ jobs:
drawio-export:
runs-on: ubuntu-latest
steps:
- name: Make Sure Required 'GH_APP_ID' and 'GH_APP_PRIVATE_KEY' Secrets are Available
shell: bash
run: |
if [[ -z "${{ secrets.GH_APP_ID }}" || -z "${{ secrets.GH_APP_PRIVATE_KEY }}" ]]; then
echo "Error: Required secrets 'GH_APP_ID' and 'GH_APP_PRIVATE_KEY' are not set."
exit 1
fi

- name: Get Github Access Token
id: github_app_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
# if owner and repositories are empty, access will be scoped to only the current repository
owner: ''
repositories: ''

- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ steps.github_app_token.outputs.token }}

- name: Export drawio files to asciidoctor and png files
uses: rlespinasse/drawio-export-action@v2
if: ${{ inputs.drawio_export_as_png == true }}
with:
path: ${{ inputs.drawio_path }}
output: ${{ inputs.drawio_png_format_export_path }}
format: png
transparent: false
action-mode: all
action-mode: ${{ inputs.drawio_action_mode }}
remove-page-suffix: true
scale: 2
quality: 95
uncompressed: true

- name: Export drawio files to svg files
uses: rlespinasse/drawio-export-action@v2
if: ${{ inputs.drawio_export_as_svg == true }}
with:
path: ${{ inputs.drawio_path }}
output: ${{ inputs.drawio_svg_format_export_path }}
format: svg
transparent: false
action-mode: ${{ inputs.drawio_action_mode }}
remove-page-suffix: true
scale: 2
quality: 95
uncompressed: true

- name: Consolidate exported files to root level
if: ${{ inputs.consolidate_exported_files_to_single_location == true }}
run: |
#!/bin/bash

SEARCH_PATH="drawio"
FINAL_EXPORTS_PATH="exports"
mkdir -p "${FINAL_EXPORTS_PATH}"

echo "Consolidating exported files into '${FINAL_EXPORTS_PATH}'..."

find "${SEARCH_PATH}" -type d -name "exports" | while read -r nested_dir; do
# For a path like "drawio/subfolder/subsubfolder/exports", this gets the parent
parent_dir=$(dirname "${nested_dir}")

# This extracts the full relative path from the search path,
# e.g., "subfolder/subsubfolder"
relative_path="${parent_dir#${SEARCH_PATH}/}"

echo "Processing exports from: ${relative_path}"

# --- Move PNG files ---
if [ -d "${nested_dir}/png" ] && [ -n "$(ls -A "${nested_dir}/png")" ]; then
# The destination now includes the full relative path
final_png_dest="${FINAL_EXPORTS_PATH}/${relative_path}/png"
sudo mkdir -p "${final_png_dest}"
echo " -> Moving PNGs to ${final_png_dest}/"
sudo mv "${nested_dir}/png"/* "${final_png_dest}/"
fi

# --- Move SVG files ---
if [ -d "${nested_dir}/svg" ] && [ -n "$(ls -A "${nested_dir}/svg")" ]; then
final_svg_dest="${FINAL_EXPORTS_PATH}/${relative_path}/svg"
sudo mkdir -p "${final_svg_dest}"
echo " -> Moving SVGs to ${final_svg_dest}/"
sudo mv "${nested_dir}/svg"/* "${final_svg_dest}/"
fi

echo " -> Cleaning up ${nested_dir}"
sudo rm -rf "${nested_dir}"
done

echo "Consolidation complete!"

- name: Commit Changes
id: commit_changes
run: |
git config --local user.name "${{ inputs.commit_user }}"
git config --local user.email "${{ inputs.commit_email }}"
Expand All @@ -58,7 +173,8 @@ jobs:
git diff-index --quiet HEAD || git commit -m "docs: sync draw.io exported files" -a

- name: Push Changes
id: push_changes
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ steps.github_app_token.outputs.token }}
branch: ${{ github.ref }}
branch: ${{ github.ref }}