package.sh: build from metadata.json and contents/ only; --install for testing

3464f52 · gmorell · 2026-11-06 17:25

2 files +53 -62
Message
{commit_body(@commit)}

Files changed

modified README.md
+3 −3
@@ -89,10 +89,10 @@ node tools/check.mjs git-gud waxx # just these
89 89 ## Install
90 90
91 91 ```bash
92 −kpackagetool6 --type Plasma/Applet --install .
93 −kpackagetool6 --type Plasma/Applet --upgrade . # after changes
92 +./package.sh --install # installs, or upgrades after changes
93 +systemctl --user restart plasma-plasmashell # Plasma holds the old QML until then
94 94
95 −./package.sh 0.1.0 # release archive (tools/ and .env left out)
95 +./package.sh 0.1.0 # release archive
96 96 ```
97 97
98 98 Test without installing:
modified package.sh
+50 −59
@@ -1,81 +1,72 @@
1 1 #!/bin/bash
2 +#
3 +# Local packaging for a neiam plasmoid. Identical in every plasmoid repo.
4 +#
5 +# ./package.sh --install install, or upgrade, into ~/.local for testing
6 +# ./package.sh [VERSION] release archives (.tar.gz, .zip) for the KDE Store
7 +#
8 +# Both start from the same clean copy: metadata.json, contents/ and the
9 +# licence — what Plasma loads, and what the .deb and .rpm ship (see
10 +# packaging/build.sh). Named in, rather than everything else excluded,
11 +# so build output, CI config, secrets and old archives lying in the
12 +# checkout can't ride along. `kpackagetool6 --upgrade .` copies the whole
13 +# directory, dist/ and all; use --install instead.
14 +
15 +set -euo pipefail
16 +
17 +root=$(cd -- "$(dirname -- "$0")" && pwd)
18 +PACKAGE_NAME=$(basename "$root")
19 +ID=$(sed -n 's/^ *"Id": *"\([^"]*\)".*/\1/p' "$root/metadata.json" | head -1)
20 +
21 +stage() {
22 + local dest=$1
23 + mkdir -p "$dest"
24 + install -m 0644 "$root/metadata.json" "$root/LICENSE.md" "$dest/"
25 + # Editor droppings inside contents/ stay behind too.
26 + rsync -a \
27 + --exclude='*.swp' --exclude='*~' --exclude='*.kate-swp' --exclude='.*' \
28 + "$root/contents/" "$dest/contents/"
29 +}
2 30
3 −# Local packaging script for Grafana Plasmoid
4 −# This script mirrors what the GitHub Action does for local testing
5 −
6 −set -e
7 −
8 −VERSION=${1:-"dev"}
9 −PACKAGE_NAME="grafana-plasmoid"
10 −
11 −echo "🚀 Packaging $PACKAGE_NAME version $VERSION"
12 −
13 −# Create temporary directory
14 31 TEMP_DIR=$(mktemp -d)
32 +trap 'rm -rf "$TEMP_DIR"' EXIT
15 33 PACKAGE_DIR="$TEMP_DIR/$PACKAGE_NAME"
16 34
17 −echo "📁 Creating package directory: $PACKAGE_DIR"
18 −mkdir -p "$PACKAGE_DIR"
35 +if [[ "${1:-}" == "--install" ]]; then
36 + stage "$PACKAGE_DIR"
37 + if kpackagetool6 --type Plasma/Applet --show "$ID" >/dev/null 2>&1; then
38 + kpackagetool6 --type Plasma/Applet --upgrade "$PACKAGE_DIR"
39 + else
40 + kpackagetool6 --type Plasma/Applet --install "$PACKAGE_DIR"
41 + fi
42 + echo ""
43 + echo "Plasma keeps the old QML loaded until the shell restarts:"
44 + echo " systemctl --user restart plasma-plasmashell"
45 + exit 0
46 +fi
19 47
20 −# Copy files (excluding development files)
21 −echo "📋 Copying files..."
22 −rsync -av \
23 − --exclude='.git' \
24 − --exclude='.github' \
25 − --exclude='*.swp' \
26 − --exclude='*~' \
27 − --exclude='*.kate-swp' \
28 − --exclude='package.sh' \
29 − --exclude='node_modules' \
30 − --exclude='*.log' \
31 − --exclude='.env' \
32 − --exclude='tools' \
33 − . "$PACKAGE_DIR/"
48 +VERSION=${1:-"dev"}
49 +echo "🚀 Packaging $PACKAGE_NAME version $VERSION"
50 +stage "$PACKAGE_DIR"
34 51
35 −# Update version in metadata.json if not "dev"
36 52 if [[ "$VERSION" != "dev" ]]; then
37 53 echo "🔢 Updating version to $VERSION"
38 54 sed -i "s/\"Version\": \"[^\"]*\"/\"Version\": \"$VERSION\"/" "$PACKAGE_DIR/metadata.json"
39 55 fi
40 56
41 −# Create packages
42 −cd "$TEMP_DIR"
57 +archives=("${PACKAGE_NAME}-${VERSION}.tar.gz")
58 +(cd "$TEMP_DIR" && tar -czf "$root/${PACKAGE_NAME}-${VERSION}.tar.gz" "$PACKAGE_NAME/")
43 59
44 −echo "📦 Creating tar.gz package..."
45 −tar -czf "${PACKAGE_NAME}-${VERSION}.tar.gz" "$PACKAGE_NAME/"
46 −
47 −echo "📦 Creating zip package..."
48 60 if command -v zip >/dev/null 2>&1; then
49 − zip -r "${PACKAGE_NAME}-${VERSION}.zip" "$PACKAGE_NAME/"
50 − CREATED_ZIP=true
61 + rm -f "$root/${PACKAGE_NAME}-${VERSION}.zip"
62 + (cd "$TEMP_DIR" && zip -qr "$root/${PACKAGE_NAME}-${VERSION}.zip" "$PACKAGE_NAME/")
63 + archives+=("${PACKAGE_NAME}-${VERSION}.zip")
51 64 else
52 65 echo "⚠️ zip command not found, skipping zip package creation"
53 − CREATED_ZIP=false
54 −fi
55 −
56 −# Move to current directory
57 −mv "${PACKAGE_NAME}-${VERSION}.tar.gz" "$OLDPWD/"
58 −if [[ "$CREATED_ZIP" == "true" ]]; then
59 − mv "${PACKAGE_NAME}-${VERSION}.zip" "$OLDPWD/"
60 66 fi
61 67
62 −# Cleanup
63 −rm -rf "$TEMP_DIR"
64 −
65 68 echo "✅ Packages created:"
66 −echo " - ${PACKAGE_NAME}-${VERSION}.tar.gz"
67 −if [[ "$CREATED_ZIP" == "true" ]]; then
68 − echo " - ${PACKAGE_NAME}-${VERSION}.zip"
69 −fi
70 −
71 −# Display package info
72 −echo ""
73 −echo "📊 Package information:"
74 −if [[ "$CREATED_ZIP" == "true" ]]; then
75 − ls -lh "${PACKAGE_NAME}-${VERSION}".{tar.gz,zip}
76 −else
77 − ls -lh "${PACKAGE_NAME}-${VERSION}.tar.gz"
78 −fi
69 +(cd "$root" && ls -lh "${archives[@]}")
79 70
80 71 echo ""
81 72 echo "🎯 Next steps:"

Parents: 84b8f07