From 82734470d2d35096b2bd3a8b0e2fc28dff031c91 Mon Sep 17 00:00:00 2001 From: leafee98 Date: Fri, 18 Aug 2023 17:28:14 +0800 Subject: [PATCH] refactor package directory, enhance build script - update makedeb - use bin, git, normal, leafee98 to classify packages - only build package from leafee98 and bin in ci - add script to build all packages locally - add more log about running hook in build.sh --- .gitignore | 6 ++-- .woodpecker/build.yml | 33 +++++++++---------- makedeb | 2 +- packages/{ => bin}/dufs-bin/DEBBUILD | 0 .../{ => bin}/dufs-bin/materials/dufs.service | 0 packages/{ => bin}/filebrowser-bin/DEBBUILD | 0 .../materials/filebrowser.service | 0 packages/{ => bin}/forgejo-bin/DEBBUILD | 0 .../forgejo-bin/materials/forgejo.service | 0 packages/{ => bin}/neovim-bin/DEBBUILD | 0 packages/{ => bin}/plik-bin/DEBBUILD | 0 .../plik-bin/materials/plikd.service | 0 packages/{ => git}/lemonade-git/DEBBUILD | 0 .../apt-repo-updater-git}/DEBBUILD | 0 .../materials/apt-repo-updater.service | 0 .../static-deployer-git/DEBBUILD | 0 packages/{ => normal}/dendrite/DEBBUILD | 0 script/{build_all.sh => build.sh} | 28 +++++++++++++--- script/local_build.sh | 24 ++++++++++++++ 19 files changed, 66 insertions(+), 27 deletions(-) rename packages/{ => bin}/dufs-bin/DEBBUILD (100%) rename packages/{ => bin}/dufs-bin/materials/dufs.service (100%) rename packages/{ => bin}/filebrowser-bin/DEBBUILD (100%) rename packages/{ => bin}/filebrowser-bin/materials/filebrowser.service (100%) rename packages/{ => bin}/forgejo-bin/DEBBUILD (100%) rename packages/{ => bin}/forgejo-bin/materials/forgejo.service (100%) rename packages/{ => bin}/neovim-bin/DEBBUILD (100%) rename packages/{ => bin}/plik-bin/DEBBUILD (100%) rename packages/{ => bin}/plik-bin/materials/plikd.service (100%) rename packages/{ => git}/lemonade-git/DEBBUILD (100%) rename packages/{apt-repo-updater => leafee98/apt-repo-updater-git}/DEBBUILD (100%) rename packages/{apt-repo-updater => leafee98/apt-repo-updater-git}/materials/apt-repo-updater.service (100%) rename packages/{ => leafee98}/static-deployer-git/DEBBUILD (100%) rename packages/{ => normal}/dendrite/DEBBUILD (100%) rename script/{build_all.sh => build.sh} (83%) create mode 100755 script/local_build.sh diff --git a/.gitignore b/.gitignore index eb35a70..93ef134 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ /secrets.env -/packages/*/* -!/packages/*/DEBBUILD -!/packages/*/materials +/packages/*/*/* +!/packages/*/*/DEBBUILD +!/packages/*/*/materials !/script/* !/makedeb diff --git a/.woodpecker/build.yml b/.woodpecker/build.yml index 8acbc7d..5978304 100644 --- a/.woodpecker/build.yml +++ b/.woodpecker/build.yml @@ -2,28 +2,25 @@ steps: - name: build_all image: debian-pack:0.4 secrets: - - WEBDAV_USER - WEBDAV_PASS - - WEBDAV_HOST - - WEBDAV_REPOPATH + - WEBDAV_USER + environment: + - WEBDAV_UPLOAD_TARGET=https://dufs.leafee98.com/apt/income + - APT_BASE=https://dufs.leafee98.com/apt commands: - rm -f /tmp/apt-file-exists-cache.json - - hook_str="$(realpath ./script/package_exists.py) - --filename {} - --cache-file /tmp/apt-file-exists-cache.json - --package-arch amd64 - --apt-base https://dufs.leafee98.com/apt/" - - ./script/build_all.sh + - ./script/build.sh --makedeb-path makedeb/makedeb - --package-exists-hook "$hook_str" - --upload-to-webdav "https://dufs.leafee98.com/apt/income" + --package-exists-hook " + $(realpath ./script/package_exists.py) + --filename {} + --cache-file /tmp/apt-file-exists-cache.json + --package-arch amd64 + --apt-base $APT_BASE + " + --upload-to-webdav "$WEBDAV_UPLOAD_TARGET" --webdav-user "$WEBDAV_USER" --webdav-pass "$WEBDAV_PASS" - --package packages/apt-repo-updater - --package packages/dufs-bin - --package packages/filebrowser-bin - --package packages/forgejo-bin - --package packages/neovim-bin - --package packages/plik-bin - --package packages/static-deployer-git + --package-dir packages/bin + --package-dir packages/leafee98 diff --git a/makedeb b/makedeb index 3065562..9aedecc 160000 --- a/makedeb +++ b/makedeb @@ -1 +1 @@ -Subproject commit 3065562dab1aa1fffc8e0fe3b8885acc93e3c9ad +Subproject commit 9aedecc62e9585ba1d9b88efe083b52105e0947f diff --git a/packages/dufs-bin/DEBBUILD b/packages/bin/dufs-bin/DEBBUILD similarity index 100% rename from packages/dufs-bin/DEBBUILD rename to packages/bin/dufs-bin/DEBBUILD diff --git a/packages/dufs-bin/materials/dufs.service b/packages/bin/dufs-bin/materials/dufs.service similarity index 100% rename from packages/dufs-bin/materials/dufs.service rename to packages/bin/dufs-bin/materials/dufs.service diff --git a/packages/filebrowser-bin/DEBBUILD b/packages/bin/filebrowser-bin/DEBBUILD similarity index 100% rename from packages/filebrowser-bin/DEBBUILD rename to packages/bin/filebrowser-bin/DEBBUILD diff --git a/packages/filebrowser-bin/materials/filebrowser.service b/packages/bin/filebrowser-bin/materials/filebrowser.service similarity index 100% rename from packages/filebrowser-bin/materials/filebrowser.service rename to packages/bin/filebrowser-bin/materials/filebrowser.service diff --git a/packages/forgejo-bin/DEBBUILD b/packages/bin/forgejo-bin/DEBBUILD similarity index 100% rename from packages/forgejo-bin/DEBBUILD rename to packages/bin/forgejo-bin/DEBBUILD diff --git a/packages/forgejo-bin/materials/forgejo.service b/packages/bin/forgejo-bin/materials/forgejo.service similarity index 100% rename from packages/forgejo-bin/materials/forgejo.service rename to packages/bin/forgejo-bin/materials/forgejo.service diff --git a/packages/neovim-bin/DEBBUILD b/packages/bin/neovim-bin/DEBBUILD similarity index 100% rename from packages/neovim-bin/DEBBUILD rename to packages/bin/neovim-bin/DEBBUILD diff --git a/packages/plik-bin/DEBBUILD b/packages/bin/plik-bin/DEBBUILD similarity index 100% rename from packages/plik-bin/DEBBUILD rename to packages/bin/plik-bin/DEBBUILD diff --git a/packages/plik-bin/materials/plikd.service b/packages/bin/plik-bin/materials/plikd.service similarity index 100% rename from packages/plik-bin/materials/plikd.service rename to packages/bin/plik-bin/materials/plikd.service diff --git a/packages/lemonade-git/DEBBUILD b/packages/git/lemonade-git/DEBBUILD similarity index 100% rename from packages/lemonade-git/DEBBUILD rename to packages/git/lemonade-git/DEBBUILD diff --git a/packages/apt-repo-updater/DEBBUILD b/packages/leafee98/apt-repo-updater-git/DEBBUILD similarity index 100% rename from packages/apt-repo-updater/DEBBUILD rename to packages/leafee98/apt-repo-updater-git/DEBBUILD diff --git a/packages/apt-repo-updater/materials/apt-repo-updater.service b/packages/leafee98/apt-repo-updater-git/materials/apt-repo-updater.service similarity index 100% rename from packages/apt-repo-updater/materials/apt-repo-updater.service rename to packages/leafee98/apt-repo-updater-git/materials/apt-repo-updater.service diff --git a/packages/static-deployer-git/DEBBUILD b/packages/leafee98/static-deployer-git/DEBBUILD similarity index 100% rename from packages/static-deployer-git/DEBBUILD rename to packages/leafee98/static-deployer-git/DEBBUILD diff --git a/packages/dendrite/DEBBUILD b/packages/normal/dendrite/DEBBUILD similarity index 100% rename from packages/dendrite/DEBBUILD rename to packages/normal/dendrite/DEBBUILD diff --git a/script/build_all.sh b/script/build.sh similarity index 83% rename from script/build_all.sh rename to script/build.sh index 7eecde9..94d40e4 100755 --- a/script/build_all.sh +++ b/script/build.sh @@ -14,8 +14,9 @@ function msg_warn { function usage { echo "$_PROGRAM_NAME:" - echo " --package add a dir to build, allow use it multi times" - echo " --package-dir all dir in this directory is a package" + echo " --package add a dir to build, can use multi times" + echo " --package-dir all dir in this directory is a package," + echo " can use multi times" echo " --makedeb-path specify the path of makedeb" echo " --upload-to-webdav https://webdav_host/path/dir" echo " upload built file to a webdav server" @@ -46,8 +47,13 @@ function run_hook { local exe_str="$1" local place_holder="$2" local package_name="$3" + local log_exe_str="${4-}" + local final_exe_str="${exe_str/$place_holder/$package_name}" - echo $final_exe_str + + if [[ -n "${log_exe_str}" ]] ; then + msg_info "Running: $final_exe_str" + fi $final_exe_str } @@ -77,7 +83,12 @@ while (( "$#" >= 1 )); do --upload-to-webdav) UPLOAD_TO_WEBDAV="$2" ; shift ;; --webdav-user) WEBDAV_USER="$2" ; shift ;; --webdav-pass) WEBDAV_PASS="$2" ; shift ;; - --package-exists-hook) PACKAGE_EXISTS_HOOK="$2" ; shift ;; + --package-exists-hook) + PACKAGE_EXISTS_HOOK="$2" + # strip white space, see https://stackoverflow.com/a/3352015 + PACKAGE_EXISTS_HOOK="${PACKAGE_EXISTS_HOOK#"${PACKAGE_EXISTS_HOOK%%[![:space:]]*}"}" + PACKAGE_EXISTS_HOOK="${PACKAGE_EXISTS_HOOK%"${PACKAGE_EXISTS_HOOK##*[![:space:]]}"}" + shift ;; --) shift MAKEDEB_ARGS=("$@") @@ -114,6 +125,10 @@ if [[ "${#_PACKGES_TO_BUILD[@]}" -eq 0 ]] ; then msg_info "No package to build, exiting..." fi +if [[ -n "$PACKAGE_EXISTS_HOOK" ]] ; then + msg_info "hook for checking if package exists: $PACKAGE_EXISTS_HOOK" +fi + for package in "${_PACKGES_TO_BUILD[@]}" ; do ( msg_info "$_DELIMITER" @@ -130,7 +145,8 @@ for package in "${_PACKGES_TO_BUILD[@]}" ; do if [[ -n "${PACKAGE_EXISTS_HOOK}" ]] ; then ret=0 - run_hook "$PACKAGE_EXISTS_HOOK" "{}" "$package_name" || ret="$?" + msg_info "Checking if package $package_name exists..." + run_hook "$PACKAGE_EXISTS_HOOK" "{}" "$package_name" log_exe_str || ret="$?" if [[ $ret -eq 0 ]] ; then msg_info "Package ${package_name} already built, skip" @@ -138,6 +154,8 @@ for package in "${_PACKGES_TO_BUILD[@]}" ; do fi fi + msg_info "Start building..." + "$MAKEDEB_PATH" --noextract "${MAKEDEB_ARGS[@]}" && ret=$? || ret=$? if [[ $ret -ne 0 ]] ; then msg_warn "Error occurred when running makedeb, skip this package" diff --git a/script/local_build.sh b/script/local_build.sh new file mode 100755 index 0000000..1007d7a --- /dev/null +++ b/script/local_build.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +WEBDAV_UPLOAD_TARGET=https://dufs.leafee98.com/apt/income +APT_BASE=https://dufs.leafee98.com/apt + +./script/build.sh \ + --makedeb-path makedeb/makedeb \ + --package-exists-hook " + $(realpath ./script/package_exists.py) + --filename {} + --cache-file /tmp/apt-file-exists-cache.json + --package-arch amd64 + --apt-base $APT_BASE \ + "\ + --package-dir packages/bin \ + --package-dir packages/leafee98 \ + --package-dir packages/git \ + --package-dir packages/normal \ + -- \ + -f + # --upload-to-webdav "$WEBDAV_UPLOAD_TARGET" \ + # --webdav-user "$WEBDAV_USER" \ + # --webdav-pass "$WEBDAV_PASS" \ +