Skip to content

Commit

Permalink
Add --reproduce
Browse files Browse the repository at this point in the history
  • Loading branch information
legoktm committed Jul 16, 2024
1 parent 25e88cf commit 8bff81f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ jobs:
- name: Check repository metadata is up-to-date
run: |
git config --global --add safe.directory '*'
shopt -s globstar
# Parse the value out of <revision></revision>
export SOURCE_DATE_EPOCH=$(grep -m 1 "revision" public/**/repomd.xml | cut -d '>' -f 2 | cut -d '<' -f 1)
./tools/publish-real
./tools/publish-real --reproduce
git status
git diff --exit-code
27 changes: 22 additions & 5 deletions tools/publish-real
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,54 @@ copied into public/ and metadata is generated there.
import os
import shutil
import subprocess
import sys
from pathlib import Path
import xml.etree.ElementTree as ET


def fetch_reproduce_timestamp(public: Path) -> int:
repomd = next(public.glob("workstation/dom0/*/repodata/repomd.xml"))
tree = ET.parse(repomd)
root = tree.getroot()
revision = root.find('repo:revision', {'repo': 'http://linux.duke.edu/metadata/repo'})
print(f"Will use a timestamp of {revision.text} (from {repomd})")
return int(revision.text)


def main():
root = Path(__file__).parent.parent
public = root / "public"
workstation = root / "workstation"
source_date_epoch = int(os.environ.get("SOURCE_DATE_EPOCH", 0))
if "--reproduce" in sys.argv:
try:
timestamp = fetch_reproduce_timestamp(public)
except Exception as err:
raise RuntimeError("Failed to fetch timestamp from repomd.xml") from err
else:
timestamp = None
# Reset public, copy the workstation/ tree into it
print("Creating public/ (from scratch)")
if public.exists():
shutil.rmtree(public)
public.mkdir()
shutil.copytree(workstation, public / "workstation")
if source_date_epoch:
if timestamp:
for rpm in public.glob("**/*.rpm"):
os.utime(rpm, (source_date_epoch, source_date_epoch))
os.utime(rpm, (timestamp, timestamp))
# Folders are public/workstation/dom0/fXX, run createrepo_c in each one
for folder in public.glob("*/*/*/"):
if not folder.is_dir():
continue
print(f"Generating metadata for {folder}")
args = ["createrepo_c"]
if source_date_epoch:
if timestamp:
# The <revision> and <timestamp> fields are set to the current UNIX time
# unless we explicitly override them. In most cases we want to use
# the current time except when we're doing reproducibility testing.
args.extend(
[
"--revision",
str(source_date_epoch),
str(timestamp),
"--set-timestamp-to-revision",
]
)
Expand Down

0 comments on commit 8bff81f

Please sign in to comment.