From 5c710ca53c0d4ccbb5dca1080ff75dc37be66793 Mon Sep 17 00:00:00 2001 From: bbhtt Date: Thu, 28 May 2026 10:32:31 +0530 Subject: [PATCH 1/3] builder-main: Set a default build subject to commit and commit message See https://github.com/flatpak/flatpak-builder/issues/743 --- src/builder-main.c | 3 +++ src/builder-utils.c | 24 ++++++++++++++++++++++++ src/builder-utils.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/builder-main.c b/src/builder-main.c index 8510da66..a7338e6f 100644 --- a/src/builder-main.c +++ b/src/builder-main.c @@ -1096,6 +1096,9 @@ main (int argc, g_print ("Exporting %s to repo\n", builder_manifest_get_id (manifest)); builder_set_term_title (_("Exporting to repository")); + if (opt_subject == NULL) + opt_subject = get_default_build_subject (); + if (!do_export (build_context, &error, FALSE, flatpak_file_get_path_cached (export_repo), diff --git a/src/builder-utils.c b/src/builder-utils.c index 01d981b5..84d08331 100644 --- a/src/builder-utils.c +++ b/src/builder-utils.c @@ -1973,3 +1973,27 @@ appstream_has_version (int major, (as_major == major && as_minor > minor) || (as_major == major && as_minor == minor && as_micro >= micro); } + +char * +get_default_build_subject (void) +{ + g_auto(GStrv) parts = NULL; + g_autofree char *output = NULL; + const char *argv[] = { "git", "log", "-1", + "--pretty=format:%s%x1f%h", + "--abbrev=12", NULL }; + + if (!flatpak_spawnv (NULL, &output, G_SUBPROCESS_FLAGS_STDERR_SILENCE, + NULL, argv, NULL)) + return NULL; + + parts = g_strsplit (output, "\x1f", 2); + if (parts[0] == NULL || parts[1] == NULL) + return NULL; + + g_autofree char *tmp = parts[0]; + parts[0] = g_str_to_ascii (tmp, NULL); + parts[0][MIN (strlen (parts[0]), 58)] = '\0'; + + return g_strdup_printf ("%s (%s)", parts[0], parts[1]); +} diff --git a/src/builder-utils.h b/src/builder-utils.h index 74e756a5..dd4aeef6 100644 --- a/src/builder-utils.h +++ b/src/builder-utils.h @@ -228,6 +228,8 @@ gboolean appstream_has_version (int major, int minor, int micro); +char *get_default_build_subject (void); + G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakXml, flatpak_xml_free); G_END_DECLS From 30773821905436c0756b365d19190b4a46781b36 Mon Sep 17 00:00:00 2001 From: bbhtt Date: Thu, 28 May 2026 10:34:22 +0530 Subject: [PATCH 2/3] builder-main: Set default build body to manifest checksum See https://github.com/flatpak/flatpak-builder/issues/743 --- src/builder-main.c | 3 +++ src/builder-utils.c | 6 ++++++ src/builder-utils.h | 1 + 3 files changed, 10 insertions(+) diff --git a/src/builder-main.c b/src/builder-main.c index a7338e6f..9b4f36db 100644 --- a/src/builder-main.c +++ b/src/builder-main.c @@ -1099,6 +1099,9 @@ main (int argc, if (opt_subject == NULL) opt_subject = get_default_build_subject (); + if (opt_body == NULL) + opt_body = get_default_build_body (manifest_sha256); + if (!do_export (build_context, &error, FALSE, flatpak_file_get_path_cached (export_repo), diff --git a/src/builder-utils.c b/src/builder-utils.c index 84d08331..a5f76af8 100644 --- a/src/builder-utils.c +++ b/src/builder-utils.c @@ -1997,3 +1997,9 @@ get_default_build_subject (void) return g_strdup_printf ("%s (%s)", parts[0], parts[1]); } + +char * +get_default_build_body (const char *sha) +{ + return g_strdup_printf ("Manifest checksum: %s", sha); +} diff --git a/src/builder-utils.h b/src/builder-utils.h index dd4aeef6..aef62327 100644 --- a/src/builder-utils.h +++ b/src/builder-utils.h @@ -229,6 +229,7 @@ gboolean appstream_has_version (int major, int micro); char *get_default_build_subject (void); +char *get_default_build_body (const char *sha); G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakXml, flatpak_xml_free); From cde570cd13c95bb0ca911a7951e8ddd0a3f3ce65 Mon Sep 17 00:00:00 2001 From: bbhtt Date: Thu, 28 May 2026 11:09:03 +0530 Subject: [PATCH 3/3] tests: Add tests for build subject and body --- tests/meson.build | 1 + tests/test-build-subj.sh | 127 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100755 tests/test-build-subj.sh diff --git a/tests/meson.build b/tests/meson.build index eda0e2d1..9940f383 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -16,6 +16,7 @@ test_names = [ 'test-builder-cleanup', 'test-builder-licence-paths', 'test-builder-src-date-epoch', + 'test-build-subj', ] tap_test = find_program( diff --git a/tests/test-build-subj.sh b/tests/test-build-subj.sh new file mode 100755 index 00000000..2933200e --- /dev/null +++ b/tests/test-build-subj.sh @@ -0,0 +1,127 @@ +#!/bin/bash +# +# Copyright (C) 2026 Boudhayan Bhattacharya +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +set -euo pipefail + +. $(dirname $0)/libtest.sh + +skip_without_fuse + +echo "1..3" + +setup_repo +install_repo +setup_sdk_repo +install_sdk_repo + +# Flatpak only exposes subject but not body +# +# ostree show format: +# +# commit 5f7703dc87237cfd81ace54e660cc4308c63e0ff59e546332202d0743a0c2f93 +# ContentChecksum: c283ccf614d1e5a07b2e9cb4e3eae3ff5373d1cad8a377b7d8fa553271ac2440 +# Date: 2026-05-28 05:50:51 +0000 +# +# A subject +# +# A body +# + +ostree_get_subject () { + local repo=$1 + local ref=$2 + ostree show --repo="$repo" "$ref" | awk '/^$/{found=1; next} found{sub(/^ /, ""); print; exit}' +} + +ostree_get_body () { + local repo=$1 + local ref=$2 + ostree show --repo="$repo" "$ref" | awk '/^$/{found=1; next} found{sub(/^ /, ""); print}' | tail -n +2 +} + +TEST_GIT_DIR="$(mktemp -d)" + +cd "$TEST_GIT_DIR" + +git init -q +git config --local user.email "test@flatpak.org" +git config --local user.name "test" +git commit -q --allow-empty -m "Init" + +APP_ID="org.test.git_subj" +MANIFEST_NAME="$APP_ID.json" +REPO="$TEST_DATA_DIR/repo" +COMMIT_SUBJ="Add manifést foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar" + +cat > "$MANIFEST_NAME" <<'EOF' +{ + "app-id": "org.test.git_subj", + "runtime": "org.test.Platform", + "sdk": "org.test.Sdk", + "modules": [{ + "name": "test", + "buildsystem": "simple", + "build-commands": ["mkdir -p /app"] + }] +} +EOF + +git add "$MANIFEST_NAME" +git commit -q -m "$COMMIT_SUBJ" + +COMMIT_HASH="$(git rev-parse --short=12 HEAD)" +MANIFEST_SHA256="$(sha256sum "$MANIFEST_NAME" | awk '{print $1}')" +EXPECTED_SUBJECT="Add manifest foo bar foo bar foo bar foo bar foo bar foo b ($COMMIT_HASH)" +EXPECTED_BODY="Manifest checksum: $MANIFEST_SHA256" + +${FLATPAK_BUILDER} --force-clean --repo="$REPO"_1 appdir "$MANIFEST_NAME" >&2 + +REF="$(ostree refs --repo="$REPO"_1 | grep "^app/$APP_ID")" +SUBJECT="$(ostree_get_subject "$REPO"_1 "$REF")" +BODY="$(ostree_get_body "$REPO"_1 "$REF")" + +assert_streq "$SUBJECT" "$EXPECTED_SUBJECT" +assert_streq "$BODY" "$EXPECTED_BODY" + +echo "ok default subject and body are set from git" + +${FLATPAK_BUILDER} --force-clean --repo="$REPO"_2 \ + --subject="Custom subject" --body="Custom body" appdir "$MANIFEST_NAME" >&2 + +REF="$(ostree refs --repo="$REPO"_2 | grep "^app/$APP_ID")" +SUBJECT="$(ostree_get_subject "$REPO"_2 "$REF")" +BODY="$(ostree_get_body "$REPO"_2 "$REF")" + +assert_streq "$SUBJECT" "Custom subject" +assert_streq "$BODY" "Custom body" + +echo "ok explicit subject and body override defaults" + +rm -rf "$TEST_GIT_DIR/.git" + +${FLATPAK_BUILDER} --force-clean --repo="$REPO"_3 appdir "$MANIFEST_NAME" >&2 + +REF="$(ostree refs --repo="$REPO"_3 | grep "^app/$APP_ID")" +SUBJECT="$(ostree_get_subject "$REPO"_3 "$REF")" +BODY="$(ostree_get_body "$REPO"_3 "$REF")" + +assert_streq "$SUBJECT" "Export $APP_ID" +assert_streq "$BODY" "$EXPECTED_BODY" + +echo "ok default export subject is used outside git dir"