-
Notifications
You must be signed in to change notification settings - Fork 1
124 lines (110 loc) · 4.84 KB
/
push.yml
File metadata and controls
124 lines (110 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Git Autodeploy CI
on:
push:
branches: ['*']
pull_request:
branches: ['*']
jobs:
build_and_run_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, dom, curl, libxml, xml, xmlreader
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php8.1-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php8.1-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run test suite
run: composer run-script test
lint-php-code:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Lint PHP code (Dry Run)
run: ./linter/lint.sh --dry-run
deploy:
runs-on: ubuntu-latest
needs: [build_and_run_tests, lint-php-code]
if: success()
steps:
- name: Self-Update All Instances
env:
AUTODEPLOY_URL: ${{ vars.AUTODEPLOY_URL }}
run: |
# Convert comma-separated URLs into array
IFS=',' read -ra URLS <<< "$AUTODEPLOY_URL"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔄 Self-updating ${#URLS[@]} instance(s)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Array to track results
declare -a RESULTS
declare -a FAILED_INSTANCES
ALL_SUCCESS=true
# Iterate over each URL
for i in "${!URLS[@]}"; do
URL="${URLS[$i]}"
# Remove whitespace
URL=$(echo "$URL" | xargs)
INSTANCE_NUM=$((i + 1))
echo "┌─────────────────────────────────────────────┐"
echo "│ Instance $INSTANCE_NUM/${#URLS[@]}: $URL"
echo "└─────────────────────────────────────────────┘"
# Call /self-update endpoint
response=$(curl -X GET \
-s -o "response_${i}.txt" -w "%{http_code}" \
--max-time 60 \
"https://${URL}/self-update" 2>&1 || echo "000")
# Check the result
if [ "$response" -ge 200 ] && [ "$response" -lt 400 ]; then
echo "✅ SUCCESS - Self-update completed (HTTP $response)"
RESULTS[$i]="✅ $URL - Self-updated (HTTP $response)"
else
echo "❌ FAILED - Self-update failed (HTTP $response)"
RESULTS[$i]="❌ $URL - Self-update failed (HTTP $response)"
FAILED_INSTANCES+=("$URL")
ALL_SUCCESS=false
fi
# Show response preview
echo ""
echo "Response preview:"
if [ -f "response_${i}.txt" ]; then
head -n 20 "response_${i}.txt" | sed 's/^/ /'
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
done
# Final summary
echo ""
echo "╔═══════════════════════════════════════════════╗"
echo "║ SELF-UPDATE SUMMARY ║"
echo "╚═══════════════════════════════════════════════╝"
echo ""
for result in "${RESULTS[@]}"; do
echo " $result"
done
echo ""
if [ "$ALL_SUCCESS" = true ]; then
echo "🎉 All instances self-updated successfully!"
exit 0
else
echo "⚠️ Some self-updates failed:"
for failed in "${FAILED_INSTANCES[@]}"; do
echo " - $failed"
done
exit 1
fi