Skip to content

Commit 70cada2

Browse files
committed
Add check for new releases in last 24 hours before building
1 parent d92065b commit 70cada2

File tree

1 file changed

+101
-1
lines changed

1 file changed

+101
-1
lines changed

.github/workflows/main.yml

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,62 @@ jobs:
2121
- name: Checkout repository
2222
uses: actions/checkout@v4
2323

24+
- name: Check for new releases in last 24 hours
25+
id: check_new_release
26+
run: |
27+
echo "Checking if there's a new AdGuardHome release in the last 24 hours..."
28+
29+
# Get current timestamp and 24 hours ago timestamp
30+
CURRENT_TIME=$(date +%s)
31+
TIME_24H_AGO=$((CURRENT_TIME - 86400))
32+
33+
# Fetch all releases (including pre-releases)
34+
RELEASE_JSON=$(curl -s -f -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/AdguardTeam/AdGuardHome/releases" 2>/dev/null || echo "")
35+
36+
if [ -z "$RELEASE_JSON" ] || [ "$RELEASE_JSON" = "null" ]; then
37+
echo "Failed to fetch releases from API"
38+
echo "has_new_release=false" >> $GITHUB_OUTPUT
39+
exit 0
40+
fi
41+
42+
# Check if any release was published in the last 24 hours
43+
HAS_NEW_RELEASE=false
44+
LATEST_RELEASE_TIME=""
45+
46+
# Get the published_at timestamp of the latest release
47+
LATEST_RELEASE_TIME=$(echo "$RELEASE_JSON" | jq -r '.[0].published_at' 2>/dev/null)
48+
49+
if [ -n "$LATEST_RELEASE_TIME" ] && [ "$LATEST_RELEASE_TIME" != "null" ]; then
50+
# Convert ISO 8601 timestamp to Unix timestamp
51+
RELEASE_TIMESTAMP=$(date -d "$LATEST_RELEASE_TIME" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$LATEST_RELEASE_TIME" +%s 2>/dev/null)
52+
53+
if [ -n "$RELEASE_TIMESTAMP" ]; then
54+
echo "Latest release time: $LATEST_RELEASE_TIME"
55+
echo "Latest release timestamp: $RELEASE_TIMESTAMP"
56+
echo "24 hours ago timestamp: $TIME_24H_AGO"
57+
58+
if [ "$RELEASE_TIMESTAMP" -gt "$TIME_24H_AGO" ]; then
59+
HAS_NEW_RELEASE=true
60+
echo "✅ New release found within the last 24 hours!"
61+
else
62+
echo "❌ No new release in the last 24 hours"
63+
TIME_DIFF=$((CURRENT_TIME - RELEASE_TIMESTAMP))
64+
HOURS_AGO=$((TIME_DIFF / 3600))
65+
echo "Latest release was $HOURS_AGO hours ago"
66+
fi
67+
fi
68+
fi
69+
70+
echo "has_new_release=$HAS_NEW_RELEASE" >> $GITHUB_OUTPUT
71+
72+
# If running on schedule and no new release, we'll skip the rest
73+
if [ "${{ github.event_name }}" = "schedule" ] && [ "$HAS_NEW_RELEASE" = "false" ]; then
74+
echo "⏭️ Skipping build as there's no new release in the last 24 hours"
75+
fi
76+
2477
- name: Get latest AdGuardHome release
2578
id: get_release
79+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
2680
run: |
2781
# Get the latest release (including pre-releases) from AdGuardHome repository
2882
echo "Fetching latest AdGuardHome release information..."
@@ -64,6 +118,7 @@ jobs:
64118
echo "Architecture: ${{ matrix.arch }}"
65119
66120
- name: Download and extract AdGuardHome
121+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
67122
run: |
68123
# Create temporary directory
69124
mkdir -p temp_extract
@@ -121,6 +176,7 @@ jobs:
121176
fi
122177
123178
- name: Copy AdGuardHome binary to bin directory
179+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
124180
run: |
125181
# Ensure bin directory exists
126182
mkdir -p src/bin
@@ -140,6 +196,7 @@ jobs:
140196
du -h src/bin/AdGuardHome
141197
142198
- name: Create release archive
199+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
143200
run: |
144201
# Create cache directory for output
145202
mkdir -p cache
@@ -157,13 +214,15 @@ jobs:
157214
unzip -l cache/AdGuardHomeForRoot_${{ matrix.arch }}_${{ steps.get_release.outputs.tag_name }}.zip
158215
159216
- name: Upload build artifacts
217+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
160218
uses: actions/upload-artifact@v4
161219
with:
162220
name: AdGuardHomeForRoot_${{ matrix.arch }}_${{ steps.get_release.outputs.tag_name }}
163221
path: cache/AdGuardHomeForRoot_${{ matrix.arch }}_${{ steps.get_release.outputs.tag_name }}.zip
164222
retention-days: 30
165223

166224
- name: Clean up
225+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
167226
run: |
168227
# Clean up temporary files
169228
rm -rf temp_extract
@@ -173,14 +232,52 @@ jobs:
173232
release:
174233
needs: build
175234
runs-on: ubuntu-latest
176-
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
235+
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && needs.build.result == 'success'
177236

178237
steps:
179238
- name: Checkout repository
180239
uses: actions/checkout@v4
181240

241+
- name: Check for new releases in last 24 hours
242+
id: check_new_release
243+
run: |
244+
echo "Checking if there's a new AdGuardHome release in the last 24 hours..."
245+
246+
# Get current timestamp and 24 hours ago timestamp
247+
CURRENT_TIME=$(date +%s)
248+
TIME_24H_AGO=$((CURRENT_TIME - 86400))
249+
250+
# Fetch all releases (including pre-releases)
251+
RELEASE_JSON=$(curl -s -f -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/AdguardTeam/AdGuardHome/releases" 2>/dev/null || echo "")
252+
253+
if [ -z "$RELEASE_JSON" ] || [ "$RELEASE_JSON" = "null" ]; then
254+
echo "Failed to fetch releases from API"
255+
echo "has_new_release=false" >> $GITHUB_OUTPUT
256+
exit 0
257+
fi
258+
259+
# Check if any release was published in the last 24 hours
260+
HAS_NEW_RELEASE=false
261+
262+
# Get the published_at timestamp of the latest release
263+
LATEST_RELEASE_TIME=$(echo "$RELEASE_JSON" | jq -r '.[0].published_at' 2>/dev/null)
264+
265+
if [ -n "$LATEST_RELEASE_TIME" ] && [ "$LATEST_RELEASE_TIME" != "null" ]; then
266+
RELEASE_TIMESTAMP=$(date -d "$LATEST_RELEASE_TIME" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$LATEST_RELEASE_TIME" +%s 2>/dev/null)
267+
268+
if [ -n "$RELEASE_TIMESTAMP" ] && [ "$RELEASE_TIMESTAMP" -gt "$TIME_24H_AGO" ]; then
269+
HAS_NEW_RELEASE=true
270+
echo "✅ New release found within the last 24 hours!"
271+
else
272+
echo "❌ No new release in the last 24 hours"
273+
fi
274+
fi
275+
276+
echo "has_new_release=$HAS_NEW_RELEASE" >> $GITHUB_OUTPUT
277+
182278
- name: Get latest AdGuardHome release tag
183279
id: get_tag
280+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
184281
run: |
185282
# Get the latest release tag (same logic as build job)
186283
RELEASE_JSON=$(curl -s -f -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/AdguardTeam/AdGuardHome/releases" 2>/dev/null || echo "")
@@ -210,13 +307,15 @@ jobs:
210307
echo "Using AdGuardHome release: $TAG_NAME"
211308
212309
- name: Download artifacts
310+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
213311
uses: actions/download-artifact@v4
214312
with:
215313
pattern: AdGuardHomeForRoot_*_${{ steps.get_tag.outputs.tag_name }}
216314
path: artifacts
217315
merge-multiple: true
218316

219317
- name: Create Release
318+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
220319
id: create_release
221320
uses: actions/create-release@v1
222321
env:
@@ -251,6 +350,7 @@ jobs:
251350
prerelease: false
252351

253352
- name: Upload ARM64 Release Asset
353+
if: steps.check_new_release.outputs.has_new_release == 'true' || github.event_name != 'schedule'
254354
uses: actions/upload-release-asset@v1
255355
env:
256356
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)