thepopebot 1.2.48 → 1.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -12,38 +12,104 @@ jobs:
|
|
|
12
12
|
deploy:
|
|
13
13
|
runs-on: self-hosted
|
|
14
14
|
steps:
|
|
15
|
-
- name:
|
|
15
|
+
- name: Pull latest and detect version change
|
|
16
|
+
id: pull
|
|
16
17
|
run: |
|
|
17
18
|
docker exec thepopebot-event-handler bash -c '
|
|
18
|
-
# Load GH_TOKEN and authenticate git via GitHub CLI
|
|
19
19
|
export GH_TOKEN=$(grep "^GH_TOKEN=" /app/.env | cut -d= -f2-)
|
|
20
20
|
echo "${GH_TOKEN}" | gh auth login --with-token
|
|
21
21
|
gh auth setup-git
|
|
22
22
|
|
|
23
|
-
# Check if there are code changes (not just logs)
|
|
24
23
|
git fetch origin main
|
|
25
24
|
CHANGED=$(git diff --name-only HEAD origin/main)
|
|
26
25
|
if ! echo "$CHANGED" | grep -qv "^logs/"; then
|
|
27
|
-
echo "
|
|
26
|
+
echo "SKIP" > /app/.rebuild-status
|
|
28
27
|
git reset --hard origin/main
|
|
29
28
|
exit 0
|
|
30
29
|
fi
|
|
31
30
|
|
|
32
|
-
#
|
|
31
|
+
# Detect thepopebot version change from package-lock.json in git
|
|
32
|
+
git show HEAD:package-lock.json > /tmp/old-lock.json 2>/dev/null || echo "{}" > /tmp/old-lock.json
|
|
33
|
+
git show origin/main:package-lock.json > /tmp/new-lock.json
|
|
34
|
+
OLD_TPB=$(node -p "try{require(\"/tmp/old-lock.json\").packages[\"node_modules/thepopebot\"]?.version||\"\"}catch(e){\"\"}")
|
|
35
|
+
NEW_TPB=$(node -p "try{require(\"/tmp/new-lock.json\").packages[\"node_modules/thepopebot\"]?.version||\"\"}catch(e){\"\"}")
|
|
36
|
+
rm -f /tmp/old-lock.json /tmp/new-lock.json
|
|
37
|
+
|
|
33
38
|
git reset --hard origin/main
|
|
34
|
-
npm install --omit=dev
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
if [ -n "$OLD_TPB" ] && [ "$OLD_TPB" != "$NEW_TPB" ]; then
|
|
41
|
+
# Version changed — run thepopebot init to scaffold new templates
|
|
42
|
+
npx thepopebot init
|
|
43
|
+
npm install --omit=dev
|
|
44
|
+
|
|
45
|
+
# Commit any template changes from init
|
|
46
|
+
git add -A
|
|
47
|
+
if ! git diff --cached --quiet; then
|
|
48
|
+
git commit -m "chore: apply thepopebot init after upgrade"
|
|
49
|
+
git push origin main
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Update THEPOPEBOT_VERSION in .env so docker compose pulls the right image
|
|
53
|
+
if grep -q "^THEPOPEBOT_VERSION=" /app/.env; then
|
|
54
|
+
sed -i "s/^THEPOPEBOT_VERSION=.*/THEPOPEBOT_VERSION=$NEW_TPB/" /app/.env
|
|
55
|
+
else
|
|
56
|
+
echo "THEPOPEBOT_VERSION=$NEW_TPB" >> /app/.env
|
|
57
|
+
fi
|
|
58
|
+
echo "VERSION_CHANGED" > /app/.rebuild-status
|
|
59
|
+
else
|
|
60
|
+
npm install --omit=dev
|
|
61
|
+
echo "REBUILD" > /app/.rebuild-status
|
|
62
|
+
fi
|
|
63
|
+
'
|
|
64
|
+
|
|
65
|
+
STATUS=$(docker exec thepopebot-event-handler cat /app/.rebuild-status)
|
|
66
|
+
docker exec thepopebot-event-handler rm -f /app/.rebuild-status
|
|
67
|
+
echo "status=$STATUS" >> $GITHUB_OUTPUT
|
|
68
|
+
|
|
69
|
+
- name: Rebuild (no version change)
|
|
70
|
+
if: steps.pull.outputs.status == 'REBUILD'
|
|
71
|
+
run: |
|
|
72
|
+
docker exec thepopebot-event-handler bash -c '
|
|
37
73
|
rm -rf .next-new .next-old
|
|
38
74
|
NEXT_BUILD_DIR=.next-new npm run build
|
|
39
75
|
|
|
40
|
-
# Atomic swap: old .next keeps serving until pm2 reload
|
|
41
76
|
mv .next .next-old 2>/dev/null || true
|
|
42
77
|
mv .next-new .next
|
|
43
78
|
|
|
44
79
|
echo "Rebuild complete, reloading Next.js..."
|
|
45
80
|
npx pm2 reload all
|
|
46
81
|
|
|
47
|
-
|
|
82
|
+
rm -rf .next-old
|
|
83
|
+
'
|
|
84
|
+
|
|
85
|
+
- name: Pull new image and restart container
|
|
86
|
+
if: steps.pull.outputs.status == 'VERSION_CHANGED'
|
|
87
|
+
run: |
|
|
88
|
+
cd /project
|
|
89
|
+
docker compose pull event-handler
|
|
90
|
+
docker compose up -d event-handler
|
|
91
|
+
|
|
92
|
+
- name: Rebuild in new container
|
|
93
|
+
if: steps.pull.outputs.status == 'VERSION_CHANGED'
|
|
94
|
+
run: |
|
|
95
|
+
echo "Waiting for new container..."
|
|
96
|
+
for i in $(seq 1 30); do
|
|
97
|
+
if docker exec thepopebot-event-handler echo "ready" 2>/dev/null; then
|
|
98
|
+
break
|
|
99
|
+
fi
|
|
100
|
+
sleep 2
|
|
101
|
+
done
|
|
102
|
+
|
|
103
|
+
docker exec thepopebot-event-handler bash -c '
|
|
104
|
+
npm install --omit=dev
|
|
105
|
+
|
|
106
|
+
rm -rf .next-new .next-old
|
|
107
|
+
NEXT_BUILD_DIR=.next-new npm run build
|
|
108
|
+
|
|
109
|
+
mv .next .next-old 2>/dev/null || true
|
|
110
|
+
mv .next-new .next
|
|
111
|
+
|
|
112
|
+
npx pm2 reload all
|
|
113
|
+
|
|
48
114
|
rm -rf .next-old
|
|
49
115
|
'
|
|
@@ -13,32 +13,31 @@ jobs:
|
|
|
13
13
|
steps:
|
|
14
14
|
- name: Upgrade thepopebot
|
|
15
15
|
run: |
|
|
16
|
-
# Phase 1: Update package and build (but don't swap yet)
|
|
17
16
|
docker exec thepopebot-event-handler bash -c '
|
|
18
17
|
export GH_TOKEN=$(grep "^GH_TOKEN=" /app/.env | cut -d= -f2-)
|
|
19
18
|
echo "${GH_TOKEN}" | gh auth login --with-token
|
|
20
19
|
gh auth setup-git
|
|
21
20
|
|
|
22
|
-
git
|
|
23
|
-
|
|
21
|
+
REPO_URL=$(git -C /app remote get-url origin)
|
|
22
|
+
WORK_DIR=$(mktemp -d)
|
|
23
|
+
git clone --depth 1 "$REPO_URL" "$WORK_DIR"
|
|
24
|
+
cd "$WORK_DIR"
|
|
24
25
|
|
|
26
|
+
npm install
|
|
25
27
|
npm update thepopebot
|
|
26
|
-
npx thepopebot init
|
|
27
|
-
npm install --omit=dev
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
rm -rf .next-old
|
|
29
|
+
git add -A
|
|
30
|
+
if ! git diff --cached --quiet; then
|
|
31
|
+
VERSION=$(node -p "require('./node_modules/thepopebot/package.json').version")
|
|
32
|
+
BRANCH="upgrade/thepopebot-${VERSION}-$(date +%s)"
|
|
33
|
+
git checkout -b "$BRANCH"
|
|
34
|
+
git commit -m "chore: upgrade thepopebot"
|
|
35
|
+
git push origin "$BRANCH"
|
|
36
|
+
gh pr create --title "chore: upgrade thepopebot" --body "Automated upgrade via upgrade-event-handler workflow." --base main --head "$BRANCH"
|
|
37
|
+
gh pr merge "$BRANCH" --squash --auto --delete-branch
|
|
38
|
+
else
|
|
39
|
+
echo "No changes — thepopebot is already up to date."
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
rm -rf "$WORK_DIR"
|
|
44
43
|
'
|