Skip to content

Commit

Permalink
Makefile,tools: skip whitelist on LP (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meulengracht authored Oct 1, 2024
1 parent 99cc1dc commit af91107
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ endif
# generate the changelog in this case, ensure that the current folder is
# a git repository
if git rev-parse HEAD && [ -e "/snap/$(SNAP_NAME)/current/usr/share/snappy/dpkg.yaml" ]; then \
CHG_PARAMS=; \
if [ -e /build/$(SNAP_NAME) ]; then \
CHG_PARAMS=--launchpad; \
fi; \
./tools/generate-changelog.py \
"/snap/$(SNAP_NAME)/current" \
"$(DESTDIR)" \
"$(SNAP_NAME)"; \
"$(SNAP_NAME)" \
$$CHG_PARAMS; \
else \
echo "WARNING: changelog will not be generated for this build"; \
fi
Expand Down
15 changes: 8 additions & 7 deletions tools/generate-changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def get_changelog_from_file(docs_d, pkg):
else:
raise FileNotFoundError("no supported changelog found for package " + pkg)

def get_changelog_from_url(pkg, new_v):
def get_changelog_from_url(pkg, new_v, on_lp):
url = 'https://changelogs.ubuntu.com/changelogs/binary/'

print(f"failed to resolve changelog for {pkg} locally, downloading from official repo")
safe_name = package_name(pkg)
if safe_name not in pkg_allowed_list:
if not on_lp and safe_name not in pkg_allowed_list:
raise Exception(f"{pkg} has not been whitelisted for changelog retrieval")

if safe_name.startswith('lib'):
Expand All @@ -97,14 +97,14 @@ def get_changelog_from_url(pkg, new_v):

# Gets difference in changelog between old and new versions
# Returns source package and the differences
def get_changes_for_version(docs_d, pkg, old_v, new_v, indent):
def get_changes_for_version(docs_d, pkg, old_v, new_v, indent, on_lp):
# Try our best to resolve the changelog locally, if it does
# not exist locally, then the package must be in the whitelisted
# list of packages, when we try to resolve it from URL as backup.
try:
changelog = get_changelog_from_file(docs_d, pkg)
except Exception:
changelog = get_changelog_from_url(pkg, new_v)
changelog = get_changelog_from_url(pkg, new_v, on_lp)

source_pkg = changelog[0:changelog.find(' ')]

Expand Down Expand Up @@ -138,7 +138,7 @@ def get_changes_for_version(docs_d, pkg, old_v, new_v, indent):
# old_manifest_p: path to old manifest
# new_manifest_p: path to newer manifest
# docs_d: directory with docs from debian packages
def compare_manifests(old_manifest_p, new_manifest_p, docs_d):
def compare_manifests(old_manifest_p, new_manifest_p, docs_d, on_lp):
old_packages = packages_from_manifest(old_manifest_p)
new_packages = packages_from_manifest(new_manifest_p)
changes = ''
Expand All @@ -150,7 +150,7 @@ def compare_manifests(old_manifest_p, new_manifest_p, docs_d):
old_v = old_packages[pkg]
if old_v != new_v:
src, pkg_change = get_changes_for_version(docs_d, pkg, old_v,
new_v, ' ')
new_v, ' ', on_lp)
if src not in src_pkgs:
src_pkgs[src] = SrcPkgData(old_v, new_v, pkg_change, [pkg])
else:
Expand Down Expand Up @@ -214,6 +214,7 @@ def main():
parser.add_argument('old', metavar='previous-snap-root', help='Path to the root of the previous snap directory')
parser.add_argument('new', metavar='new-snap-root', help='Path to the root of the new snap directory')
parser.add_argument('name', help='The name of the snap')
parser.add_argument("--launchpad", action="store_true", help='Indicate we are building on LP, ignoring the whitelist')
args = parser.parse_args()

old_changelog = os.path.join(args.old, "usr", "share", "doc", "ChangeLog")
Expand Down Expand Up @@ -242,7 +243,7 @@ def main():
changes += f'No detected changes for the {args.name} snap\n\n'

changes += '[ Changes in primed packages ]\n\n'
pkg_changes = compare_manifests(old_manifest, new_manifest, docs_dir)
pkg_changes = compare_manifests(old_manifest, new_manifest, docs_dir, args.launchpad)
if pkg_changes != '':
changes += pkg_changes
else:
Expand Down

0 comments on commit af91107

Please sign in to comment.