Skip to content

Commit 0c1e604

Browse files
committed
Update update-entitlements-db.yml
1 parent f995eb2 commit 0c1e604

File tree

1 file changed

+175
-35
lines changed

1 file changed

+175
-35
lines changed

.github/workflows/update-entitlements-db.yml

Lines changed: 175 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ on:
44
schedule:
55
- cron: '0 19 * * *' # daily at 11:00 PST (19:00 UTC)
66
workflow_dispatch:
7+
inputs:
8+
force_update:
9+
description: 'Force update even if no new IPSWs detected'
10+
required: false
11+
default: false
12+
type: boolean
13+
platforms:
14+
description: 'Platforms to check (comma-separated: ios,macos)'
15+
required: false
16+
default: 'ios,macos'
17+
type: string
718

819
jobs:
920
update-entitlements-db:
@@ -19,59 +30,188 @@ jobs:
1930
run: |
2031
go build -o ipsw ./cmd/ipsw
2132
22-
- name: Determine latest IPSW URL
23-
id: get-ipsw
33+
- name: Determine latest IPSW URLs
34+
id: get-ipsws
2435
run: |
25-
# Get the latest IPSW URL
26-
echo "CURRENT_IPSW_URL=$(./ipsw dl ipsw --device iPhone17,1 --latest --urls)" >> $GITHUB_ENV
36+
# Determine which platforms to check
37+
PLATFORMS="${{ github.event.inputs.platforms || 'ios,macos' }}"
38+
echo "Checking platforms: $PLATFORMS"
39+
40+
# Function to get latest IPSW URL for a platform
41+
get_ipsw_url() {
42+
local device="$1"
43+
local platform_name="$2"
44+
echo "Checking $platform_name ($device)..."
45+
46+
# Try to get latest IPSW URL, handle errors gracefully
47+
url=$(./ipsw dl ipsw --device "$device" --latest --urls 2>/dev/null | head -1 || echo "")
48+
49+
if [ -n "$url" ] && [ "$url" != "null" ]; then
50+
echo "Found $platform_name IPSW: $url"
51+
echo "$url"
52+
else
53+
echo "No $platform_name IPSW found for device $device"
54+
echo ""
55+
fi
56+
}
57+
58+
# Initialize URLs
59+
IOS_URL=""
60+
MACOS_URL=""
61+
62+
# Check each requested platform
63+
if echo "$PLATFORMS" | grep -q "ios"; then
64+
IOS_URL=$(get_ipsw_url "iPhone17,1" "iOS")
65+
fi
66+
67+
if echo "$PLATFORMS" | grep -q "macos"; then
68+
MACOS_URL=$(get_ipsw_url "Mac15,3" "macOS")
69+
fi
70+
71+
# Export URLs to environment
72+
echo "IOS_URL=$IOS_URL" >> $GITHUB_ENV
73+
echo "MACOS_URL=$MACOS_URL" >> $GITHUB_ENV
2774
28-
- name: Check for new IPSW
29-
id: check-ipsw
75+
- name: Check for new IPSWs
76+
id: check-ipsws
3077
run: |
31-
LAST=$(jq -r '.latest_ipsw.url // ""' hack/.watch_cache)
32-
echo "Last cached IPSW URL: $LAST"
33-
echo "Current IPSW URL: $CURRENT_IPSW_URL"
34-
if [ "$LAST" = "$CURRENT_IPSW_URL" ]; then
35-
echo "No new IPSW found; skipping"
36-
echo "should_update=false" >> $GITHUB_OUTPUT
78+
# Get cached URLs
79+
LAST_IOS=$(jq -r '.latest_ipsw.ios_url // ""' hack/.watch_cache)
80+
LAST_MACOS=$(jq -r '.latest_ipsw.macos_url // ""' hack/.watch_cache)
81+
82+
echo "=== Cached URLs ==="
83+
echo "iOS: $LAST_IOS"
84+
echo "macOS: $LAST_MACOS"
85+
86+
echo "=== Current URLs ==="
87+
echo "iOS: $IOS_URL"
88+
echo "macOS: $MACOS_URL"
89+
90+
# Check for changes
91+
SHOULD_UPDATE_IOS="false"
92+
SHOULD_UPDATE_MACOS="false"
93+
SHOULD_UPDATE_ANY="false"
94+
95+
if [ -n "$IOS_URL" ] && [ "$LAST_IOS" != "$IOS_URL" ]; then
96+
echo "iOS IPSW changed: $LAST_IOS -> $IOS_URL"
97+
SHOULD_UPDATE_IOS="true"
98+
SHOULD_UPDATE_ANY="true"
99+
fi
100+
101+
if [ -n "$MACOS_URL" ] && [ "$LAST_MACOS" != "$MACOS_URL" ]; then
102+
echo "macOS IPSW changed: $LAST_MACOS -> $MACOS_URL"
103+
SHOULD_UPDATE_MACOS="true"
104+
SHOULD_UPDATE_ANY="true"
105+
fi
106+
107+
# Force update if requested
108+
if [ "${{ github.event.inputs.force_update }}" = "true" ]; then
109+
echo "Force update requested"
110+
SHOULD_UPDATE_ANY="true"
111+
if [ -n "$IOS_URL" ]; then SHOULD_UPDATE_IOS="true"; fi
112+
if [ -n "$MACOS_URL" ]; then SHOULD_UPDATE_MACOS="true"; fi
113+
fi
114+
115+
# Export update flags
116+
echo "should_update_ios=$SHOULD_UPDATE_IOS" >> $GITHUB_OUTPUT
117+
echo "should_update_macos=$SHOULD_UPDATE_MACOS" >> $GITHUB_OUTPUT
118+
echo "should_update_any=$SHOULD_UPDATE_ANY" >> $GITHUB_OUTPUT
119+
120+
if [ "$SHOULD_UPDATE_ANY" = "true" ]; then
121+
echo "Will proceed with database updates"
37122
else
38-
echo "New IPSW found; proceeding with update"
39-
echo "should_update=true" >> $GITHUB_OUTPUT
123+
echo "No new IPSWs found; skipping updates"
40124
fi
41125
42-
- name: Download IPSW
43-
if: steps.check-ipsw.outputs.should_update == 'true'
126+
- name: Download IPSWs
127+
if: steps.check-ipsws.outputs.should_update_any == 'true'
44128
run: |
45-
echo "Downloading IPSW: $CURRENT_IPSW_URL"
46-
curl -L "$CURRENT_IPSW_URL" -o latest.ipsw
47-
echo "IPSW downloaded: $(ls -lh latest.ipsw)"
129+
echo "Downloading new IPSWs..."
130+
131+
# Download iOS IPSW
132+
if [ "${{ steps.check-ipsws.outputs.should_update_ios }}" = "true" ] && [ -n "$IOS_URL" ]; then
133+
echo "Downloading iOS IPSW: $IOS_URL"
134+
curl -L "$IOS_URL" -o ios_latest.ipsw
135+
echo "iOS IPSW downloaded: $(ls -lh ios_latest.ipsw)"
136+
fi
137+
138+
# Download macOS IPSW
139+
if [ "${{ steps.check-ipsws.outputs.should_update_macos }}" = "true" ] && [ -n "$MACOS_URL" ]; then
140+
echo "Downloading macOS IPSW: $MACOS_URL"
141+
curl -L "$MACOS_URL" -o macos_latest.ipsw
142+
echo "macOS IPSW downloaded: $(ls -lh macos_latest.ipsw)"
143+
fi
48144
49145
- name: Update entitlements database
50-
if: steps.check-ipsw.outputs.should_update == 'true'
146+
if: steps.check-ipsws.outputs.should_update_any == 'true'
51147
run: |
52-
echo "Updating Supabase entitlements database..."
53-
./ipsw ent \
54-
--pg-host ${{ secrets.SUPABASE_HOST }} \
55-
--pg-port 6543 \
56-
--pg-user postgres \
57-
--pg-password "${{ secrets.SUPABASE_PASSWORD }}" \
58-
--pg-database postgres \
59-
--pg-sslmode require \
60-
--ipsw latest.ipsw
61-
echo "Database update completed successfully"
148+
echo "Updating Supabase entitlements database with replacement support..."
149+
150+
# Function to update database for a platform
151+
update_platform() {
152+
local platform="$1"
153+
local ipsw_file="$2"
154+
155+
if [ -f "$ipsw_file" ]; then
156+
echo "Processing $platform IPSW: $ipsw_file"
157+
./ipsw ent \
158+
--pg-host ${{ secrets.SUPABASE_HOST }} \
159+
--pg-port 6543 \
160+
--pg-user postgres \
161+
--pg-password "${{ secrets.SUPABASE_PASSWORD }}" \
162+
--pg-database postgres \
163+
--pg-sslmode require \
164+
--ipsw "$ipsw_file" \
165+
--replace
166+
echo "$platform database update completed successfully"
167+
else
168+
echo "Skipping $platform (no IPSW file: $ipsw_file)"
169+
fi
170+
}
171+
172+
# Process each platform that needs updating
173+
if [ "${{ steps.check-ipsws.outputs.should_update_ios }}" = "true" ]; then
174+
update_platform "iOS" "ios_latest.ipsw"
175+
fi
176+
177+
if [ "${{ steps.check-ipsws.outputs.should_update_macos }}" = "true" ]; then
178+
update_platform "macOS" "macos_latest.ipsw"
179+
fi
180+
181+
echo "All database updates completed successfully"
62182
63183
- name: Update cache and commit
64-
if: steps.check-ipsw.outputs.should_update == 'true'
184+
if: steps.check-ipsws.outputs.should_update_any == 'true'
65185
run: |
66-
# Update the cache file with the new IPSW URL
67-
jq --arg url "$CURRENT_IPSW_URL" '.latest_ipsw = {"url": $url}' hack/.watch_cache > hack/.watch_cache.tmp
186+
# Update the cache file with new IPSW URLs
187+
echo "Updating cache with new IPSW URLs..."
188+
189+
# Create temporary cache with current URLs
190+
jq --arg ios_url "$IOS_URL" \
191+
--arg macos_url "$MACOS_URL" \
192+
'.latest_ipsw = {
193+
"ios_url": (if $ios_url != "" then $ios_url else .latest_ipsw.ios_url // "" end),
194+
"macos_url": (if $macos_url != "" then $macos_url else .latest_ipsw.macos_url // "" end),
195+
"url": (if $ios_url != "" then $ios_url else .latest_ipsw.url // "" end)
196+
}' hack/.watch_cache > hack/.watch_cache.tmp
68197
mv hack/.watch_cache.tmp hack/.watch_cache
69198
70199
# Configure git
71200
git config --local user.name "github-actions[bot]"
72201
git config --local user.email "github-actions[bot]@users.noreply.github.com"
73202
74-
# Commit only the cache file (no more SQLite DB to commit)
203+
# Create commit message with updated platforms
204+
UPDATED_PLATFORMS=""
205+
if [ "${{ steps.check-ipsws.outputs.should_update_ios }}" = "true" ]; then
206+
UPDATED_PLATFORMS="${UPDATED_PLATFORMS}iOS "
207+
fi
208+
if [ "${{ steps.check-ipsws.outputs.should_update_macos }}" = "true" ]; then
209+
UPDATED_PLATFORMS="${UPDATED_PLATFORMS}macOS "
210+
fi
211+
212+
COMMIT_MSG="chore(ents): update entitlements DB for ${UPDATED_PLATFORMS}[skip ci]"
213+
214+
# Commit cache file changes
75215
git add hack/.watch_cache
76-
git commit -m "chore(ents): update entitlements DB to $CURRENT_IPSW_URL [skip ci]" || echo "No changes to commit"
216+
git commit -m "$COMMIT_MSG" || echo "No changes to commit"
77217
git push

0 commit comments

Comments
 (0)