summaryrefslogtreecommitdiffstats
path: root/.github/scripts/platform-impending-eol.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:08 +0000
commit81581f9719bc56f01d5aa08952671d65fda9867a (patch)
tree0f5c6b6138bf169c23c9d24b1fc0a3521385cb18 /.github/scripts/platform-impending-eol.py
parentReleasing debian version 1.38.1-1. (diff)
downloadnetdata-81581f9719bc56f01d5aa08952671d65fda9867a.tar.xz
netdata-81581f9719bc56f01d5aa08952671d65fda9867a.zip
Merging upstream version 1.39.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '.github/scripts/platform-impending-eol.py')
-rwxr-xr-x.github/scripts/platform-impending-eol.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/.github/scripts/platform-impending-eol.py b/.github/scripts/platform-impending-eol.py
new file mode 100755
index 000000000..c57e5edde
--- /dev/null
+++ b/.github/scripts/platform-impending-eol.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+'''Check if a given distro is going to be EOL soon.
+
+ This queries the public API of https://endoflife.date to fetch EOL dates.
+
+ ‘soon’ is defined by LEAD_DAYS, currently 30 days.'''
+
+import datetime
+import json
+import sys
+import urllib.request
+
+URL_BASE = 'https://endoflife.date/api'
+NOW = datetime.date.today()
+LEAD_DAYS = datetime.timedelta(days=30)
+
+DISTRO = sys.argv[1]
+RELEASE = sys.argv[2]
+
+EXIT_NOT_IMPENDING = 0
+EXIT_IMPENDING = 1
+EXIT_NO_DATA = 2
+EXIT_FAILURE = 3
+
+try:
+ with urllib.request.urlopen(f'{ URL_BASE }/{ DISTRO }/{ RELEASE }.json') as response:
+ match response.status:
+ case 200:
+ data = json.load(response)
+ case _:
+ print(
+ f'Failed to retrieve data for { DISTRO } { RELEASE } ' +
+ f'(status: { response.status }).',
+ file=sys.stderr
+ )
+ sys.exit(EXIT_FAILURE)
+except urllib.error.HTTPError as e:
+ match e.code:
+ case 404:
+ print(f'No data available for { DISTRO } { RELEASE }.', file=sys.stderr)
+ sys.exit(EXIT_NO_DATA)
+ case _:
+ print(
+ f'Failed to retrieve data for { DISTRO } { RELEASE } ' +
+ f'(status: { e.code }).',
+ file=sys.stderr
+ )
+ sys.exit(EXIT_FAILURE)
+
+eol = datetime.date.fromisoformat(data['eol'])
+
+offset = abs(eol - NOW)
+
+if offset <= LEAD_DAYS:
+ print(data['eol'])
+ sys.exit(EXIT_IMPENDING)
+else:
+ sys.exit(EXIT_NOT_IMPENDING)