From ccbff9c76caa62dd7f20f90e1efc4999d6642980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6thlisberger?= Date: Thu, 7 Mar 2024 11:57:53 +0000 Subject: [PATCH] snapshot: Include hostname in commit message So that the Portal can show a description such as "@user's uncommitted changes on {hostname}". Note: Hostname of GitHub Actions runners are like "fv-az1500-136" (ubuntu) or "Mac-1709811484995.local" (macos). --- stbt_rig.py | 8 ++++++-- test_stbt_rig.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/stbt_rig.py b/stbt_rig.py index f9d567c..3a7f094 100755 --- a/stbt_rig.py +++ b/stbt_rig.py @@ -24,6 +24,7 @@ import re import shutil import signal +import socket import subprocess import sys import tempfile @@ -1660,9 +1661,12 @@ def take_snapshot(self): else: extra_env = {} + commit_message = "snapshot\n\nremoteref: %s\nhostname: %s" % ( + remoteref, socket.gethostname()) + commit_sha = self._git( - ['commit-tree', write_tree, '-p', base_commit, '-m', - "snapshot\n\nremoteref: %s" % remoteref], + ['commit-tree', write_tree, '-p', base_commit, + '-m', commit_message], extra_env=extra_env).strip() if no_workingdir_changes: diff --git a/test_stbt_rig.py b/test_stbt_rig.py index 3847e6e..c691481 100644 --- a/test_stbt_rig.py +++ b/test_stbt_rig.py @@ -31,8 +31,12 @@ def test_testpack_snapshot_no_change_if_no_commits(test_pack): commit_sha, run_sha = test_pack.take_snapshot() assert rev_parse("HEAD") == run_sha assert tree_sha(commit_sha) == tree_sha(run_sha) - assert commit_msg(commit_sha) == ( - "snapshot\n\nremoteref: refs/heads/mybranch") + assert re.match(dedent("""\ + snapshot + + remoteref: refs/heads/mybranch + hostname: (drothlisxps13|fv-|Mac-)"""), + commit_msg(commit_sha)) # Check that the SHA is deterministic: time.sleep(1)