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

This commit is contained in:
scottr
2021-06-18 16:55:22 -07:00
parent 1519180cec
commit 8b68aa9f5a
4 changed files with 105 additions and 7 deletions
@@ -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 ****************************************************************
+66
View File
@@ -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)