create-deb.sh: move to scripts, add download-and-upload-debs.sh
Some checks failed
Build and test / check (push) Successful in 1m42s
Build and test / build (push) Successful in 2m55s
Build and test / check-license (push) Successful in 1m30s
Build and test / test (push) Successful in 3m5s
Build and test / docs (push) Has been cancelled

This commit is contained in:
2025-12-16 16:38:17 +09:00
parent 62b2b30f94
commit 21bb5b62ff
4 changed files with 71 additions and 2 deletions

50
scripts/create-deb.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
set -euo pipefail
declare -r RUST_PROFILE="release-lto"
if [[ "${CREATE_DEB_DEBUG:-}" == "1" ]]; then
set -x
fi
if ! command -v cargo &> /dev/null; then
echo "cargo could not be found" >&2
exit 1
fi
if ! command -v cargo-deb &> /dev/null; then
echo "cargo-deb could not be found" >&2
exit 1
fi
cargo build --profile "$RUST_PROFILE"
mkdir -p assets/completions
(
PATH="./target/$RUST_PROFILE:$PATH"
COMPLETE=bash muscl > assets/completions/muscl.bash
COMPLETE=zsh muscl > assets/completions/_muscl
COMPLETE=fish muscl > assets/completions/muscl.fish
COMPLETE=bash mysql-dbadm > assets/completions/mysql-dbadm.bash
COMPLETE=zsh mysql-dbadm > assets/completions/_mysql-dbadm
COMPLETE=fish mysql-dbadm > assets/completions/mysql-dbadm.fish
COMPLETE=bash mysql-useradm > assets/completions/mysql-useradm.bash
COMPLETE=zsh mysql-useradm > assets/completions/_mysql-useradm
COMPLETE=fish mysql-useradm > assets/completions/mysql-useradm.fish
)
# See https://github.com/clap-rs/clap/issues/1764
sed -i 's/muscl/mysql-dbadm/g' assets/completions/{mysql-dbadm.bash,mysql-dbadm.fish,_mysql-dbadm}
sed -i 's/muscl/mysql-useradm/g' assets/completions/{mysql-useradm.bash,mysql-useradm.fish,_mysql-useradm}
DEFAULT_CARGO_DEB_ARGS=(
--profile "$RUST_PROFILE"
--no-build
)
cargo deb "${DEFAULT_CARGO_DEB_ARGS[@]}" "$@"

View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ "${CREATE_DEB_DEBUG:-}" == "1" ]]; then
set -x
fi
declare -a COMMANDS=(
curl
unzip
mktemp
find
)
for cmd in "${COMMANDS[@]}"; do
if ! command -v "$cmd" &> /dev/null; then
echo "$cmd could not be found" >&2
exit 1
fi
done
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <gitea-run-number> <git-sha>" >&2
echo "Example:" >&2
echo " GITEA_USER=me GITEA_TOKEN=secret ./scripts/download-and-upload-debs.sh 123 \$(git rev-parse HEAD)" >&2
exit 1
fi
if [ -z "${GITEA_USER:-}" ]; then
echo "GITEA_USER is not set" >&2
exit 1
fi
if [ -z "${GITEA_TOKEN:-}" ]; then
echo "GITEA_TOKEN is not set" >&2
exit 1
fi
declare -r RUN_NUMBER="$1"
declare -r GIT_SHA="$2"
TMPDIR="$(mktemp -d)"
for variant in debian-bookworm debian-trixie ubuntu-jammy ubuntu-noble; do
echo "Downloading and uploading debs for variant: $variant"
curl "https://git.pvv.ntnu.no/Projects/muscl/actions/runs/$RUN_NUMBER/artifacts/muscl-deb-$variant-$GIT_SHA.zip" --output "$TMPDIR/muscl-deb-$variant-$GIT_SHA.zip"
unzip "$TMPDIR/muscl-deb-$variant-$GIT_SHA.zip" -d "$TMPDIR/muscl-deb-$variant-$GIT_SHA"
DISTRO_VERSION_NAME="$(echo "$variant" | cut -d'-' -f2)"
DEB_NAME=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f1 | head -n1)
DEB_VERSION=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f2 | head -n1)
DEB_ARCH=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f3 | cut -d'.' -f1 | head -n1)
curl \
-X DELETE \
--user "$GITEA_USER:$GITEA_TOKEN" \
"https://git.pvv.ntnu.no/api/packages/Projects/debian/pool/$DISTRO_VERSION_NAME/main/$DEB_NAME/$DEB_VERSION/$DEB_ARCH"
curl \
-X PUT \
--user "$GITEA_USER:$GITEA_TOKEN" \
--upload-file "$TMPDIR/muscl-deb-$variant-$GIT_SHA/${DEB_NAME}_${DEB_VERSION}_${DEB_ARCH}.deb" \
"https://git.pvv.ntnu.no/api/packages/Projects/debian/pool/$DISTRO_VERSION_NAME/main/upload"
done
rm -rf "$TMPDIR"