Skip to content

Commit

Permalink
Retry if create-dmg fails
Browse files Browse the repository at this point in the history
we get random errors due to hdiutil resource busy problems (not our fault)
  • Loading branch information
m-kuhn committed Jan 3, 2025
1 parent 5b0199b commit c2cba5c
Showing 1 changed file with 59 additions and 21 deletions.
80 changes: 59 additions & 21 deletions platform/macos/CPackMacDeployQt.cmake.in
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
# We retry a few times, due to a macos/github action runner (macos-13) limitation
# see https://github.com/actions/runner-images/issues/7522
# This function can eventually be retired, it's a bandaid until all runners are updated
function(create_dmg_with_retry)
cmake_parse_arguments(ARG "" "CODESIGN" "" ${ARGN})

set(DMG_CMD create-dmg
--volname "@QGIS_APP_NAME@ Installer"
--hide-extension @QGIS_APP_NAME@.app
--volicon "@CMAKE_SOURCE_DIR@/images/icons/mac/qgis.icns"
--background "@CMAKE_SOURCE_DIR@/platform/macos/installer_background.png"
--window-pos 200 120
--window-size 512 320
--icon-size 100
--icon "@QGIS_APP_NAME@.app" 130 160
--app-drop-link 400 155)

if(ARG_CODESIGN)
list(APPEND DMG_CMD --codesign ${ARG_CODESIGN})
endif()

list(APPEND DMG_CMD
@CMAKE_BINARY_DIR@/@QGIS_APP_NAME@-Installer.dmg
${CPACK_TEMPORARY_DIRECTORY}/@QGIS_APP_NAME@.app)

set(MAX_RETRIES 10)
set(RETRY_COUNT 0)
set(SUCCESS FALSE)

while(NOT SUCCESS AND RETRY_COUNT LESS ${MAX_RETRIES})
execute_process(
COMMAND ${DMG_CMD}
RESULT_VARIABLE CREATE_DMG_FAILURE
)

if(CREATE_DMG_FAILURE)
math(EXPR RETRY_COUNT "${RETRY_COUNT} + 1")
if(RETRY_COUNT LESS ${MAX_RETRIES})
message(STATUS "Creating dmg failed (attempt ${RETRY_COUNT} of ${MAX_RETRIES}). Retrying...")
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 2)
endif()
else()
set(SUCCESS TRUE)
endif()
endwhile()

if(NOT SUCCESS)
message(FATAL_ERROR "Failed to create DMG after ${MAX_RETRIES} attempts")
endif()
endfunction()

# Fixup rpath of QGIS app to let it find libraries
execute_process(COMMAND install_name_tool -add_rpath @loader_path/../Frameworks ${CPACK_TEMPORARY_DIRECTORY}/@QGIS_APP_NAME@.app/Contents/MacOS/QGIS
WORKING_DIRECTORY @CMAKE_BINARY_DIR@
COMMAND_ERROR_IS_FATAL ANY
)
WORKING_DIRECTORY @CMAKE_BINARY_DIR@
COMMAND_ERROR_IS_FATAL ANY
)

if(NOT "$ENV{MACOS_CODE_SIGN_IDENTITY}" STREQUAL "")
# -appstore-compliant will strip away odbc, psql and webengine plugins
execute_process(COMMAND "@MACDEPLOYQT_EXECUTABLE@" @QGIS_APP_NAME@.app -codesign=${MACOS_CODE_SIGN_IDENTITY} -sign-for-notarization=${MACOS_CODE_SIGN_IDENTITY}
WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(COMMAND create-dmg --volname "@QGIS_APP_NAME@ Installer" --hide-extension @QGIS_APP_NAME@.app --volicon "@CMAKE_SOURCE_DIR@/images/icons/mac/qgis.icns" --background "@CMAKE_SOURCE_DIR@/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "@QGIS_APP_NAME@.app" 130 160 --app-drop-link 400 155 --codesign "${MACOS_CODE_SIGN_IDENTITY}" @CMAKE_BINARY_DIR@/@QGIS_APP_NAME@-Installer.dmg ${CPACK_TEMPORARY_DIRECTORY}/@QGIS_APP_NAME@.app
RESULT_VARIABLE CREATE_DMG_FAILURE)

if(CREATE_DMG_FAILURE)
message(STATUS "Creating dmg failed. Retrying ...")
execute_process(COMMAND create-dmg --volname "@QGIS_APP_NAME@ Installer" --hide-extension @QGIS_APP_NAME@.app --volicon "@CMAKE_SOURCE_DIR@/images/icons/mac/qgis.icns" --background "@CMAKE_SOURCE_DIR@/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "@QGIS_APP_NAME@.app" 130 160 --app-drop-link 400 155 --codesign "${MACOS_CODE_SIGN_IDENTITY}" @CMAKE_BINARY_DIR@/@QGIS_APP_NAME@-Installer.dmg ${CPACK_TEMPORARY_DIRECTORY}/@QGIS_APP_NAME@.app
COMMAND_ERROR_IS_FATAL ANY)
endif()

create_dmg_with_retry(CODESIGN "${MACOS_CODE_SIGN_IDENTITY}")
else()
# -appstore-compliant will strip away odbc, psql and webengine plugins
execute_process(COMMAND "@MACDEPLOYQT_EXECUTABLE@" "@QGIS_APP_NAME@.app"
WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
COMMAND_ERROR_IS_FATAL ANY
)

execute_process(COMMAND create-dmg --volname "@QGIS_APP_NAME@ Installer" --hide-extension @QGIS_APP_NAME@.app --volicon "@CMAKE_SOURCE_DIR@/images/icons/mac/qgis.icns" --background "@CMAKE_SOURCE_DIR@/platform/macos/installer_background.png" --window-pos 200 120 --window-size 512 320 --icon-size 100 --icon "@QGIS_APP_NAME@.app" 130 160 --app-drop-link 400 155 @CMAKE_BINARY_DIR@/@QGIS_APP_NAME@-Installer.dmg ${CPACK_TEMPORARY_DIRECTORY}/@QGIS_APP_NAME@.app
RESULT_VARIABLE CREATE_DMG_FAILURE)

if(CREATE_DMG_FAILURE)
message(STATUS "Creating dmg failed.")
endif()

create_dmg_with_retry()
endif()

0 comments on commit c2cba5c

Please sign in to comment.