|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Publish the ANGLE Swift package to xLightsSequencer/xLights-spm. |
| 4 | +# |
| 5 | +# Usage: submodules/spm/publish.sh <release|latest> |
| 6 | +# |
| 7 | +# release Stable channel (run from the tag-triggered release workflow). |
| 8 | +# Uses the per-tag release assets already attached by the release |
| 9 | +# step, generates Package.swift pointing at them, pushes to the |
| 10 | +# xLights-spm `main` branch and tags a semver derived from the deps |
| 11 | +# tag: xlights_2026.10 -> 2026.10.0. Consumers: from: "2026.10.0". |
| 12 | +# |
| 13 | +# latest Rolling channel (run from CI on every push to main). (Re)builds a |
| 14 | +# `latest` prerelease on this repo with SHA-stamped assets (a fresh |
| 15 | +# URL each commit, so GitHub's CDN can never serve stale bytes under |
| 16 | +# a reused URL), generates Package.swift pointing at them, and |
| 17 | +# force-pushes the xLights-spm `latest` branch. Consumers: |
| 18 | +# branch: "latest". |
| 19 | +# |
| 20 | +# Required env: |
| 21 | +# SPM_REPO_TOKEN token with Contents:read/write on xLights-spm |
| 22 | +# GH_TOKEN token for `gh` against THIS repo (latest channel only) |
| 23 | +# plus the standard GitHub Actions GITHUB_* variables. |
| 24 | +# |
| 25 | +# If SPM_REPO_TOKEN is absent the script no-ops with a notice (so forks / PRs |
| 26 | +# and unconfigured repos don't fail the build). |
| 27 | +set -e |
| 28 | + |
| 29 | +CHANNEL="${1:?usage: publish.sh <release|latest>}" |
| 30 | +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 31 | +BASE_DEPS_DIR=$( cd -- "${SCRIPT_DIR}/../.." &> /dev/null && pwd ) |
| 32 | +cd "${BASE_DEPS_DIR}" |
| 33 | + |
| 34 | +if [ -z "${SPM_REPO_TOKEN}" ]; then |
| 35 | + echo "::notice::SPM_REPO_TOKEN not set — skipping xLights-spm publish." |
| 36 | + exit 0 |
| 37 | +fi |
| 38 | + |
| 39 | +REPO_URL="https://github.com/${GITHUB_REPOSITORY}" |
| 40 | + |
| 41 | +case "${CHANNEL}" in |
| 42 | + release) |
| 43 | + SUFFIX="" |
| 44 | + ASSET_BASE="${REPO_URL}/releases/download/${GITHUB_REF_NAME}" |
| 45 | + SPM_VER="${GITHUB_REF_NAME#xlights_}.0" # xlights_2026.10 -> 2026.10.0 |
| 46 | + ;; |
| 47 | + latest) |
| 48 | + SHA="$(git rev-parse --short HEAD)" |
| 49 | + SUFFIX="-${SHA}" |
| 50 | + ASSET_BASE="${REPO_URL}/releases/download/latest" |
| 51 | + # Ensure the rolling prerelease exists, then clear its old assets. |
| 52 | + gh release create latest --prerelease --title "latest" \ |
| 53 | + --notes "Rolling latest build of the ANGLE Swift package." 2>/dev/null || true |
| 54 | + for a in $(gh release view latest --json assets -q '.assets[].name' 2>/dev/null); do |
| 55 | + gh release delete-asset latest "$a" -y 2>/dev/null || true |
| 56 | + done |
| 57 | + # SHA-stamped copies of the freshly built zips, then upload them. |
| 58 | + for FW in libEGL libGLESv2; do |
| 59 | + for v in macos ios; do |
| 60 | + cp "output/${FW}-${v}.xcframework.zip" "output/${FW}-${v}${SUFFIX}.xcframework.zip" |
| 61 | + done |
| 62 | + done |
| 63 | + gh release upload latest output/*"${SUFFIX}".xcframework.zip --clobber |
| 64 | + ;; |
| 65 | + *) echo "unknown channel: ${CHANNEL}" >&2; exit 1 ;; |
| 66 | +esac |
| 67 | + |
| 68 | +# Checksums of the (suffixed) zips consumers will actually download. |
| 69 | +sha() { swift package compute-checksum "output/$1${SUFFIX}.xcframework.zip"; } |
| 70 | +EGL_MAC_SHA=$(sha libEGL-macos) |
| 71 | +EGL_IOS_SHA=$(sha libEGL-ios) |
| 72 | +GLES_MAC_SHA=$(sha libGLESv2-macos) |
| 73 | +GLES_IOS_SHA=$(sha libGLESv2-ios) |
| 74 | + |
| 75 | +rm -rf spm-repo |
| 76 | +git clone --depth 1 "https://x-access-token:${SPM_REPO_TOKEN}@github.com/xLightsSequencer/xLights-spm.git" spm-repo |
| 77 | +cd spm-repo |
| 78 | + |
| 79 | +mkdir -p Sources/ANGLE/include |
| 80 | +rm -rf Sources/ANGLE/include/EGL Sources/ANGLE/include/GLES2 \ |
| 81 | + Sources/ANGLE/include/GLES3 Sources/ANGLE/include/KHR |
| 82 | +cp -R ../include/EGL ../include/GLES2 ../include/GLES3 ../include/KHR Sources/ANGLE/include/ |
| 83 | +[ -f Sources/ANGLE/shim.c ] || printf '// header-only umbrella target for ANGLE\n' > Sources/ANGLE/shim.c |
| 84 | +[ -f .gitignore ] || printf '.build/\n' > .gitignore |
| 85 | + |
| 86 | +sed -e "s|__ASSET_BASE__|${ASSET_BASE}|g" \ |
| 87 | + -e "s|__SUFFIX__|${SUFFIX}|g" \ |
| 88 | + -e "s|__LIBEGL_MACOS_SHA__|${EGL_MAC_SHA}|g" \ |
| 89 | + -e "s|__LIBEGL_IOS_SHA__|${EGL_IOS_SHA}|g" \ |
| 90 | + -e "s|__LIBGLESV2_MACOS_SHA__|${GLES_MAC_SHA}|g" \ |
| 91 | + -e "s|__LIBGLESV2_IOS_SHA__|${GLES_IOS_SHA}|g" \ |
| 92 | + ../submodules/spm/Package.swift.in > Package.swift |
| 93 | + |
| 94 | +git config user.name "github-actions[bot]" |
| 95 | +git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 96 | +git add -A |
| 97 | + |
| 98 | +if [ "${CHANNEL}" = "release" ]; then |
| 99 | + git commit -m "ANGLE ${SPM_VER} (from ${GITHUB_REF_NAME})" || echo "No changes to commit" |
| 100 | + git push origin HEAD:main |
| 101 | + git tag -f "${SPM_VER}" |
| 102 | + git push -f origin "${SPM_VER}" |
| 103 | + echo "::notice::Published xLights-spm ${SPM_VER}" |
| 104 | +else |
| 105 | + git checkout -B latest |
| 106 | + git commit -m "ANGLE latest (${GITHUB_SHA})" || echo "No changes to commit" |
| 107 | + git push -f origin latest |
| 108 | + echo "::notice::Published xLights-spm latest branch (${SHA})" |
| 109 | +fi |
0 commit comments