|
| 1 | +name: "Generate board images" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +env: |
| 8 | + # Where board configs live in the armbian/build repo |
| 9 | + BOARDS_PATH: "build/config/boards" |
| 10 | + # Thumbnail sizes to generate (W) |
| 11 | + THUMB_WIDTHS: "100 150 272 300 360 480 768 960 1024 1920" |
| 12 | + # Number of shards to split boards across (avoid 256 matrix limit) |
| 13 | + SHARDS: 4 |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: board-images |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + |
| 21 | + Check: |
| 22 | + name: "Check permissions" |
| 23 | + runs-on: ubuntu-24.04 |
| 24 | + steps: |
| 25 | + - name: "Check permissions" |
| 26 | + uses: armbian/actions/team-check@main |
| 27 | + with: |
| 28 | + ORG_MEMBERS: ${{ secrets.ORG_MEMBERS }} |
| 29 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + TEAM: "Release manager" |
| 31 | + |
| 32 | + Boards-index: |
| 33 | + name: "Build boards matrix" |
| 34 | + runs-on: ubuntu-24.04 |
| 35 | + needs: Check |
| 36 | + outputs: |
| 37 | + matrix: ${{ steps.boards.outputs.JSON_CONTENT }} |
| 38 | + steps: |
| 39 | + |
| 40 | + - name: "Checkout armbian/build" |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + repository: armbian/build |
| 44 | + path: build |
| 45 | + |
| 46 | + - name: "Generate boards JSON matrix" |
| 47 | + id: boards |
| 48 | + run: | |
| 49 | + set -euo pipefail |
| 50 | +
|
| 51 | + cd "${BOARDS_PATH}" |
| 52 | +
|
| 53 | + # Find *.conf, *.csc, *.wip, *.tvb, strip extension, sort, and turn into JSON array |
| 54 | + boards=$(find . -maxdepth 1 -type f \ |
| 55 | + \( -name "*.conf" -o -name "*.csc" -o -name "*.wip" -o -name "*.tvb" \) \ |
| 56 | + -printf '%f\n' \ |
| 57 | + | sed -E 's/\.(conf|csc|wip|tvb)$//' \ |
| 58 | + | sort) |
| 59 | +
|
| 60 | + echo "Boards found:" |
| 61 | + printf '%s\n' "${boards}" |
| 62 | +
|
| 63 | + echo 'JSON_CONTENT<<EOF' >> "$GITHUB_OUTPUT" |
| 64 | + printf '%s\n' "${boards}" | jq -R . | jq -s . >> "$GITHUB_OUTPUT" |
| 65 | + echo 'EOF' >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + Generate-images: |
| 68 | + name: "Generate board images" |
| 69 | + runs-on: ubuntu-24.04 |
| 70 | + needs: Boards-index |
| 71 | + strategy: |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + # Small matrix over shards, not over boards (avoids 256-config limit) |
| 75 | + shard: [0, 1, 2, 3] |
| 76 | + |
| 77 | + env: |
| 78 | + BOARDS_JSON: ${{ needs.Boards-index.outputs.matrix }} |
| 79 | + |
| 80 | + steps: |
| 81 | + |
| 82 | + - name: "Checkout armbian.github.io" |
| 83 | + uses: actions/checkout@v4 |
| 84 | + with: |
| 85 | + fetch-depth: 0 |
| 86 | + |
| 87 | + - name: "Install SSH key" |
| 88 | + uses: shimataro/ssh-key-action@v2 |
| 89 | + with: |
| 90 | + key: "${{ secrets.KEY_UPLOAD }}" |
| 91 | + known_hosts: "${{ secrets.KNOWN_HOSTS_ARMBIAN_UPLOAD }}" |
| 92 | + if_key_exists: replace |
| 93 | + |
| 94 | + - name: "Install ImageMagick (robust)" |
| 95 | + run: | |
| 96 | + set -euo pipefail |
| 97 | + echo "Installing ImageMagick..." |
| 98 | + sudo apt-get update -y |
| 99 | + sudo apt-get install -y imagemagick pngquant |
| 100 | +
|
| 101 | + # Some distros rename convert → magick |
| 102 | + if ! command -v convert >/dev/null 2>&1; then |
| 103 | + if command -v magick >/dev/null 2>&1; then |
| 104 | + echo "convert not found, mapping 'magick convert' wrapper…" |
| 105 | + echo -e '#!/bin/bash\nexec magick convert "$@"' | sudo tee /usr/local/bin/convert >/dev/null |
| 106 | + sudo chmod +x /usr/local/bin/convert |
| 107 | + else |
| 108 | + echo "::error ::ImageMagick installation failed — 'convert' or 'magick' not found!" |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + fi |
| 112 | +
|
| 113 | + echo "ImageMagick installed successfully." |
| 114 | +
|
| 115 | + - name: "Process boards in shard ${{ matrix.shard }}" |
| 116 | + run: | |
| 117 | + set -euo pipefail |
| 118 | +
|
| 119 | + SHARD="${{ matrix.shard }}" |
| 120 | + SHARDS="${SHARDS}" |
| 121 | + WIDTHS="${THUMB_WIDTHS}" |
| 122 | +
|
| 123 | + echo "Shard: ${SHARD}/${SHARDS}" |
| 124 | + echo "Widths: ${WIDTHS}" |
| 125 | +
|
| 126 | + # Parse boards JSON into a simple newline list |
| 127 | + echo "${BOARDS_JSON}" | jq -r '.[]' > all-boards.txt |
| 128 | +
|
| 129 | + idx=0 |
| 130 | +
|
| 131 | + while IFS= read -r BOARD; do |
| 132 | + # Sharding: only process boards where idx % SHARDS == SHARD |
| 133 | + if (( idx % SHARDS != SHARD )); then |
| 134 | + idx=$((idx + 1)) |
| 135 | + continue |
| 136 | + fi |
| 137 | +
|
| 138 | + echo "==== [${idx}] Processing board: ${BOARD} on shard ${SHARD} ====" |
| 139 | +
|
| 140 | + # Find original board image (first match of <board>.png anywhere in repo) |
| 141 | + mapfile -t matches < <(find . -type f -iname "${BOARD}.png" | sort || true) |
| 142 | +
|
| 143 | + if [[ "${#matches[@]}" -eq 0 ]]; then |
| 144 | + echo "No image found for board: ${BOARD}" |
| 145 | +
|
| 146 | + { |
| 147 | + echo "## Missing board image" |
| 148 | + echo "" |
| 149 | + echo "- \`${BOARD}\`" |
| 150 | + echo "" |
| 151 | + } >> "$GITHUB_STEP_SUMMARY" |
| 152 | +
|
| 153 | + idx=$((idx + 1)) |
| 154 | + continue |
| 155 | + fi |
| 156 | +
|
| 157 | + ORIGINAL="${matches[0]}" |
| 158 | + echo "Using original image: ${ORIGINAL}" |
| 159 | +
|
| 160 | + # ORIGINAL size folder: images/original/<board>.png |
| 161 | + mkdir -p "output/images/original" |
| 162 | + cp --update=none -- "${ORIGINAL}" "output/images/original/${BOARD}.png" |
| 163 | +
|
| 164 | + echo "ImageMagick version:" |
| 165 | + convert -version || true |
| 166 | +
|
| 167 | + echo "Probing original image:" |
| 168 | + identify "${ORIGINAL}" || echo "identify failed for ${ORIGINAL}" >&2 |
| 169 | +
|
| 170 | + # THUMBNAILS: images/<WIDTH>/<BOARD>.png |
| 171 | + for width in ${WIDTHS}; do |
| 172 | + mkdir -p "output/images/${width}" |
| 173 | + OUT="output/images/${width}/${BOARD}.png" |
| 174 | + echo "Generating ${OUT}" |
| 175 | +
|
| 176 | + convert "${ORIGINAL}" \ |
| 177 | + -resize "${width}>" \ |
| 178 | + -strip \ |
| 179 | + -quality 90 \ |
| 180 | + "${OUT}" |
| 181 | +
|
| 182 | + # Optional but recommended, if you installed pngquant: |
| 183 | + pngquant --quality=65-85 --speed 1 --force --output "${OUT}" "${OUT}" |
| 184 | +
|
| 185 | + done |
| 186 | +
|
| 187 | + { |
| 188 | + echo "## Processed board image" |
| 189 | + echo "" |
| 190 | + echo "- \`${BOARD}\` → original + thumbnails generated" |
| 191 | + echo "" |
| 192 | + } >> "$GITHUB_STEP_SUMMARY" |
| 193 | +
|
| 194 | + idx=$((idx + 1)) |
| 195 | + done < all-boards.txt |
| 196 | +
|
| 197 | + - name: "Upload images to cache servers" |
| 198 | + run: | |
| 199 | + set -euo pipefail |
| 200 | +
|
| 201 | + # get cache servers and upload files under /images |
| 202 | + curl -sS \ |
| 203 | + -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \ |
| 204 | + -H "Accept: application/json; indent=4" \ |
| 205 | + "${{ secrets.NETBOX_API }}/virtualization/virtual-machines/?limit=500&name__empty=false&status=active" \ |
| 206 | + | jq '.results[] |
| 207 | + | select([.tags[].name] | index("cache")) |
| 208 | + | {id, name, custom_fields}' > servers.json |
| 209 | +
|
| 210 | + if [[ ! -s servers.json ]]; then |
| 211 | + echo "No cache servers returned from NetBox query, nothing to upload." |
| 212 | + exit 0 |
| 213 | + fi |
| 214 | +
|
| 215 | + for row in $(jq -r '@base64' servers.json); do |
| 216 | + _jq() { |
| 217 | + echo "${row}" | base64 --decode | jq -r "${1}" |
| 218 | + } |
| 219 | +
|
| 220 | + id=$(_jq '.id') |
| 221 | + name=$(_jq '.name') |
| 222 | + path=$(_jq '.custom_fields.path') |
| 223 | + port=$(_jq '.custom_fields.port') |
| 224 | + username=$(_jq '.custom_fields.username') |
| 225 | +
|
| 226 | + echo "Uploading images to ${username}@${name}:${path}/cache/images (VM ID: ${id})" |
| 227 | +
|
| 228 | + rsync -e "ssh -p ${port} -o StrictHostKeyChecking=accept-new" \ |
| 229 | + -rvP output/images/ "${username}@${name}:${path}/cache/images" |
| 230 | + done |
0 commit comments