[cpack/jenkins-main] rework build tagging to include git repo info in installer job

main
scottr 5 years ago
parent 1519180cec
commit 8b68aa9f5a

@ -120,7 +120,7 @@ function(strip_trailing_slash in_url out_url)
endif()
endfunction()
set(_versioned_target_url_tag ${LY_VERSION_STRING}/${PAL_HOST_PLATFORM_NAME})
set(CPACK_VERSIONED_TARGET_TAG "${PAL_HOST_PLATFORM_NAME}-${LY_VERSION_STRING}")
if(NOT LY_INSTALLER_UPLOAD_URL AND DEFINED ENV{LY_INSTALLER_UPLOAD_URL})
set(LY_INSTALLER_UPLOAD_URL $ENV{LY_INSTALLER_UPLOAD_URL})
@ -139,7 +139,7 @@ if(LY_INSTALLER_UPLOAD_URL)
endif()
strip_trailing_slash(${LY_INSTALLER_UPLOAD_URL} LY_INSTALLER_UPLOAD_URL)
set(CPACK_UPLOAD_URL ${LY_INSTALLER_UPLOAD_URL}/${_versioned_target_url_tag})
set(CPACK_UPLOAD_URL ${LY_INSTALLER_UPLOAD_URL})
endif()
# IMPORTANT: required to be included AFTER setting all property overrides
@ -189,7 +189,7 @@ if(LY_INSTALLER_DOWNLOAD_URL)
# this will set the following variables: CPACK_DOWNLOAD_SITE, CPACK_DOWNLOAD_ALL, and CPACK_UPLOAD_DIRECTORY (local)
cpack_configure_downloads(
${LY_INSTALLER_DOWNLOAD_URL}/${_versioned_target_url_tag}
${LY_INSTALLER_DOWNLOAD_URL}
UPLOAD_DIRECTORY ${CMAKE_BINARY_DIR}/_CPack_Uploads # to match the _CPack_Packages directory
ALL
)

@ -24,10 +24,24 @@ set(_ext_flags
-ext WixBalExtension
)
set(_build_id_file ${CPACK_BINARY_DIR}/build_id.txt)
if(EXISTS ${_build_id_file})
file(READ ${_build_id_file} _build_id)
set(_full_download_url ${CPACK_DOWNLOAD_SITE}/${_build_id}/${CPACK_VERSIONED_TARGET_TAG})
set(_full_upload_url ${CPACK_UPLOAD_URL}/${_build_id}/${CPACK_VERSIONED_TARGET_TAG})
else()
# format: YYYY-MM-DD-HHmm UTC
string(TIMESTAMP _timestamp "%Y%-%m-%d-%H%m" UTC)
set(_full_download_url ${CPACK_DOWNLOAD_SITE}/notag/${_timestamp}/${CPACK_VERSIONED_TARGET_TAG})
set(_full_upload_url ${CPACK_UPLOAD_URL}/notag/${_timestamp}/${CPACK_VERSIONED_TARGET_TAG})
endif()
set(_addtional_defines
-dCPACK_BOOTSTRAP_THEME_FILE=${CPACK_BINARY_DIR}/BootstrapperTheme
-dCPACK_BOOTSTRAP_UPGRADE_GUID=${CPACK_WIX_BOOTSTRAP_UPGRADE_GUID}
-dCPACK_DOWNLOAD_SITE=${CPACK_DOWNLOAD_SITE}
-dCPACK_DOWNLOAD_SITE=${_full_download_url}
-dCPACK_LOCAL_INSTALLER_DIR=${_cpack_wix_out_dir}
-dCPACK_PACKAGE_FILE_NAME=${CPACK_PACKAGE_FILE_NAME}
-dCPACK_PACKAGE_INSTALL_DIRECTORY=${_fixed_package_install_dir}
@ -109,7 +123,7 @@ file(TO_NATIVE_PATH "${_root_path}/scripts/build/tools/upload_to_s3.py" _upload_
file(TO_NATIVE_PATH "${_cpack_wix_out_dir}" _cpack_wix_out_dir)
# strip the scheme and extract the bucket/key prefix from the URL
string(REPLACE "s3://" "" _stripped_url ${CPACK_UPLOAD_URL})
string(REPLACE "s3://" "" _stripped_url ${_full_upload_url})
string(REPLACE "/" ";" _tokens ${_stripped_url})
list(POP_FRONT _tokens _bucket)
@ -127,12 +141,15 @@ set(_upload_command
--profile ${CPACK_AWS_PROFILE}
)
message(STATUS "Uploading artifacts to ${_full_upload_url}")
execute_process(
COMMAND ${_upload_command}
RESULT_VARIABLE _upload_result
ERROR_VARIABLE _upload_errors
)
if (NOT ${_upload_result} EQUAL 0)
if (${_upload_result} EQUAL 0)
message(STATUS "Artifact uploading complete!")
else()
message(FATAL_ERROR "An error occurred uploading artifacts. ${_upload_errors}")
endif()

@ -50,10 +50,25 @@ IF ERRORLEVEL 1 (
GOTO :popd_error
)
REM generate the build ID for artifact upload tagging
PUSHD "%~dp0/../../../.."
SET "ENGINE_ROOT=%cd%"
POPD
SET "GEN_BUILD_ID_SCRIPT=%ENGINE_ROOT%/scripts/build/tools/generate_build_tag.py"
SET "BUILD_ID_FILE=_CPack/build_id.txt"
ECHO [ci_build] "%ENGINE_ROOT%/python/python.cmd" -u "%GEN_BUILD_ID_SCRIPT%" "%BUILD_ID_FILE%"
CALL "%ENGINE_ROOT%/python/python.cmd" -u "%GEN_BUILD_ID_SCRIPT%" "%BUILD_ID_FILE%"
IF ERRORLEVEL 1 (
ECHO [ci_build] Failed to generate build ID
GOTO :popd_error
)
ECHO [ci_build] "!CPACK_PATH!" -C %CONFIGURATION%
"!CPACK_PATH!" -C %CONFIGURATION%
IF NOT %ERRORLEVEL%==0 (
rem dump the log file generated by cpack specifically for WIX
REM dump the log file generated by cpack specifically for WIX
ECHO ****************************************************************
TYPE "_CPack_Packages\\WIX\\wix.log"
ECHO ****************************************************************

@ -0,0 +1,66 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
import argparse
import os
import pathlib
import shutil
import subprocess
import sys
def run_git_command(args, repo_root):
process = subprocess.run(['git', *args],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=repo_root,
env=os.environ.copy(),
universal_newlines=True,
)
if process.returncode != 0:
print(
f'An error occurred while running a command\n'
f'Command: git {subprocess.list2cmdline(args)}\n'
f'Return Code: {process.returncode}\n'
f'Error: {process.stderr}'
)
exit(1)
output = process.stdout.splitlines()
# something went wrong and we somehow got more information then requested
if len(output) != 1:
print(f'Unexpected output received from command: git {subprocess.list2cmdline(args)}')
exit(1)
return output[0].strip('"')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generates a build ID based on the state of the git repository')
parser.add_argument('output_file', help='Path to the output file where the build ID will be written to')
parsed_args = parser.parse_args()
repo_root = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
branch = run_git_command(['branch', '--show-current'], repo_root)
branch = branch.replace('/', '-')
commit_hash = run_git_command(['show', '--format="%h"', '--no-patch'], repo_root)
# include the commit date to allow some sensible way of sorting
commit_date = run_git_command(['show', '-s', '--format="%cs"', commit_hash], repo_root)
with open(parsed_args.output_file, 'w') as out_file:
out_file.write(f'{branch}/{commit_date}-{commit_hash}')
sys.exit(0)
Loading…
Cancel
Save