Skip to content

Commit

Permalink
internal: support PR labels in gamemode (#1940)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Apr 27, 2024
1 parent 642eb31 commit 8a87514
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
23 changes: 20 additions & 3 deletions skymp5-functions-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,34 @@ if(BUILD_GAMEMODE)
set(SCRIPT_PATH "${CMAKE_CURRENT_LIST_DIR}/download-and-build.cmake")
configure_file(${SCRIPT_PATH} ${CMAKE_BINARY_DIR}/download-and-build.cmake)

set(DEPLOY_BRANCH "$ENV{DEPLOY_BRANCH}")
set(AUTO_MERGE_REPO "Pospelove/auto-merge-action")
set(AUTO_MERGE_BRANCH "main")
set(AUTO_MERGE_REPO_URL "https://github.com/${AUTO_MERGE_REPO}.git")
set(GAMEMODE_REPO_URL "https://${GITHUB_TOKEN}:x-oauth-basic@github.com/${GAMEMODE_REPO_OWNER}/${GAMEMODE_REPO_NAME}.git")
set(ENV_INPUT_REPOSITORIES "[{\"owner\": \"Pospelove\", \"repo\": \"skymp5-gamemode\", \"labels\": [\"merge-to:${DEPLOY_BRANCH}\"], \"token\": \"${GITHUB_TOKEN}\"}]")

# Pass variables to the download script with PRS.
set(SCRIPT_PATH2 "${CMAKE_CURRENT_LIST_DIR}/download-and-build-with-prs.cmake")
configure_file(${SCRIPT_PATH2} ${CMAKE_BINARY_DIR}/download-and-build-with-prs.cmake ESCAPE_QUOTES)

if("$ENV{CI}" STREQUAL "true" AND NOT "$ENV{DEPLOY_BRANCH}" STREQUAL "")
set(source download-and-build-with-prs.cmake)
else()
set(source download-and-build.cmake)
endif()

add_custom_target(skymp5-functions-lib ALL
SOURCES ${sources}
SOURCES ${source}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/dist/server
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/${GAMEMODE_REPO_NAME}-${GAMEMODE_BRANCH}
COMMAND ${CMAKE_COMMAND} -E env DOWNLOAD_NO_PROGRESS=1
${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/download-and-build.cmake
${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/${source}
COMMENT "Downloading & building gamemode repo..."
)
else()
add_custom_target(skymp5-functions-lib ALL
SOURCES ${sources}
SOURCES ${source}
COMMAND ${CMAKE_COMMAND} -E echo "Building skymp5-functions-lib is disabled. To enable it, set BUILD_GAMEMODE to ON."
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/dist/server
COMMAND ${CMAKE_COMMAND} -E true > ${CMAKE_BINARY_DIR}/dist/server/gamemode.js
Expand Down
77 changes: 77 additions & 0 deletions skymp5-functions-lib/download-and-build-with-prs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
include(${CMAKE_SOURCE_DIR}/cmake/yarn.cmake)

message(STATUS "Downloading gamemode sources")

# Download the repository using Git

# TODO: Fix CMakeLists.txt: GIT_RESULT/GIT_OUTPUT do not help since configure_file eliminates the variables
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/gamemode-sources)
execute_process(
COMMAND git clone "${GAMEMODE_REPO_URL}" ${CMAKE_BINARY_DIR}/gamemode-sources
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE GIT_OUTPUT
)

if(GIT_RESULT EQUAL 0)
message(STATUS "Downloaded gamemode sources")
else()
message(FATAL_ERROR "Failed to download gamemode sources: ${GIT_OUTPUT}")
endif()

message(STATUS "Downloading Pospelove/auto-merge-action@main (dist/index.js)")

message(STATUS "Downloading ${AUTO_MERGE_REPO}@${AUTO_MERGE_BRANCH} (dist/index.js)")

file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/auto-merge-action)
execute_process(
COMMAND git clone --branch "${AUTO_MERGE_BRANCH}" "${AUTO_MERGE_REPO_URL}" ${CMAKE_BINARY_DIR}/auto-merge-action
RESULT_VARIABLE GIT_AM_RESULT
OUTPUT_VARIABLE GIT_AM_OUTPUT
)

if(GIT_AM_RESULT EQUAL 0)
message(STATUS "Downloaded ${AUTO_MERGE_REPO}@${AUTO_MERGE_BRANCH} (dist/index.js)")
else()
message(FATAL_ERROR "Failed to download ${AUTO_MERGE_REPO}@${AUTO_MERGE_BRANCH}: ${GIT_AM_OUTPUT}")
endif()

message(STATUS "Run Pospelove/auto-merge-action@main (dist/index.js)")

# Execute the NodeJS script
set(ENV{INPUT_REPOSITORIES} "${ENV_INPUT_REPOSITORIES}")
set(ENV{INPUT_PATH} ${CMAKE_BINARY_DIR}/gamemode-sources)
execute_process(
COMMAND node ${CMAKE_BINARY_DIR}/auto-merge-action/dist/index.js
RESULT_VARIABLE NODE_RESULT
#OUTPUT_VARIABLE NODE_OUTPUT
)

if(NODE_RESULT EQUAL 0)
message(STATUS "Successfully ran Pospelove/auto-merge-action@main")
else()
message(FATAL_ERROR "Failed to run Pospelove/auto-merge-action@main: ${NODE_OUTPUT}")
endif()

message(STATUS "Installing yarn dependencies for gamemode")

yarn_execute_command(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gamemode-sources
COMMAND install
)

message(STATUS "Installed yarn dependencies for gamemode")

message(STATUS "Building gamemode.js")

yarn_execute_command(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gamemode-sources
COMMAND build
)

message(STATUS "Built gamemode.js")

message(STATUS "Installing gamemode.js")

file(COPY ${CMAKE_BINARY_DIR}/gamemode-sources/build/gamemode.js DESTINATION "${GAMEMODE_JS_DEST_DIR}")

message(STATUS "Installed gamemode.js")

0 comments on commit 8a87514

Please sign in to comment.