switch gitea action to using dropshell to publish
Some checks failed
Test and Publish Templates / test-and-publish (push) Failing after 4s

This commit is contained in:
j
2025-12-28 12:18:53 +13:00
parent d07dd8236f
commit 97206507f9
2 changed files with 6 additions and 206 deletions

View File

@@ -18,51 +18,21 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
# Install sos tool for uploading # Install dropshell
curl -o /tmp/sos https://getbin.xyz/sos:latest && chmod +x /tmp/sos curl -fsSL https://getbin.xyz/dropshell-install | bash
sudo mv /tmp/sos /usr/local/bin/sos ~/.local/bin/dropshell install
# Install jq for JSON parsing # Install jq for JSON parsing
which jq || sudo apt-get update && sudo apt-get install -y jq which jq || sudo apt-get update && sudo apt-get install -y jq
# Install tar for packaging # Install tar for packaging
which tar || sudo apt-get update && sudo apt-get install -y tar which tar || sudo apt-get update && sudo apt-get install -y tar
# Install xxhash for calculating template hashes
which xxhsum || sudo apt-get update && sudo apt-get install -y xxhash
- name: Run tests - name: Run tests
run: | run: |
chmod +x test.sh chmod +x test.sh
./test.sh ./test.sh
- name: Detect changed templates
id: changes
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
chmod +x detect-changes.sh
CHANGED_TEMPLATES=$(./detect-changes.sh)
if [ -z "$CHANGED_TEMPLATES" ]; then
echo "No templates have changed"
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "Changed templates: $CHANGED_TEMPLATES"
echo "changed=true" >> $GITHUB_OUTPUT
# Store changed templates for the next step
echo "$CHANGED_TEMPLATES" > changed_templates.txt
fi
- name: Publish changed templates - name: Publish changed templates
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.changes.outputs.changed == 'true'
run: | run: |
chmod +x publish.sh SOS_WRITE_TOKEN=${{ secrets.SOS_WRITE_TOKEN }} ~/.local/bin/dropshell publish -all ./
# Publish only changed templates
SOS_WRITE_TOKEN=${{ secrets.SOS_WRITE_TOKEN }} \
./publish.sh --changed-only
- name: Update versions after successful publish
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.changes.outputs.changed == 'true'
run: |
# This step would normally commit the updated versions.json
# But we'll leave this for manual version bumping
echo "Templates published successfully. Consider bumping versions in versions.json for the changed templates."

View File

@@ -1,170 +0,0 @@
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR"
# Detect architecture
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
ARCH="x86_64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
ARCH="aarch64"
else
echo "WARNING: Unknown architecture: $ARCH, defaulting to x86_64" >&2
ARCH="x86_64"
fi
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"
# Create temporary directory for packaging
TMPDIR=$(mktemp -d)
trap "rm -rf $TMPDIR" EXIT
# Always download the latest sos to ensure compatibility
info "Downloading latest sos utility..."
SOS_BIN="$TMPDIR/sos"
curl -L -o "$SOS_BIN" "https://getbin.xyz/sos:latest-$ARCH" 2>/dev/null || die "Failed to download sos"
chmod +x "$SOS_BIN"
info "sos downloaded successfully"
# 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
# Download dshash if not available
if ! which dshash >/dev/null 2>&1; then
info "Downloading dshash utility..."
DSHASH_BIN="$TMPDIR/dshash"
curl -L -o "$DSHASH_BIN" "https://getbin.xyz/dshash:latest-$ARCH" 2>/dev/null || die "Failed to download dshash"
chmod +x "$DSHASH_BIN"
info "dshash downloaded successfully"
else
DSHASH_BIN="dshash"
fi
# 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)"
# Calculate SHA256 hash of the template directory
info "Calculating SHA256 for $TEMPLATE"
SHA256_HASH=$("$DSHASH_BIN" "$TEMPLATE")
info "SHA256 for $TEMPLATE: $SHA256_HASH"
# Upload to templates.dropshell.app using sos
info "Uploading $TEMPLATE to templates.dropshell.app"
# Always upload with :latest tag
"$SOS_BIN" upload templates.dropshell.app "$TARBALL" "${TEMPLATE}:latest" --metadata "unpackedhash=$SHA256_HASH" || die "Failed to upload $TEMPLATE:latest"
info "Uploaded ${TEMPLATE}:latest"
# Also upload with specific version tag
"$SOS_BIN" upload templates.dropshell.app "$TARBALL" "${TEMPLATE}:${VERSION}" --metadata "unpackedhash=$SHA256_HASH" || 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_BIN" upload templates.dropshell.app "$TARBALL" "${TEMPLATE}:v${MAJOR_VERSION}" --metadata "unpackedhash=$SHA256_HASH" || 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!"