Add 7 and update 2 files
Some checks failed
Test and Publish Templates / test-and-publish (push) Failing after 14s
Some checks failed
Test and Publish Templates / test-and-publish (push) Failing after 14s
This commit is contained in:
139
publish.sh
Executable file
139
publish.sh
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
function die() {
|
||||
echo "ERROR: $1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
function info() {
|
||||
echo "INFO: $1"
|
||||
}
|
||||
|
||||
function get_version() {
|
||||
local template="$1"
|
||||
if [ -f "versions.json" ]; then
|
||||
# Use jq if available, otherwise use python
|
||||
if which jq >/dev/null 2>&1; then
|
||||
jq -r ".\"$template\" // \"1.0.0\"" versions.json
|
||||
elif which python3 >/dev/null 2>&1; then
|
||||
python3 -c "import json; data=json.load(open('versions.json')); print(data.get('$template', '1.0.0'))"
|
||||
else
|
||||
echo "1.0.0"
|
||||
fi
|
||||
else
|
||||
echo "1.0.0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
PUBLISH_ALL=false
|
||||
TEMPLATES_TO_PUBLISH=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--all)
|
||||
PUBLISH_ALL=true
|
||||
shift
|
||||
;;
|
||||
--changed-only)
|
||||
# Detect changed templates
|
||||
if [ -x "./detect-changes.sh" ]; then
|
||||
TEMPLATES_TO_PUBLISH=$(./detect-changes.sh)
|
||||
if [ -z "$TEMPLATES_TO_PUBLISH" ]; then
|
||||
info "No templates have changed, nothing to publish"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
die "detect-changes.sh not found or not executable"
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
# Assume it's a specific template name
|
||||
TEMPLATES_TO_PUBLISH="$TEMPLATES_TO_PUBLISH $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if SOS_WRITE_TOKEN is set
|
||||
[[ -n $SOS_WRITE_TOKEN ]] || die "SOS_WRITE_TOKEN environment variable not set"
|
||||
|
||||
# Check if sos is installed
|
||||
which sos >/dev/null || die "sos tool not found. Please install it first."
|
||||
|
||||
# If no specific templates specified and not --all, default to changed templates
|
||||
if [ -z "$TEMPLATES_TO_PUBLISH" ] && [ "$PUBLISH_ALL" = false ]; then
|
||||
if [ -x "./detect-changes.sh" ]; then
|
||||
TEMPLATES_TO_PUBLISH=$(./detect-changes.sh)
|
||||
if [ -z "$TEMPLATES_TO_PUBLISH" ]; then
|
||||
info "No templates have changed, nothing to publish"
|
||||
exit 0
|
||||
fi
|
||||
info "Publishing changed templates: $(echo $TEMPLATES_TO_PUBLISH | tr '\n' ' ')"
|
||||
else
|
||||
# Fallback to all templates if detect-changes.sh doesn't exist
|
||||
PUBLISH_ALL=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get list of templates to publish
|
||||
if [ "$PUBLISH_ALL" = true ]; then
|
||||
TEMPLATES_TO_PUBLISH=$(find . -maxdepth 1 -type d ! -name ".*" ! -name "." | sed 's|^\./||' | grep -v ".gitea")
|
||||
info "Publishing all templates: $(echo $TEMPLATES_TO_PUBLISH | tr '\n' ' ')"
|
||||
fi
|
||||
|
||||
if [ -z "$TEMPLATES_TO_PUBLISH" ]; then
|
||||
die "No templates found to publish"
|
||||
fi
|
||||
|
||||
# Create temporary directory for packaging
|
||||
TMPDIR=$(mktemp -d)
|
||||
trap "rm -rf $TMPDIR" EXIT
|
||||
|
||||
# Package and upload each template
|
||||
for TEMPLATE in $TEMPLATES_TO_PUBLISH; do
|
||||
if [ ! -f "$TEMPLATE/install.sh" ]; then
|
||||
info "Skipping $TEMPLATE (no install.sh found)"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Get the version for this template
|
||||
VERSION=$(get_version "$TEMPLATE")
|
||||
info "Packaging template: $TEMPLATE (version: $VERSION)"
|
||||
|
||||
# Create tarball of the template
|
||||
TARBALL="$TMPDIR/${TEMPLATE}.tgz"
|
||||
tar -czf "$TARBALL" -C . "$TEMPLATE"
|
||||
|
||||
# Calculate file size for info
|
||||
SIZE=$(du -h "$TARBALL" | cut -f1)
|
||||
info "Created $TEMPLATE.tgz ($SIZE)"
|
||||
|
||||
# Upload to templates.dropshell.app using sos
|
||||
info "Uploading $TEMPLATE to templates.dropshell.app"
|
||||
|
||||
# Always upload with :latest tag
|
||||
sos templates.dropshell.app "$TARBALL" "${TEMPLATE}:latest" || die "Failed to upload $TEMPLATE:latest"
|
||||
info "Uploaded ${TEMPLATE}:latest"
|
||||
|
||||
# Also upload with specific version tag
|
||||
sos templates.dropshell.app "$TARBALL" "${TEMPLATE}:${VERSION}" || die "Failed to upload $TEMPLATE:${VERSION}"
|
||||
info "Uploaded ${TEMPLATE}:${VERSION}"
|
||||
|
||||
# If we have a major version, also tag with major version only (e.g., v1)
|
||||
MAJOR_VERSION=$(echo "$VERSION" | cut -d. -f1)
|
||||
if [ -n "$MAJOR_VERSION" ]; then
|
||||
sos templates.dropshell.app "$TARBALL" "${TEMPLATE}:v${MAJOR_VERSION}" || die "Failed to upload $TEMPLATE:v${MAJOR_VERSION}"
|
||||
info "Uploaded ${TEMPLATE}:v${MAJOR_VERSION}"
|
||||
fi
|
||||
|
||||
info "Successfully uploaded $TEMPLATE"
|
||||
done
|
||||
|
||||
info "All selected templates published successfully!"
|
Reference in New Issue
Block a user