|
| 1 | +name: "Release Web" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: [ "*" ] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: release-web-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-wasm: |
| 16 | + if: github.repository == 'AlpineMapsOrg/renderer' |
| 17 | + runs-on: ubuntu-24.04 |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Install dependencies |
| 21 | + run: | |
| 22 | + sudo apt-get update |
| 23 | + sudo apt-get install -y build-essential ccache ninja-build |
| 24 | +
|
| 25 | + - uses: actions/checkout@v7 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + fetch-tags: true |
| 29 | + |
| 30 | + - name: Load CI versions |
| 31 | + run: cat .github/ci-versions.env >> "$GITHUB_ENV" |
| 32 | + |
| 33 | + - uses: mymindstorm/setup-emsdk@v15 |
| 34 | + with: |
| 35 | + version: ${{ env.WEBASSEMBLY_VERSION }} |
| 36 | + actions-cache-folder: emsdk-cache |
| 37 | + cache-key: emsdk-${{ runner.os }}-${{ env.WEBASSEMBLY_VERSION }} |
| 38 | + |
| 39 | + - name: Use stable Emscripten path |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + STABLE_EMSDK_ROOT="${{ github.workspace }}/emsdk-cache/emsdk-main" |
| 43 | + if [ ! -x "$STABLE_EMSDK_ROOT/emsdk" ]; then |
| 44 | + echo "Expected emsdk at $STABLE_EMSDK_ROOT/emsdk" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + "$STABLE_EMSDK_ROOT/emsdk" activate "$WEBASSEMBLY_VERSION" |
| 49 | + "$STABLE_EMSDK_ROOT/emsdk" construct_env | while IFS= read -r line; do |
| 50 | + case "$line" in |
| 51 | + "PATH += "*) |
| 52 | + echo "${line#PATH += }" >> "$GITHUB_PATH" |
| 53 | + ;; |
| 54 | + *" = "*) |
| 55 | + name="${line%% = *}" |
| 56 | + value="${line#* = }" |
| 57 | + echo "$name=$value" >> "$GITHUB_ENV" |
| 58 | + ;; |
| 59 | + esac |
| 60 | + done |
| 61 | +
|
| 62 | + - name: Install Qt native version |
| 63 | + uses: jurplel/install-qt-action@v4 |
| 64 | + with: |
| 65 | + version: ${{ env.QT_VERSION }} |
| 66 | + host: linux |
| 67 | + target: desktop |
| 68 | + arch: linux_gcc_64 |
| 69 | + dir: '${{ github.workspace }}/qt_host' |
| 70 | + install-deps: 'true' |
| 71 | + modules: qtshadertools |
| 72 | + cache: true |
| 73 | + tools: tools_cmake |
| 74 | + |
| 75 | + - name: Set reusable strings |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + echo "BUILD_DIR=${{ github.workspace }}/build" >> "$GITHUB_ENV" |
| 79 | + echo "INSTALL_DIR=${{ github.workspace }}/install/wasm_mt_lto" >> "$GITHUB_ENV" |
| 80 | + echo "QT_WASM_ROOT_DIR=${{ github.workspace }}/qt_wasm_lite" >> "$GITHUB_ENV" |
| 81 | + echo "QT_SRC_CONFIGURE=${{ github.workspace }}/qt_src/configure" >> "$GITHUB_ENV" |
| 82 | + echo "QT_LITE_CONFIG=${{ github.workspace }}/misc/qt_lite.txt" >> "$GITHUB_ENV" |
| 83 | +
|
| 84 | + - name: Cache Qt WebAssembly build |
| 85 | + id: qt-cache |
| 86 | + uses: actions/cache@v6 |
| 87 | + with: |
| 88 | + path: qt_wasm_lite |
| 89 | + key: wasm_mt_lto_qt-${{ env.QT_VERSION }}_emcc-${{ env.WEBASSEMBLY_VERSION }}_qtpositioning_${{ hashFiles('misc/qt_lite.txt', 'misc/qt_68_qtbase_remove_dejavu_fonts.patch') }} |
| 90 | + |
| 91 | + - name: Download and patch Qt |
| 92 | + if: steps.qt-cache.outputs.cache-hit != 'true' |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + git clone --branch "$QT_VERSION" git://code.qt.io/qt/qt5.git qt_src |
| 96 | + mkdir qt_wasm_build |
| 97 | + cd qt_wasm_build |
| 98 | + "$QT_SRC_CONFIGURE" -qt-host-path "$QT_ROOT_DIR" -platform wasm-emscripten -init-submodules -submodules qtdeclarative,qtbase,qtpositioning -skip qtlanguageserver,qtquicktimeline,qtimageformats |
| 99 | + cd "${{ github.workspace }}/qt_src/qtbase" |
| 100 | + git apply "${{ github.workspace }}/misc/qt_68_qtbase_remove_dejavu_fonts.patch" |
| 101 | + cd "${{ github.workspace }}" |
| 102 | + rm -rf qt_wasm_build |
| 103 | + mkdir qt_wasm_build |
| 104 | +
|
| 105 | + - name: Build Qt for WebAssembly |
| 106 | + if: steps.qt-cache.outputs.cache-hit != 'true' |
| 107 | + shell: bash |
| 108 | + run: | |
| 109 | + cd qt_wasm_build |
| 110 | + "$QT_SRC_CONFIGURE" \ |
| 111 | + -qt-host-path "$QT_ROOT_DIR" \ |
| 112 | + -platform wasm-emscripten \ |
| 113 | + -release \ |
| 114 | + -optimize-size \ |
| 115 | + -submodules qtdeclarative,qtbase,qtpositioning \ |
| 116 | + -skip qtlanguageserver,qtquicktimeline,qtimageformats \ |
| 117 | + -gui \ |
| 118 | + -ltcg \ |
| 119 | + $(cat "$QT_LITE_CONFIG") \ |
| 120 | + -feature-thread \ |
| 121 | + -prefix "$QT_WASM_ROOT_DIR/" |
| 122 | + # Work around https://bugreports.qt.io/browse/QTBUG-129522. |
| 123 | + sed -i 's/-flto=thin/-flto/g' ./build.ninja |
| 124 | + cmake --build . --parallel |
| 125 | + cmake --install . |
| 126 | + test -d "$QT_WASM_ROOT_DIR" |
| 127 | + test -n "$(ls -A "$QT_WASM_ROOT_DIR")" |
| 128 | +
|
| 129 | + - name: Remove StatsWindow |
| 130 | + run: rm ./app/StatsWindow.qml |
| 131 | + |
| 132 | + - name: Set ccache config |
| 133 | + shell: bash |
| 134 | + run: | |
| 135 | + echo "CCACHE_DIR=${{ github.workspace }}/.ccache" >> "$GITHUB_ENV" |
| 136 | + echo "CCACHE_BASEDIR=${{ github.workspace }}" >> "$GITHUB_ENV" |
| 137 | + echo "CCACHE_COMPRESS=true" >> "$GITHUB_ENV" |
| 138 | + echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV" |
| 139 | + echo "CCACHE_MAXSIZE=500M" >> "$GITHUB_ENV" |
| 140 | +
|
| 141 | + - name: Cache ccache |
| 142 | + uses: actions/cache@v6 |
| 143 | + with: |
| 144 | + path: ${{ github.workspace }}/.ccache |
| 145 | + key: ccache-${{ runner.os }}-wasm_mt_lto-emscripten-${{ env.WEBASSEMBLY_VERSION }}-qt-${{ env.QT_VERSION }}-v3-${{ github.run_id }}-${{ github.run_attempt }} |
| 146 | + restore-keys: | |
| 147 | + ccache-${{ runner.os }}-wasm_mt_lto-emscripten-${{ env.WEBASSEMBLY_VERSION }}-qt-${{ env.QT_VERSION }}-v3- |
| 148 | +
|
| 149 | + - name: Configure AlpineApp |
| 150 | + run: | |
| 151 | + "$QT_WASM_ROOT_DIR/bin/qt-cmake" \ |
| 152 | + -G Ninja \ |
| 153 | + -B "$BUILD_DIR" \ |
| 154 | + -DCMAKE_BUILD_TYPE=MinSizeRel \ |
| 155 | + -DALP_WWW_INSTALL_DIR="$INSTALL_DIR" \ |
| 156 | + -DALP_ENABLE_THREADING=ON \ |
| 157 | + -DALP_ENABLE_ASSERTS=OFF \ |
| 158 | + -DALP_ENABLE_LTO=ON \ |
| 159 | + -DALP_BUILD_UNITTESTS=OFF \ |
| 160 | + -DALP_BUILD_PLAIN_RENDERER=OFF \ |
| 161 | + -DALP_BUILD_ALPINEAPP=ON \ |
| 162 | + -DALP_BUILD_WEBGPU_BASE=OFF \ |
| 163 | + -DALP_BUILD_WEBGPU_ENGINE=OFF \ |
| 164 | + -DALP_BUILD_WEBGPU_COMPUTE=OFF \ |
| 165 | + -DALP_BUILD_WEBGPU_APP=OFF \ |
| 166 | + -DFMT_INSTALL=OFF \ |
| 167 | + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ |
| 168 | + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ |
| 169 | + -S "${{ github.workspace }}" |
| 170 | +
|
| 171 | + - name: Reset ccache stats |
| 172 | + run: ccache --zero-stats |
| 173 | + |
| 174 | + - name: Build AlpineApp |
| 175 | + run: cmake --build "$BUILD_DIR" --target install |
| 176 | + |
| 177 | + - name: Show ccache stats |
| 178 | + if: always() |
| 179 | + run: ccache --show-stats --verbose |
| 180 | + |
| 181 | + - name: Stage release |
| 182 | + shell: bash |
| 183 | + run: | |
| 184 | + APP_DIR="$INSTALL_DIR/alpineapp" |
| 185 | + test -f "$APP_DIR/alpineapp.html" |
| 186 | + test -f "$APP_DIR/alpineapp.js" |
| 187 | + test -f "$APP_DIR/alpineapp.wasm" |
| 188 | + test -f "$APP_DIR/alpineapp.worker.js" |
| 189 | + test -f "$APP_DIR/qtloader.js" |
| 190 | + test -f "$APP_DIR/logo_vertical_light_bg.png" |
| 191 | +
|
| 192 | + mkdir "${{ github.workspace }}/release" |
| 193 | + cp -a "$APP_DIR/." "${{ github.workspace }}/release/" |
| 194 | + mv "${{ github.workspace }}/release/alpineapp.html" "${{ github.workspace }}/release/index.html" |
| 195 | +
|
| 196 | + - name: Create release artifact |
| 197 | + uses: actions/upload-artifact@v7 |
| 198 | + with: |
| 199 | + name: release_web |
| 200 | + path: ${{ github.workspace }}/release/ |
| 201 | + if-no-files-found: error |
| 202 | + |
| 203 | + deploy: |
| 204 | + if: github.repository == 'AlpineMapsOrg/renderer' |
| 205 | + needs: build-wasm |
| 206 | + runs-on: ubuntu-latest |
| 207 | + |
| 208 | + steps: |
| 209 | + - name: Install lftp |
| 210 | + run: | |
| 211 | + sudo apt-get update |
| 212 | + sudo apt-get install -y lftp |
| 213 | +
|
| 214 | + - name: Download release artifact |
| 215 | + uses: actions/download-artifact@v8 |
| 216 | + with: |
| 217 | + name: release_web |
| 218 | + path: ${{ github.workspace }}/release |
| 219 | + |
| 220 | + - name: Deploy to alpinemaps.org |
| 221 | + shell: bash |
| 222 | + env: |
| 223 | + FTP_RELEASE_HOST: ${{ secrets.FTP_RELEASE_HOST }} |
| 224 | + FTP_RELEASE_USER: ${{ secrets.FTP_RELEASE_USER }} |
| 225 | + FTP_RELEASE_PASS: ${{ secrets.FTP_RELEASE_PASS }} |
| 226 | + run: | |
| 227 | + set -euo pipefail |
| 228 | +
|
| 229 | + for name in FTP_RELEASE_HOST FTP_RELEASE_USER FTP_RELEASE_PASS; do |
| 230 | + if [ -z "${!name}" ]; then |
| 231 | + echo "$name is required for the release deployment." |
| 232 | + exit 1 |
| 233 | + fi |
| 234 | + done |
| 235 | +
|
| 236 | + RELEASE_DIR="${{ github.workspace }}/release" |
| 237 | + test -f "$RELEASE_DIR/index.html" |
| 238 | + test ! -e "$RELEASE_DIR/alpineapp.html" |
| 239 | + test ! -e "$RELEASE_DIR/coi-serviceworker.min.js" |
| 240 | +
|
| 241 | + lftp <<LFTP |
| 242 | + set cmd:fail-exit true |
| 243 | + set ftp:ssl-force true |
| 244 | + set ftp:ssl-protect-data true |
| 245 | + set ssl:verify-certificate true |
| 246 | + open -u "$FTP_RELEASE_USER","$FTP_RELEASE_PASS" "$FTP_RELEASE_HOST" |
| 247 | + mirror --reverse --delete --verbose "$RELEASE_DIR" .release-new |
| 248 | + bye |
| 249 | + LFTP |
| 250 | +
|
| 251 | + lftp > "${{ runner.temp }}/release-root-entries" <<LFTP |
| 252 | + set cmd:fail-exit true |
| 253 | + set ftp:ssl-force true |
| 254 | + set ftp:ssl-protect-data true |
| 255 | + set ssl:verify-certificate true |
| 256 | + open -u "$FTP_RELEASE_USER","$FTP_RELEASE_PASS" "$FTP_RELEASE_HOST" |
| 257 | + find -d 2 . |
| 258 | + bye |
| 259 | + LFTP |
| 260 | +
|
| 261 | + ROTATE_SCRIPT="${{ runner.temp }}/rotate-release.lftp" |
| 262 | + { |
| 263 | + echo "rm -rf old" |
| 264 | + echo "mkdir old" |
| 265 | +
|
| 266 | + while IFS= read -r entry; do |
| 267 | + entry="${entry#./}" |
| 268 | + entry="${entry%/}" |
| 269 | + case "$entry" in |
| 270 | + ""|"."|".."|"old"|".release-new") |
| 271 | + continue |
| 272 | + ;; |
| 273 | + esac |
| 274 | +
|
| 275 | + escaped="${entry//\\/\\\\}" |
| 276 | + escaped="${escaped//\"/\\\"}" |
| 277 | + escaped="${escaped//\$/\\\$}" |
| 278 | + escaped="${escaped//\`/\\\`}" |
| 279 | + printf 'mv "%s" old/\n' "$escaped" |
| 280 | + done < "${{ runner.temp }}/release-root-entries" |
| 281 | +
|
| 282 | + shopt -s dotglob nullglob |
| 283 | + for path in "$RELEASE_DIR"/*; do |
| 284 | + entry="${path##*/}" |
| 285 | + escaped="${entry//\\/\\\\}" |
| 286 | + escaped="${escaped//\"/\\\"}" |
| 287 | + escaped="${escaped//\$/\\\$}" |
| 288 | + escaped="${escaped//\`/\\\`}" |
| 289 | + printf 'mv ".release-new/%s" ./\n' "$escaped" |
| 290 | + done |
| 291 | +
|
| 292 | + echo "rmdir .release-new" |
| 293 | + echo "bye" |
| 294 | + } > "$ROTATE_SCRIPT" |
| 295 | +
|
| 296 | + { |
| 297 | + echo "set cmd:fail-exit true" |
| 298 | + echo "set ftp:ssl-force true" |
| 299 | + echo "set ftp:ssl-protect-data true" |
| 300 | + echo "set ssl:verify-certificate true" |
| 301 | + echo "open -u \"$FTP_RELEASE_USER\",\"$FTP_RELEASE_PASS\" \"$FTP_RELEASE_HOST\"" |
| 302 | + cat "$ROTATE_SCRIPT" |
| 303 | + } | lftp |
0 commit comments