У меня есть pre-commit hook, который определяет номер сборки, используя ruby gem semver2. Драгоценный камень в основном создает файл с именем.semver, в котором хранится информация о версии для пакета.
Крюк генерирует номер сборки на основе некоторых параметров даты/фиксации, а затем изменяет AssemblyInfo.cs с этой информацией, а затем добавляет измененный файл перед фиксацией.
У меня есть несколько вопросов здесь:
Есть ли опасность в том, что крючок изменяет мой файл AssemblyInfo в отношении.NET?
Должно ли это быть сделано с крюком предварительной фиксации или другим крюком?
Как я могу сказать, что этот крюк ведет себя по-другому на --amend
, merge
и rebase
?
Как я могу сказать, что этот крюк ведет себя по-разному на ветки по ветки?
У вас есть другое решение для автоматизации номера сборки?
Крюк:
#!/bin/sh
#
# Append build number to semver version
#
# check semver has been initiated
if [ -f .semver ]; then
echo 'semver'
else
echo 'semver init'
echo 'semver inc minor'
echo 'semver pre 'alpha.1''
echo 'semver'
fi
# grab date string
date_str='date +%y%m.%d.'
# grab commit count +1
build_num=$(git rev-list --since="00:00:00" HEAD --count)
let "build_num += 1"
# generate build & apply to semver
build=$date_str$build_num
semver meta $build
# define version strings
semver_str=$(semver)
ver_full=${semver_str#"v"}
cut_meta=$(cut -d "+" -f 1 <<<"$ver_full")
ver_small=$(cut -d "-" -f 1 <<<"$cut_meta")
# find AssemblyInfo & line number for AssemblyVersion
line=$(grep -n "AssemblyVersion(" "Properties/AssemblyInfo.cs")
line_num=$(cut -d ":" -f 1 <<<"$line")
# edit AssemblyVersion
new_line='[assembly: AssemblyVersion("'$ver_small'")]'
sed -i "${line_num}s/.*/$new_line/" "Properties/AssemblyInfo.cs"
# find line number for Semver
line=$(grep -n "Semver(" "Properties/AssemblyInfo.cs")
line_num=$(cut -d ":" -f 1 <<<"$line")
# edit Semver
new_line='[assembly: Semver("'$ver_full'")]'
sed -i "${line_num}s/.*/$new_line/" "Properties/AssemblyInfo.cs"
# add files
git add .semver
git add "Properties/AssemblyInfo.cs"
AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Authenticator.Properties;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b6f9caad-fbfc-455a-8d69-f795fb9812ad")]
// This assembly uses the Semantic Versioning v2.0.0
// For more information on Semantic Versioning please see http://semver.org/
[assembly: AssemblyVersion("0.1.0")]
[assembly: Semver("0.1.0-alpha.1.0.0+1406.04.15")]
Мой прием.
Я написал блог, в котором показано, как подключиться к MSBuild и изменить файлы AssemblyInfo, и из этого вы можете найти множество других примеров, инструментов и ссылок.