Skip to content

Commit

Permalink
Self-review
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jan 24, 2024
1 parent 3b07af4 commit cbdbbf2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions scripts/version-patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
import subprocess
import sys

def replace_version(filename, new_text):
def replace_version(filename, build_info):
pattern = r'(Current : constant String := "[^+]+\+)([^"]*)(";)'
with open(filename, 'rb') as file:
content = file.read()

# Depending on the context in which this is run, there may be mix-ups with
# line terminators between the environment detected, github runner, etc...
# So just keep them as they are and that should always work.
content = content.decode()

new_content = re.sub(pattern, r'\g<1>' + new_text + r'\3', content)
with open(filename, 'rb') as file:
content = file.read().decode()

# The pattern captures the part between '+' and '";', replacing it with our
# new build information

new_content = re.sub(pattern, r'\g<1>' + build_info + r'\3', content)

# A few sanity checks and write if needed

if new_content == content:
if new_text in content:
if build_info in content:
print(f"Note: version in {filename} already up to date")
else:
print(f"WARNING: failed to update version in {filename}")
Expand All @@ -32,11 +37,11 @@ def replace_version(filename, new_text):
sys.exit(0)

# If there is an argument to the script, retrieve it here and use it as the new
# dirty flag
# dirty flag after the commit
if len(sys.argv) > 1:
dirty = sys.argv[1]
else:
# Detect the current directory contains changes
# Detect whether the current directory contains changes
if subprocess.call(['git', 'diff-index', '--quiet', 'HEAD', '--']) != 0:
dirty = "_dirty"
else:
Expand All @@ -45,6 +50,6 @@ def replace_version(filename, new_text):
# Find the short git commit of the repository in the current directory
commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()

# Replace the build version part with the short commit hash
# Replace the build version part with the short commit hash plus any extra info
print(f"Updating version in src/alire/alire-version.ads to commit {commit}{dirty}...")
replace_version('src/alire/alire-version.ads', commit+dirty)
2 changes: 1 addition & 1 deletion src/alire/alire-version.ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package Alire.Version with Preelaborate is
-- be replaced by `alr build` with the current commit, and appended with
-- "_or_later" after build.

Current : constant String := "2.0-beta2+92896bd3_or_later";
Current : constant String := "2.0-beta2+99325800_or_later";
-- 2.0.0-b1: first public release on the 2.0 branch
-- 1.2.1: build switches fix and other minor assorted fixes
-- 1.2.0: rpm speed-up, silence propagation warning, early switch parse
Expand Down

0 comments on commit cbdbbf2

Please sign in to comment.