Skip to content

Commit 2702ae6

Browse files
authored
fix: ensure reproducible documentation builds wrt SOURCE_DATE_EPOCH (#2568)
* fix: ensure reproducible documentation builds wrt `SOURCE_DATE_EPOCH` * docs: add a newsfragment
1 parent 9971742 commit 2702ae6

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Falcon's documentation build process was not fully reproducible, as the output
2+
could vary with the build system's date. The issue was addressed by adding
3+
support for setting the build date via the
4+
`SOURCE_DATE_EPOCH <https://reproducible-builds.org/docs/source-date-epoch/>`__
5+
standardized environment variable.

docs/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import multiprocessing
2222
import os
2323
import sys
24+
import time
2425

2526
try:
2627
import falconry_pygments_theme
@@ -65,9 +66,15 @@
6566
for component in _version_components
6667
)
6768

69+
# NOTE(vytas): Afford overriding the current date with SOURCE_DATE_EPOCH for
70+
# reproducible documentation builds.
71+
# (See also: https://reproducible-builds.org/docs/source-date-epoch/)
72+
build_date = datetime.datetime.fromtimestamp(
73+
int(os.environ.get('SOURCE_DATE_EPOCH', time.time())), tz=datetime.timezone.utc
74+
)
6875

6976
project = 'Falcon'
70-
copyright = f'{datetime.datetime.now().year} Falcon Contributors'
77+
copyright = f'{build_date.year} Falcon Contributors'
7178
author = 'Kurt Griffiths et al.'
7279
version = '.'.join(_version_components[0:2])
7380
release = falcon.__version__

docs/ext/falcon_releases.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import datetime
2424
import enum
2525
import itertools
26+
import os
2627
import pathlib
2728
import re
29+
import time
2830

2931
import sphinx.util.docutils
3032

@@ -136,6 +138,17 @@ class FalconReleasesDirective(sphinx.util.docutils.SphinxDirective):
136138
required_arguments = 1
137139
has_content = True
138140

141+
@staticmethod
142+
def get_build_date():
143+
# NOTE(vytas,bmwiedemann): Afford overriding the current date with
144+
# SOURCE_DATE_EPOCH for reproducible documentation builds.
145+
# (See also: https://reproducible-builds.org/docs/source-date-epoch/)
146+
build_date = datetime.datetime.fromtimestamp(
147+
int(os.environ.get('SOURCE_DATE_EPOCH', time.time())),
148+
tz=datetime.timezone.utc,
149+
)
150+
return build_date.date()
151+
139152
def run(self):
140153
changelog_path = pathlib.Path(self.arguments[0])
141154
if not changelog_path.is_absolute():
@@ -184,7 +197,7 @@ def run(self):
184197
eol_date = (
185198
current_series[0].first.date + self._OLDSTABLE_MAINTENANCE_PERIOD
186199
)
187-
if datetime.date.today() < eol_date:
200+
if self.get_build_date() < eol_date:
188201
status = _ReleaseStatus.security
189202
# NOTE(vytas): Move to a new line because otherwise table
190203
# layout gets messed up in an unpleasant way.

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,17 @@ commands =
337337
# --------------------------------------------------------------------
338338

339339
[testenv:docs]
340+
# NOTE(vytas): For easy testing of reproducible documentation builds.
341+
# (See also: https://reproducible-builds.org/docs/source-date-epoch/)
342+
passenv = SOURCE_DATE_EPOCH
340343
deps = -r{toxinidir}/requirements/docs
341344
commands =
342345
sphinx-build -j auto -W -E -b html docs docs/_build/html []
343346

344347
[testenv:towncrier]
348+
# NOTE(vytas): For easy testing of reproducible documentation builds.
349+
# (See also: https://reproducible-builds.org/docs/source-date-epoch/)
350+
passenv = SOURCE_DATE_EPOCH
345351
deps = -r{toxinidir}/requirements/docs
346352
toml
347353
towncrier

0 commit comments

Comments
 (0)