-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_readme.py
32 lines (29 loc) · 1.02 KB
/
check_readme.py
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
import sys
import os
import requests
import base64
def check_readme(artifact_url):
headers = {
"Authorization": f"Bearer {os.environ['GIT_TOKEN']}",
"Content-Type": "application/json"
}
response = requests.get(
f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/contents/README.md",
headers=headers
)
if response.status_code == 200:
readme_content = response.json()
readme_content_decoded = base64.b64decode(readme_content["content"]).decode("utf-8")
if artifact_url in readme_content_decoded:
needs_update = 'false'
else:
needs_update = 'true'
else:
needs_update = 'true'
print(f"Failed to fetch README. Status code: {response.status_code}")
# Write the output to GITHUB_OUTPUT
with open(os.environ['GITHUB_OUTPUT'], 'a') as output_file:
output_file.write(f"needs_update={needs_update}\n")
if __name__ == "__main__":
artifact_url = sys.argv[1]
check_readme(artifact_url)