Fix build and upload repo

master
Marko Semet 2020-12-25 02:24:28 +01:00
parent 0dc5bea634
commit e2c434ebae
3 changed files with 65 additions and 14 deletions

View File

@ -17,7 +17,7 @@ if [ -z "$4" ]; then
BUILD_DIR= exec flatpak-builder $3 --arch "$2" --sandbox --rebuild-on-sdk-change --bundle-sources "$BUILD_DIR" "$1"
else
HASH="$("$(dirname "$0")/hash_modules.py" --installed "$1" "$2" | sed -n '1p')" &&
ID="$("$(dirname "$0")/hash_modules.py" --get-id "$1" "$2").Builds" &&
ID="$(IFS=';' && "$(dirname "$0")/hash_modules.py" --get-id "$1" "$2" | read a b c && echo "$a/$b.Builds/$c")" &&
(
find '.flatpak-builder/build' '.flatpak-builder/cache' -delete ||
rm -rf ".flatpak-builder/build" '.flatpak-builder/cache'

View File

@ -13,7 +13,7 @@ class Repo:
@property
def flatpaks(self):
tmp = subprocess.run(["ostree", "refs", "--repo", self._repo], capture_output=True, check=True)
return list(filter(lambda x: x.startswith(("runtime/", "app/")), tmp.stdout.decode().splitlines()))
return list(filter(lambda x: x.startswith(("runtime/", "app/")) or x == "empty", tmp.stdout.decode().splitlines()))
def move_commit(self, repo, commit:str, no_fsync:bool=False, gpg_key:str=None, collection:str=None):
assert isinstance(repo, Repo)
@ -29,7 +29,7 @@ class Repo:
run_args.append("--gpg-sign=" + gpg_key)
if collection:
run_args.append("--extra-collection-id=" + collection)
subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--src-repo=" + repo._repo, "--src-ref=" + commit, "--no-update-summary", self._repo, commit], check=True)
subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--src-repo=" + repo._repo, "--src-ref=" + commit, self._repo, commit], check=True)
def make_eol(self, commit:str, no_fsync:bool=False, gpg_key:str=None, collection:str=None):
assert isinstance(commit, str)
@ -44,16 +44,11 @@ class Repo:
run_args.append("--gpg-sign=" + gpg_key)
if collection:
run_args.append("--extra-collection-id=" + collection)
subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--end-of-life=Base commit doesn't exists any more.", "--no-update-summary", "--src-ref=empty", self._repo, commit], check=True)
def gen_empty(self):
subprocess.run(["tar", "-cf", "empty.tar", "-T", "/dev/null"], check=True)
subprocess.run(["ostree", "commit", "--repo", self._repo, "--tar-autocreate-parents", "--tree=tar=empty.tar", "-b", "empty"], check=True)
os.remove("empty.tar")
subprocess.run(["flatpak", "build-commit-from", "--no-update-summary", "--no-summary-index"] + run_args + ["--end-of-life=Base commit doesn't exists any more.", self._repo, commit], check=True)
def delete(self, ref:str):
assert isinstance(ref, str)
os.remove(os.path.join(self._repo, "refs", "heads", *(ref.split("/"))))
subprocess.run(["ostree", "refs", "--repo", self._repo, "--delete", ref], check=True)
if __name__ == "__main__":
@ -84,10 +79,6 @@ if __name__ == "__main__":
for j in tmp:
target_repo.move_commit(i, j, no_fsync=args.no_fsync, gpg_key=args.gpg, collection=args.collection)
# Create empty
if not args.delete and "empty" not in target_repo.flatpaks:
target_repo.gen_empty()
# Remove old
commits_added = set(commits_added)
for i in filter(lambda x: x not in commits_added, target_repo.flatpaks):
@ -95,3 +86,7 @@ if __name__ == "__main__":
target_repo.delete(i)
else:
target_repo.make_eol(i, no_fsync=args.no_fsync, gpg_key=args.gpg, collection=args.collection)
# Update summary and appstream
subprocess.run(["ostree", "summary", "--repo", args.repo, "-u"] + (["--gpg-sign=" + args.gpg] if args.gpg else []), check=True)
subprocess.run(["flatpak", "build-update-repo"] + (["--deploy-collection-id", "--collection-id", args.collection] if args.collection else []) + (["--gpg-sign", args.gpg] if args.gpg else []) + [args.repo], check=True)

56
upload.sh 100755
View File

@ -0,0 +1,56 @@
#! /usr/bin/env bash
# Args: <repo> <repo-source> <remote> <remote-path> [<gpg>] [<collection>]
ARG_REPO="$1"
ARG_REPO_SOURCE="$2"
ARG_REMOTE="$3"
ARG_REMOTE_PATH="$4"
ARG_GPG="$5"
ARG_COLLECTION="$6"
#
# Generate
#
if [ -z "$NO_UPDATE" ]
then
REPO=()
FLATPAK=()
if [ -n "$ARG_GPG" ]
then
REPO=( "${REPO[@]}" "--gpg" "$ARG_GPG" )
FLATPAK=( "${FLATPAK[@]}" "--gpg-sign=$ARG_GPG" )
fi
if [ -n "$ARG_COLLECTION" ]
then
REPO=( "${REPO[@]}" "-c" "$ARG_COLLECTION" )
FLATPAK=( "${FLATPAK[@]}" "--collection-id=$ARG_COLLECTION" "--deploy-collection-id" )
fi
"$(dirname "$0")/update_repo.py" --no-fsync "${REPO[@]}" "$ARG_REPO" "$ARG_REPO_SOURCE" &&
flatpak build-update-repo --prune --prune-depth=5 "${FLATPAK[@]}" "$ARG_REPO"
fi &&
#
# Send data
#
if [ -z "$PORT" ]
then
export PORT=8000
fi &&
echo "PORT: $PORT" &&
export "LOCK_FILE=$(mktemp)" &&
( (
cd "$ARG_REPO" &&
exec python3 -m http.server --bind 127.0.0.1 "$PORT" 2> /dev/null &
SESSION="$!" &&
sleep 1 &&
exec 200> "$LOCK_FILE" &&
flock -x 200 &&
kill "$SESSION" &&
wait
rm "$LOCK_FILE"
) &) &&
(
exec 200> "$LOCK_FILE" &&
flock -x 200 &&
sleep 10 &&
ssh "$ARG_REMOTE" -R"$PORT":127.0.0.1:"$PORT" bash -c \''ostree remote add --force --no-gpg-verify --repo "$0" origin http://127.0.0.1:'"$PORT"'/ && ostree pull --repo "$0" --mirror origin && flatpak build-update-repo --prune --prune-depth=5 --no-update-summary --no-update-appstream --generate-static-deltas "$0" '\' "$ARG_REMOTE_PATH"
)