diff --git a/.github/workflows/sync_device_svgs.yml b/.github/workflows/sync_device_svgs.yml index e1a1fd947..0fa5cea54 100644 --- a/.github/workflows/sync_device_svgs.yml +++ b/.github/workflows/sync_device_svgs.yml @@ -7,155 +7,72 @@ on: workflow_dispatch: # Allow manual triggering +# Needed so the scheduled run can commit the refreshed catalog back to the repo. +permissions: + contents: write + jobs: sync-device-svgs: runs-on: ubuntu-latest - + steps: - name: Checkout repository uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup Node.js - uses: actions/setup-node@v4 + + - name: Set up Python + uses: actions/setup-python@v5 with: - node-version: '18' - - - name: Install dependencies - run: | - npm install -g svgo - - - name: Download and process SVGs - run: | - #!/bin/bash - set -e - - # Create temporary directory - mkdir -p temp_svgs - cd temp_svgs - - # Clone web-flasher repo (shallow clone for speed) - git clone --depth 1 https://github.com/meshtastic/web-flasher.git - - # Navigate to SVG directory - cd web-flasher/public/img/devices - - # Create output directory - mkdir -p ../../../../processed_svgs - - # Process each SVG file - for svg_file in *.svg; do - if [ -f "$svg_file" ]; then - # Get filename without extension - filename=$(basename "$svg_file" .svg) - - # Optimize SVG - svgo "$svg_file" --output "../../../../processed_svgs/${filename}.svg" - - echo "Processed: $filename" - fi - done - - cd ../../../../ - ls -la processed_svgs/ - - - name: Update Xcode Assets + python-version: '3.11' + + - name: Sync device images and hardware catalog + # Reuse the exact script the Xcode "Download Node SVG Images" build phase runs, + # writing to the bundled resource location the app actually loads at runtime + # (the Bundle "images" subdirectory + DeviceHardware.json — see MeshtasticAPI). + # --force ignores the cached API hash so the committed snapshot always matches + # the upstream device hardware API instead of drifting until someone clean-builds. run: | - #!/bin/bash - set -e - - ASSETS_DIR="Meshtastic/Assets.xcassets" - - # Ensure assets directory exists - mkdir -p "$ASSETS_DIR" - - # Process each SVG - for svg_file in processed_svgs/*.svg; do - if [ -f "$svg_file" ]; then - # Get filename without extension - filename=$(basename "$svg_file" .svg) - - # Create imageset directory - imageset_dir="${ASSETS_DIR}/${filename}.imageset" - mkdir -p "$imageset_dir" - - # Copy SVG to imageset - cp "$svg_file" "${imageset_dir}/${filename}.svg" - - # Create Contents.json for the imageset - cat > "${imageset_dir}/Contents.json" << EOF - { - "images" : [ - { - "filename" : "${filename}.svg", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } - } - EOF - - echo "Created imageset: ${filename}" - fi - done - + python3 scripts/download_images.py \ + --output-dir "Meshtastic/Resources/images" \ + --output-json "Meshtastic/Resources/DeviceHardware.json" \ + --force \ + --verbose + - name: Check for changes id: check_changes run: | - if git diff --quiet; then - echo "has_changes=false" >> $GITHUB_OUTPUT + if [ -z "$(git status --porcelain Meshtastic/Resources/images Meshtastic/Resources/DeviceHardware.json)" ]; then + echo "has_changes=false" >> "$GITHUB_OUTPUT" else - echo "has_changes=true" >> $GITHUB_OUTPUT + echo "has_changes=true" >> "$GITHUB_OUTPUT" fi - + - name: Commit and push changes if: steps.check_changes.outputs.has_changes == 'true' + env: + # actions/checkout leaves a detached HEAD, so push HEAD explicitly to the + # branch. Read the ref through env (not inline ${{ }}) to avoid expanding a + # GitHub expression inside the shell. + TARGET_BRANCH: ${{ github.ref_name }} run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git add Meshtastic/Assets.xcassets/ - git commit -m "🤖 Sync device SVGs from web-flasher repo - - - Updated device images from meshtastic/web-flasher - - Automatically synced on $(date -u) - - Source: https://github.com/meshtastic/web-flasher/tree/main/public/img/devices" - git push - - - name: Create PR (alternative to direct push) - if: steps.check_changes.outputs.has_changes == 'true' && false # Set to true if you prefer PRs - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: "🤖 Sync device SVGs from web-flasher repo" - title: "Sync device SVGs from web-flasher" - body: | - This PR automatically syncs device SVG images from the [meshtastic/web-flasher](https://github.com/meshtastic/web-flasher) repository. - - **Changes:** - - Updated device images from web-flasher repo - - Source: https://github.com/meshtastic/web-flasher/tree/main/public/img/devices - - Automatically generated on $(date -u) - - The SVGs have been optimized and converted to Xcode asset format. - branch: sync-device-svgs - delete-branch: true - - - name: Cleanup - if: always() - run: | - rm -rf temp_svgs processed_svgs - + # -A stages new device SVGs, updated ones, and any pruned (removed) devices. + git add -A Meshtastic/Resources/images Meshtastic/Resources/DeviceHardware.json + git commit -m "🤖 Sync device images and hardware catalog + + - Refreshed from https://api.meshtastic.org/resource/deviceHardware + - Bundled resources: Meshtastic/Resources/images + DeviceHardware.json + - Automatically synced on $(date -u)" + git push origin "HEAD:${TARGET_BRANCH}" + - name: Summary + env: + HAS_CHANGES: ${{ steps.check_changes.outputs.has_changes }} run: | - if [ "${{ steps.check_changes.outputs.has_changes }}" == "true" ]; then - echo "✅ Device SVGs updated successfully" + if [ "$HAS_CHANGES" == "true" ]; then + echo "✅ Device images and hardware catalog updated" else - echo "â„šī¸ No changes detected - SVGs are up to date" - fi \ No newline at end of file + echo "â„šī¸ No changes detected - resources are up to date" + fi