|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (C) 2026 Boudhayan Bhattacharya <bbhtt@bbhtt.in> |
| 4 | +# |
| 5 | +# This library is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU Lesser General Public |
| 7 | +# License as published by the Free Software Foundation; either |
| 8 | +# version 2 of the License, or (at your option) any later version. |
| 9 | +# |
| 10 | +# This library is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | +# Lesser General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU Lesser General Public |
| 16 | +# License along with this library; if not, write to the |
| 17 | +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 18 | +# Boston, MA 02111-1307, USA. |
| 19 | + |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +. $(dirname $0)/libtest.sh |
| 23 | + |
| 24 | +skip_without_fuse |
| 25 | + |
| 26 | +echo "1..3" |
| 27 | + |
| 28 | +setup_repo |
| 29 | +install_repo |
| 30 | +setup_sdk_repo |
| 31 | +install_sdk_repo |
| 32 | + |
| 33 | +# Flatpak only exposes subject but not body |
| 34 | +# |
| 35 | +# ostree show format: |
| 36 | +# |
| 37 | +# commit 5f7703dc87237cfd81ace54e660cc4308c63e0ff59e546332202d0743a0c2f93 |
| 38 | +# ContentChecksum: c283ccf614d1e5a07b2e9cb4e3eae3ff5373d1cad8a377b7d8fa553271ac2440 |
| 39 | +# Date: 2026-05-28 05:50:51 +0000 |
| 40 | +# |
| 41 | +# A subject |
| 42 | +# |
| 43 | +# A body |
| 44 | +# |
| 45 | + |
| 46 | +ostree_get_subject () { |
| 47 | + local repo=$1 |
| 48 | + local ref=$2 |
| 49 | + ostree show --repo="$repo" "$ref" | awk '/^$/{found=1; next} found{sub(/^ /, ""); print; exit}' |
| 50 | +} |
| 51 | + |
| 52 | +ostree_get_body () { |
| 53 | + local repo=$1 |
| 54 | + local ref=$2 |
| 55 | + ostree show --repo="$repo" "$ref" | awk '/^$/{found=1; next} found{sub(/^ /, ""); print}' | tail -n +2 |
| 56 | +} |
| 57 | + |
| 58 | +TEST_GIT_DIR="$(mktemp -d)" |
| 59 | + |
| 60 | +cd "$TEST_GIT_DIR" |
| 61 | + |
| 62 | +git init -q |
| 63 | +git config --local user.email "test@flatpak.org" |
| 64 | +git config --local user.name "test" |
| 65 | +git commit -q --allow-empty -m "Init" |
| 66 | + |
| 67 | +APP_ID="org.test.git_subj" |
| 68 | +MANIFEST_NAME="$APP_ID.json" |
| 69 | +REPO="$TEST_DATA_DIR/repo" |
| 70 | +COMMIT_SUBJ="Add manifest foo bar" |
| 71 | + |
| 72 | +cat > "$MANIFEST_NAME" <<'EOF' |
| 73 | +{ |
| 74 | + "app-id": "org.test.git_subj", |
| 75 | + "runtime": "org.test.Platform", |
| 76 | + "sdk": "org.test.Sdk", |
| 77 | + "modules": [{ |
| 78 | + "name": "test", |
| 79 | + "buildsystem": "simple", |
| 80 | + "build-commands": ["mkdir -p /app"] |
| 81 | + }] |
| 82 | +} |
| 83 | +EOF |
| 84 | + |
| 85 | +git add "$MANIFEST_NAME" |
| 86 | +git commit -q -m "$COMMIT_SUBJ" |
| 87 | + |
| 88 | +COMMIT_HASH="$(git rev-parse --short=12 HEAD)" |
| 89 | +MANIFEST_SHA256="$(sha256sum "$MANIFEST_NAME" | awk '{print $1}')" |
| 90 | +EXPECTED_SUBJECT="$COMMIT_SUBJ ($COMMIT_HASH)" |
| 91 | +EXPECTED_BODY="Manifest checksum: $MANIFEST_SHA256" |
| 92 | + |
| 93 | +${FLATPAK_BUILDER} --force-clean --repo="$REPO"_1 appdir "$MANIFEST_NAME" >&2 |
| 94 | + |
| 95 | +REF="$(ostree refs --repo="$REPO"_1 | grep "^app/$APP_ID")" |
| 96 | +SUBJECT="$(ostree_get_subject "$REPO"_1 "$REF")" |
| 97 | +BODY="$(ostree_get_body "$REPO"_1 "$REF")" |
| 98 | + |
| 99 | +assert_streq "$SUBJECT" "$EXPECTED_SUBJECT" |
| 100 | +assert_streq "$BODY" "$EXPECTED_BODY" |
| 101 | + |
| 102 | +echo "ok default subject and body are set from git" |
| 103 | + |
| 104 | +${FLATPAK_BUILDER} --force-clean --repo="$REPO"_2 \ |
| 105 | + --subject="Custom subject" --body="Custom body" appdir "$MANIFEST_NAME" >&2 |
| 106 | + |
| 107 | +REF="$(ostree refs --repo="$REPO"_2 | grep "^app/$APP_ID")" |
| 108 | +SUBJECT="$(ostree_get_subject "$REPO"_2 "$REF")" |
| 109 | +BODY="$(ostree_get_body "$REPO"_2 "$REF")" |
| 110 | + |
| 111 | +assert_streq "$SUBJECT" "Custom subject" |
| 112 | +assert_streq "$BODY" "Custom body" |
| 113 | + |
| 114 | +echo "ok explicit subject and body override defaults" |
| 115 | + |
| 116 | +rm -rf "$TEST_GIT_DIR/.git" |
| 117 | + |
| 118 | +${FLATPAK_BUILDER} --force-clean --repo="$REPO"_3 appdir "$MANIFEST_NAME" >&2 |
| 119 | + |
| 120 | +REF="$(ostree refs --repo="$REPO"_3 | grep "^app/$APP_ID")" |
| 121 | +SUBJECT="$(ostree_get_subject "$REPO"_3 "$REF")" |
| 122 | +BODY="$(ostree_get_body "$REPO"_3 "$REF")" |
| 123 | + |
| 124 | +assert_streq "$SUBJECT" "Export $APP_ID" |
| 125 | +assert_streq "$BODY" "$EXPECTED_BODY" |
| 126 | + |
| 127 | +echo "ok default export subject is used outside git dir" |
0 commit comments