Repository: pantsbuild/pants

Issue:
generate unstable package versions which can be ordered by timestamp in release.sh
CI on master was broken after merging 067238335e8bbe2dacbe6442548dd4ee5a0782df, because when building wheels, our release script sets `PANTS_UNSTABLE_VERSION` to be the version in `src/python/pants/VERSION`, along with the first 8 characters of the commit sha. This should be fine, but not mentioned in https://www.python.org/dev/peps/pep-0440/#local-version-identifiers is that local build tags which consist of only numbers will have leading zeroes truncated, e.g.:
```
X> pex packaging setuptools
Python 2.7.15 (default, Jun 20 2018, 17:40:09)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from packaging.version import Version
>>> Version('1.15.0.dev4+06723833')
<Version('1.15.0.dev4+6723833')>
>>> str(Version('1.15.0.dev4+06723833'))
'1.15.0.dev4+6723833'
```

This required a fix in #7400 by prefacing the sha with a constant non-numeric string to avoid it getting parsed as a number.

While that was fixed, it might also be pretty useful to further modify the `PANTS_UNSTABLE_VERSION`, to add a timestamp before the SHA. This would allow `ls` to ensure the most recently produced wheel would always be at the bottom of the output.


Discussion:
Note that the timestamp component should be relatively easy to generate, but may require coordination between wheel shards in CI to work: see https://github.com/pantsbuild/pants/pull/7400#issuecomment-474121731. This might not be too difficult though.
Thinking about this again, it should be possible to deterministically extract the commit timestamp to use here, which avoid needing to coordinate between shards.

Resolving patch:
diff --git a/build-support/bin/release.py b/build-support/bin/release.py
--- a/build-support/bin/release.py
+++ b/build-support/bin/release.py
@@ -389,6 +389,22 @@ def __init__(self) -> None:
             .stdout.decode()
             .strip()
         )
+        self._head_committer_date = (
+            subprocess.run(
+                [
+                    "git",
+                    "show",
+                    "--no-patch",
+                    "--format=%cd",
+                    "--date=format:%Y%m%d%H%M",
+                    self._head_sha,
+                ],
+                stdout=subprocess.PIPE,
+                check=True,
+            )
+            .stdout.decode()
+            .strip()
+        )
         self.pants_version_file = Path("src/python/pants/VERSION")
         self.pants_stable_version = self.pants_version_file.read_text().strip()
 
@@ -418,7 +434,9 @@ def deploy_pants_wheel_dir(self) -> Path:
 
     @property
     def pants_unstable_version(self) -> str:
-        return f"{self.pants_stable_version}+git{self._head_sha[:8]}"
+        # include the commit's timestamp to make multiple builds of a single stable version more
+        # easily orderable
+        return f"{self.pants_stable_version}+{self._head_committer_date}.git{self._head_sha[:8]}"
 
     @property
     def twine_venv_dir(self) -> Path:


Test patch: