Skip to content

Commit 2ba9918

Browse files
committed
feat(actions): prefix backup filename with juju app and hostname
- Updated `actions/backup` to prepend the application name (extracted from `JUJU_UNIT_NAME`) and the machine's `hostname` to the backup tarball filename. - Added a `test-backup` job in `.github/workflows/test.yaml` to deploy the charm, execute the backup action, and verify the resulting file prefix correctly matches the `{app}-{hostname}-openclaw-backup-` format.
1 parent 3b0b884 commit 2ba9918

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

.github/workflows/test.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,3 +2274,92 @@ jobs:
22742274
run: |
22752275
juju destroy-model test-system-upgrade -y --force --no-wait || true
22762276
juju destroy-controller test-controller -y --destroy-all-models --force --no-wait || true
2277+
2278+
test-backup:
2279+
name: Test Backup Action
2280+
runs-on: ubuntu-24.04
2281+
needs: build
2282+
steps:
2283+
- name: Checkout code
2284+
uses: actions/checkout@v6
2285+
2286+
- name: Download charm artifact
2287+
uses: actions/download-artifact@v8
2288+
with:
2289+
name: openclaw-charm
2290+
2291+
- name: Set up LXD
2292+
uses: canonical/setup-lxd@main
2293+
with:
2294+
channel: latest/stable
2295+
2296+
- name: Install Juju
2297+
run: |
2298+
sudo snap install juju --channel=3/stable
2299+
sudo snap install juju-wait --classic
2300+
2301+
- name: Bootstrap Juju
2302+
run: |
2303+
lxc network set lxdbr0 ipv6.address none
2304+
juju bootstrap localhost test-controller
2305+
2306+
- name: Create test model
2307+
run: |
2308+
juju add-model test-backup
2309+
2310+
- name: Deploy charm
2311+
run: |
2312+
CHARM_FILE=$(ls openclaw_*.charm | head -1)
2313+
juju deploy ./$CHARM_FILE \
2314+
--config ai-provider="anthropic" \
2315+
--config ai-model="claude-sonnet-3-5" \
2316+
--config ai-api-key="test-key"
2317+
2318+
- name: Wait for deployment
2319+
run: |
2320+
juju-wait -v -m test-backup -t 900
2321+
2322+
- name: Run backup action and verify filename
2323+
run: |
2324+
# Run the backup action
2325+
OUTPUT=$(juju run openclaw/leader backup --format=json)
2326+
echo "Action Output: $OUTPUT"
2327+
2328+
# Extract backup-file from action output
2329+
BACKUP_FILE=$(echo "$OUTPUT" | jq -r '.. | .results? | select(. != null) | ."backup-file"')
2330+
2331+
if [ -z "$BACKUP_FILE" ] || [ "$BACKUP_FILE" = "null" ]; then
2332+
echo "✗ Failed to extract backup-file from action output"
2333+
exit 1
2334+
fi
2335+
2336+
echo "Generated backup file: $BACKUP_FILE"
2337+
2338+
# Verify filename prefix
2339+
APP_NAME="openclaw"
2340+
HOST_NAME=$(juju ssh openclaw/leader 'hostname' | tr -d '\r\n')
2341+
2342+
EXPECTED_PREFIX="${APP_NAME}-${HOST_NAME}-openclaw-backup-"
2343+
BASENAME=$(basename "$BACKUP_FILE")
2344+
2345+
if echo "$BASENAME" | grep -q "^$EXPECTED_PREFIX"; then
2346+
echo "✓ Backup filename has the correct prefix: $EXPECTED_PREFIX"
2347+
else
2348+
echo "✗ Backup filename ($BASENAME) does not have expected prefix ($EXPECTED_PREFIX)"
2349+
exit 1
2350+
fi
2351+
2352+
- name: Collect logs on failure
2353+
if: failure()
2354+
run: |
2355+
echo "=== Juju Status ==="
2356+
juju status --format=yaml
2357+
2358+
echo "=== Debug Log ==="
2359+
juju debug-log --replay --no-tail --limit 500
2360+
2361+
- name: Cleanup
2362+
if: always()
2363+
run: |
2364+
juju destroy-model test-backup -y --force --no-wait || true
2365+
juju destroy-controller test-controller -y --destroy-all-models --force --no-wait || true

actions/backup

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ FORCE="$(action-get force || echo "false")"
1111

1212
# Generate timestamp for backup filename
1313
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
14-
BACKUP_FILENAME="openclaw-backup-${TIMESTAMP}.tar.gz"
14+
APP_NAME="${JUJU_UNIT_NAME%%/*}"
15+
APP_NAME="${APP_NAME:-openclaw}"
16+
HOST_NAME=$(hostname)
17+
BACKUP_FILENAME="${APP_NAME}-${HOST_NAME}-openclaw-backup-${TIMESTAMP}.tar.gz"
1518
BACKUP_FILE="${OUTPUT_PATH}/${BACKUP_FILENAME}"
1619

1720
# OpenClaw data directory

0 commit comments

Comments
 (0)