mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
C#: Re-implement the git version logic using an attribute.
This commit is contained in:
34
csharp/scripts/gen-assembly-info.py
Normal file
34
csharp/scripts/gen-assembly-info.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Generates an `AssemblyInfo.cs` file that specifies the `AssemblyInformationalVersion` attribute.
|
||||
|
||||
This attribute is set to the git version string of the repository."""
|
||||
|
||||
import pathlib
|
||||
import argparse
|
||||
|
||||
|
||||
def options():
|
||||
p = argparse.ArgumentParser(
|
||||
description="Generate the assembly info file that contains the git SHA and branch name"
|
||||
)
|
||||
p.add_argument("output", help="The path to the output file")
|
||||
p.add_argument("gitinfo_files", nargs="+", help="The path to the gitinfo files")
|
||||
return p.parse_args()
|
||||
|
||||
|
||||
opts = options()
|
||||
|
||||
gitfiles = dict()
|
||||
for file in map(pathlib.Path, opts.gitinfo_files):
|
||||
gitfiles[file.name] = file
|
||||
|
||||
version_string = gitfiles["git-ql-describe-all.log"].read_text().strip()
|
||||
version_string += f" ({gitfiles['git-ql-rev-parse.log'].read_text().strip()})"
|
||||
|
||||
output_file = pathlib.Path(opts.output)
|
||||
output_file_contents = f"""
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyInformationalVersion("{version_string}")]
|
||||
"""
|
||||
output_file.write_text(output_file_contents)
|
||||
Reference in New Issue
Block a user