Skip to content

Commit bf58064

Browse files
committed
Try the python code
1 parent 66a4360 commit bf58064

4 files changed

Lines changed: 87 additions & 103 deletions

File tree

.github/workflows/opencatalogi-publish.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ jobs:
2525
REPO_URL="${{ github.event.repository.html_url }}"
2626
REPO_HOMEPAGE="${{ github.event.repository.homepage }}"
2727
REPO_LICENSE="${{ github.event.repository.license.key }}"
28-
REPO_CREATED_AT="${{ github.event.repository.created_at }}"
28+
REPO_CREATED_AT="${{ github.event.repository.created_at }}"
29+
2930
ORGANISATION_NAME="${{ github.event.organization.login }}"
3031
ORGANISATION_DESCRIPTION="${{ github.event.organization.description }}"
3132
ORGANISATION_GITID="${{ github.event.organization.id}}"
3233
ORGANISATION_URL="${{ github.event.organization.login }}"
3334
ORGANISATION_AVATAR="${{ github.event.organization.avatar_url }}"
35+
36+
echo "Installing PyYAML..."
37+
pip install PyYAML
38+
39+
3440
# Bit of test coding to see if everything works
3541
- run: echo Hello ${{ inputs.who-to-greet }}.
3642
shell: bash

action.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ runs:
5353
ORGANISATION_GITID="${{ github.event.organization.id}}"
5454
ORGANISATION_URL="${{ github.event.organization.login }}"
5555
ORGANISATION_AVATAR="${{ github.event.organization.avatar_url }}"
56+
57+
echo "Installing PyYAML..."
58+
pip install PyYAML
5659

5760
# Bit of test coding to see if everything works
5861
- run: echo Hello ${{ inputs.who-to-greet }}.

update_publiccode.py

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,57 @@
11
# .github/scripts/update_publiccode.py
22

3-
import os
43
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)
4+
import json
5+
from datetime import datetime
6+
7+
# Read existing publiccode.yaml
368
try:
37-
with open("publiccode.yaml", "r") as file:
38-
publiccode = yaml.safe_load(file)
9+
with open("publiccode.yaml", "r") as f:
10+
data = yaml.safe_load(f)
3911
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)
12+
data = {}
13+
14+
# Convert created_at to date format
15+
# created_at_date = datetime.fromisoformat("$REPO_CREATED_AT".replace("Z", "+00:00")).strftime('%Y-%m-%d')
16+
created_at_date = datetime.now().strftime('%Y-%m-%d')
17+
18+
# Convert topics JSON string to Python list and then to comma-separated string
19+
20+
# Update or append values
21+
if "$REPO_NAME" != "null" and "$REPO_NAME":
22+
data['name'] = "$REPO_NAME"
23+
if "$REPO_URL" != "null" and "$REPO_URL":
24+
data['url'] = "$REPO_URL"
25+
if "$REPO_DESC" != "null" and "$REPO_DESC":
26+
data['description'] = "$REPO_DESC"
27+
if "$REPO_HOMEPAGE" != "null" and "$REPO_HOMEPAGE":
28+
data['url'] = "$REPO_HOMEPAGE"
29+
#if "$REPO_TOPICS" != "null" and "$REPO_TOPICS":
30+
# data['topics'] = "$REPO_TOPICS"
31+
if "$REPO_LICENSE" != "null" and "$REPO_LICENSE":
32+
data['license'] = "$REPO_LICENSE"
33+
34+
# Add releaseDate if not present
35+
if 'releaseDate' not in data:
36+
data['releaseDate'] = created_at_date
37+
38+
# Create or update nested 'organisation' array
39+
if 'organisation' not in data:
40+
data['organisation'] = {}
41+
if "$ORGANISATION_NAME" != "null" and "$ORGANISATION_NAME":
42+
data['organisation']['name'] = "$ORGANISATION_NAME"
43+
if "$ORGANISATION_AVATAR" != "null" and "$ORGANISATION_AVATAR":
44+
data['organisation']['logo'] = "$ORGANISATION_AVATAR"
45+
if "$ORGANISATION_URL" != "null" and "$ORGANISATION_URL":
46+
data['organisation']['url'] = "$ORGANISATION_URL"
47+
if "$ORGANISATION_DESCRIPTION" != "null" and "$ORGANISATION_DESCRIPTION":
48+
data['organisation']['description'] = "$ORGANISATION_DESCRIPTION"
49+
50+
# Create or update nested 'nl' array
51+
if 'nl' not in data:
52+
data['nl'] = {}
53+
54+
# Write updated publiccode.yaml
55+
with open("publiccode.yaml", "w") as f:
56+
yaml.safe_dump(data, f)
57+
END

update_publicorganisation.py

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,30 @@
1-
# .github/scripts/update_publiccode.py
1+
# .github/scripts/update_publicorganisation.py
22

3-
import os
43
import yaml
5-
import warnings
4+
import json
5+
from datetime import datetime
66

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)
7+
# Read existing openCatalogi.yaml
368
try:
37-
with open("publiccode.yaml", "r") as file:
38-
publiccode = yaml.safe_load(file)
9+
with open("openCatalogi.yaml", "r") as f:
10+
data = yaml.safe_load(f)
3911
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)
12+
data = {}
13+
14+
if "$ORGANISATION_NAME" != "null" and "$ORGANISATION_NAME":
15+
data['name'] = "$ORGANISATION_NAME"
16+
if "$ORGANISATION_AVATAR" != "null" and "$ORGANISATION_AVATAR":
17+
data['logo'] = "$ORGANISATION_AVATAR"
18+
if "$ORGANISATION_URL" != "null" and "$ORGANISATION_URL":
19+
data['url'] = "$ORGANISATION_URL"
20+
if "$ORGANISATION_DESCRIPTION" != "null" and "$ORGANISATION_DESCRIPTION":
21+
data['description'] = "$ORGANISATION_DESCRIPTION"
22+
23+
# Create or update nested 'nl' array
24+
if 'nl' not in data:
25+
data['nl'] = {}
26+
27+
# Write updated openCatalogi.yaml
28+
with open("openCatalogi.yaml", "w") as f:
29+
yaml.safe_dump(data, f)
30+
END

0 commit comments

Comments
 (0)