Skip to content

Commit 6c8cc37

Browse files
committed
fix(upgrade): update Data Machine plugins by tag
1 parent e910210 commit 6c8cc37

4 files changed

Lines changed: 153 additions & 37 deletions

File tree

lib/data-machine.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ install_data_machine() {
2626
fi
2727
}
2828

29+
upgrade_data_machine_plugins() {
30+
if [ "$INSTALL_DATA_MACHINE" != true ]; then
31+
log "Phase 2: Skipping Data Machine plugins (--no-data-machine)"
32+
return
33+
fi
34+
35+
log "Phase 2: Updating Data Machine plugins to latest tagged releases..."
36+
update_plugin_to_latest_tag data-machine https://github.com/Extra-Chill/data-machine.git
37+
update_plugin_to_latest_tag data-machine-code https://github.com/Extra-Chill/data-machine-code.git
38+
}
39+
2940
create_dm_agent() {
3041
log "Phase 4.5: Creating Data Machine agent..."
3142

lib/wordpress.sh

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,88 @@ install_plugin() {
4747
warn "Could not pull latest $slug — check for local changes"
4848
fi
4949

50-
# Install dependencies even if plugin was pre-cloned.
51-
if [ -f "$plugin_dir/composer.json" ] && { [ ! -d "$plugin_dir/vendor" ] || [ "$DRY_RUN" = true ]; }; then
50+
install_plugin_dependencies "$slug" "$plugin_dir" false
51+
52+
activate_plugin "$slug"
53+
fix_ownership "$plugin_dir"
54+
}
55+
56+
# Install/build plugin dependencies. Set force=true after a code update so lockfile
57+
# or asset changes are applied even when vendor/node_modules already exist.
58+
install_plugin_dependencies() {
59+
local slug="$1"
60+
local plugin_dir="$2"
61+
local force="${3:-false}"
62+
63+
if [ -f "$plugin_dir/composer.json" ] && { [ "$force" = true ] || [ ! -d "$plugin_dir/vendor" ] || [ "$DRY_RUN" = true ]; }; then
5264
run_cmd env COMPOSER_ALLOW_SUPERUSER=1 composer install \
5365
--no-dev --no-interaction --working-dir="$plugin_dir" || \
5466
warn "Composer failed, some $slug features may not work"
5567
fi
56-
if [ -f "$plugin_dir/package.json" ] && { [ ! -d "$plugin_dir/node_modules" ] || [ "$DRY_RUN" = true ]; }; then
68+
if [ -f "$plugin_dir/package.json" ] && { [ "$force" = true ] || [ ! -d "$plugin_dir/node_modules" ] || [ "$DRY_RUN" = true ]; }; then
5769
log "Building $slug JS assets..."
5870
run_cmd npm install --prefix "$plugin_dir" || \
5971
warn "npm install failed for $slug"
6072
run_cmd npm run build --prefix "$plugin_dir" || \
6173
warn "npm build failed for $slug — admin pages may not work"
6274
fi
75+
}
76+
77+
# Update a git-installed plugin to its latest version tag.
78+
update_plugin_to_latest_tag() {
79+
local slug="$1"
80+
local repo_url="$2"
81+
local plugin_dir="$SITE_PATH/wp-content/plugins/$slug"
82+
83+
if [ ! -d "$plugin_dir" ]; then
84+
log "Plugin $slug missing — installing before tag checkout..."
85+
install_plugin "$slug" "$repo_url"
86+
fi
87+
88+
if [ ! -d "$plugin_dir/.git" ]; then
89+
warn "Plugin $slug is not a git checkout — skipping tagged release update"
90+
return 0
91+
fi
92+
93+
if [ "$DRY_RUN" = true ]; then
94+
echo -e "${BLUE}[dry-run]${NC} git -C $plugin_dir fetch --tags --force origin"
95+
echo -e "${BLUE}[dry-run]${NC} git -C $plugin_dir checkout --detach <latest-tag>"
96+
echo -e "${BLUE}[dry-run]${NC} Would rebuild dependencies for $slug if composer.json/package.json exist"
97+
return 0
98+
fi
99+
100+
if [ -n "$(git -C "$plugin_dir" status --porcelain 2>/dev/null)" ]; then
101+
warn "Plugin $slug has local changes — skipping tagged release update"
102+
return 0
103+
fi
104+
105+
git -C "$plugin_dir" fetch --tags --force origin || {
106+
warn "Could not fetch tags for $slug"
107+
return 0
108+
}
109+
110+
local latest_tag
111+
latest_tag=$(git -C "$plugin_dir" tag --sort=-v:refname | grep -E '^v?[0-9]' | head -n 1)
112+
if [ -z "$latest_tag" ]; then
113+
warn "No version tags found for $slug — skipping"
114+
return 0
115+
fi
116+
117+
local current_ref
118+
current_ref=$(git -C "$plugin_dir" describe --tags --exact-match 2>/dev/null || git -C "$plugin_dir" rev-parse --short HEAD)
119+
120+
if [ "$current_ref" = "$latest_tag" ]; then
121+
log "Plugin $slug already at latest tag ($latest_tag)"
122+
else
123+
log "Updating plugin $slug: $current_ref$latest_tag"
124+
git -C "$plugin_dir" checkout --detach "$latest_tag" || {
125+
warn "Could not checkout $latest_tag for $slug"
126+
return 0
127+
}
128+
UPDATED_ITEMS+=("$slug $latest_tag")
129+
fi
63130

131+
install_plugin_dependencies "$slug" "$plugin_dir" true
64132
activate_plugin "$slug"
65133
fix_ownership "$plugin_dir"
66134
}

skills/upgrade-wp-coding-agents/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ compatibility: "Requires a wp-coding-agents repo clone and an existing setup. Wo
88

99
`upgrade.sh` already auto-detects the environment, picks the chat bridge, prints a diff in dry-run, and emits the right verify + restart commands in its summary block. This skill exists for the **policy boundary** the script can't enforce on its own.
1010

11+
By default it also updates the setup-installed Data Machine plugins (`data-machine`, `data-machine-code`) to their latest version tags when those plugins are git checkouts. Use `--skip-plugins` to preserve the previous no-plugin-update behavior.
12+
1113
## When to use
1214

1315
The user says something like:
@@ -36,7 +38,7 @@ The user says something like:
3638

3739
4. **Tell the user to restart the chat bridge themselves.** Active chat sessions die on restart, so the user picks the moment.
3840

39-
Run `./upgrade.sh --help` for scope flags (`--kimaki-only`, `--skills-only`, `--agents-md-only`, `--repair-opencode-json`, etc.) and the full list of what the script touches and never touches.
41+
Run `./upgrade.sh --help` for scope flags (`--plugins-only`, `--skip-plugins`, `--kimaki-only`, `--skills-only`, `--agents-md-only`, `--repair-opencode-json`, etc.) and the full list of what the script touches and never touches.
4042

4143
## Never do
4244

0 commit comments

Comments
 (0)