Skip to content

Commit fa9c120

Browse files
authored
Create update_publiccode.py
1 parent 8e3901f commit fa9c120

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

update_publiccode.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# .github/scripts/update_publiccode.py
2+
3+
import os
4+
import yaml
5+
import warnings
6+
7+
# Check the metadata of the repository
8+
# For the simplicity, we're assuming that the metadata are environment variables
9+
# In a real case, you would fetch the metadata from the repository or other sources
10+
11+
# Metadata variables
12+
variables = [
13+
"GITHUB_REPOSITORY",
14+
"REPO_DESCRIPTION",
15+
"ORGANISATION",
16+
"TAGS",
17+
"WEBSITE",
18+
"LICENCE"
19+
]
20+
21+
# Create a dictionary to hold the metadata
22+
metadata = {}
23+
24+
# Check if each variable is set and if not, issue a warning
25+
for var in variables:
26+
value = os.getenv(var)
27+
if value:
28+
metadata[var] = value
29+
else:
30+
warnings.warn(f"The {var} environment variable is not set")
31+
32+
# Always set the repository url
33+
metadata["REPO_URL"] = f"https://github.com/{metadata.get('GITHUB_REPOSITORY', 'default_repo_name')}"
34+
35+
# Read the current publiccode.yaml (if exists)
36+
try:
37+
with open("publiccode.yaml", "r") as file:
38+
publiccode = yaml.safe_load(file)
39+
except FileNotFoundError:
40+
publiccode = {}
41+
42+
# Update the publiccode with the new metadata
43+
publiccode["publiccode"] = publiccode.get("publiccode", {})
44+
publiccode["publiccode"]["name"] = metadata.get("GITHUB_REPOSITORY")
45+
publiccode["publiccode"]["description"] = {
46+
"nl": metadata.get("REPO_DESCRIPTION")
47+
}
48+
publiccode["publiccode"]["url"] = metadata.get("REPO_URL")
49+
publiccode["publiccode"]["tags"] = metadata.get("TAGS")
50+
publiccode["publiccode"]["website"] = metadata.get("WEBSITE")
51+
publiccode["publiccode"]["license"] = metadata.get("LICENCE")
52+
publiccode["publiccode"]["owner"] = metadata.get("ORGANISATION")
53+
54+
# Write back the publiccode.yaml
55+
with open("publiccode.yaml", "w") as file:
56+
yaml.safe_dump(publiccode, file)

0 commit comments

Comments
 (0)