Skip to content

Commit c2fdfae

Browse files
committed
Merge remote-tracking branch 'origin/feature/mark-debug' into feature/public-action
2 parents cf685d1 + 1f002b9 commit c2fdfae

5 files changed

Lines changed: 151 additions & 166 deletions

File tree

.github/workflows/opencatalogi-publish.yaml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: PublicCode and PublicOrganization Check and Update
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- main
78
- feature/public-action
9+
- feature/mark-debug
810

911
jobs:
1012
check-and-update:
@@ -20,21 +22,21 @@ jobs:
2022
# Transfer the repossitory data to the container
2123
- name: Transfer the repossitory data to the container
2224
run: |
23-
REPO_NAME="${{ github.event.repository.name }}"
24-
REPO_DESC="${{ github.event.repository.description }}"
25-
REPO_URL="${{ github.event.repository.html_url }}"
26-
REPO_HOMEPAGE="${{ github.event.repository.homepage }}"
27-
REPO_LICENSE="${{ github.event.repository.license.key }}"
28-
REPO_CREATED_AT="${{ github.event.repository.created_at }}"
25+
echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
26+
echo "REPO_DESC=${{ github.event.repository.description }}" >> $GITHUB_ENV
27+
echo "REPO_URL=${{ github.event.repository.html_url }}" >> $GITHUB_ENV
28+
echo "REPO_HOMEPAGE=${{ github.event.repository.homepage }}" >> $GITHUB_ENV
29+
echo "REPO_LICENSE=${{ github.event.repository.license.key }}" >> $GITHUB_ENV
30+
echo "REPO_CREATED_AT=${{ github.event.repository.created_at }}" >> $GITHUB_ENV
2931
30-
ORGANISATION_NAME="${{ github.event.organization.login }}"
31-
ORGANISATION_DESCRIPTION="${{ github.event.organization.description }}"
32-
ORGANISATION_GITID="${{ github.event.organization.id}}"
33-
ORGANISATION_URL="${{ github.event.organization.login }}"
34-
ORGANISATION_AVATAR="${{ github.event.organization.avatar_url }}"
35-
36-
echo "Installing PyYAML..."
37-
pip install PyYAML
32+
echo "ORGANISATION_NAME=${{ github.event.organization.login }}" >> $GITHUB_ENV
33+
echo "ORGANISATION_DESCRIPTION=${{ github.event.organization.description }}" >> $GITHUB_ENV
34+
echo "ORGANISATION_GITID=${{ github.event.organization.id}}" >> $GITHUB_ENV
35+
echo "ORGANISATION_URL=${{ github.event.organization.login }}" >> $GITHUB_ENV
36+
echo "ORGANISATION_AVATAR=${{ github.event.organization.avatar_url }}" >> $GITHUB_ENV
37+
38+
echo "Installing PyYAML..."
39+
pip install PyYAML
3840
3941
4042
# Bit of test coding to see if everything works

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
.idea/
3+
_pychache_/

action.yaml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 'Create or Update publiccode.yaml'
22
author: 'Open Catalogi'
3-
description: 'Creates or updates the publiccode.yal or publicorganisation.yml file with repository metadata'
3+
description: 'Creates or updates the publiccode.yaml or publicorganisation.yml file with repository metadata'
44

55
inputs:
66
remoterepo:
@@ -39,21 +39,19 @@ runs:
3939
python-version: '3.x'
4040
# Transfer the repossitory data to the container
4141
- name: Transfer the repossitory data to the container
42-
run:
43-
REPO_NAME="${{ github.event.repository.name }}"
44-
REPO_DESC="${{ github.event.repository.description }}"
45-
REPO_URL="${{ github.event.repository.html_url }}"
46-
REPO_HOMEPAGE="${{ github.event.repository.homepage }}"
47-
#REPO_TOPICS="${{ github.event.repository.topics }}"
48-
REPO_LICENSE="${{ github.event.repository.license.key }}"
49-
REPO_CREATED_AT="${{ github.event.repository.created_at }}"
50-
51-
ORGANISATION_NAME="${{ github.event.organization.login }}"
52-
ORGANISATION_DESCRIPTION="${{ github.event.organization.description }}"
53-
ORGANISATION_GITID="${{ github.event.organization.id}}"
54-
ORGANISATION_URL="${{ github.event.organization.login }}"
55-
ORGANISATION_AVATAR="${{ github.event.organization.avatar_url }}"
56-
42+
env:
43+
REPO_NAME: ${{ github.event.repository.name }}
44+
REPO_DESC: ${{ github.event.repository.description }}
45+
REPO_URL: ${{ github.event.repository.html_url }}
46+
REPO_HOMEPAGE: ${{ github.event.repository.homepage }}
47+
REPO_LICENSE: ${{ github.event.repository.license.key }}
48+
REPO_CREATED_AT: ${{ github.event.repository.created_at }}
49+
ORGANISATION_NAME: ${{ github.event.organization.login }}
50+
ORGANISATION_DESCRIPTION: ${{ github.event.organization.description }}
51+
ORGANISATION_GITID: ${{ github.event.organization.id}}
52+
ORGANISATION_URL: ${{ github.event.organization.login }}
53+
ORGANISATION_AVATAR: ${{ github.event.organization.avatar_url }}
54+
run: |
5755
echo "Installing PyYAML..."
5856
pip install PyYAML
5957

publiccode.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
categories:
2+
- it-development
3+
description:
4+
en:
5+
apiDocumentation: ''
6+
awards: []
7+
documentation: ''
8+
features: []
9+
genericName: This GitHub Action automatically generates and updates a publiccode.yaml
10+
file in the root of your repository, based on repository metadata. The file
11+
is updated each time a push is made to the main branch.
12+
localisedName: ''
13+
longDescription: ''
14+
screenshots: []
15+
shortDescription: ''
16+
videos: []
17+
developmentStatus: development
18+
landingURL: ''
19+
legal:
20+
authorsFile: ''
21+
license: ''
22+
mainCopyrightOwner: ''
23+
repoOwner: ''
24+
localisation:
25+
availableLanguages:
26+
- en
27+
localisationReady: false
28+
maintenance:
29+
contacts: []
30+
contractors: []
31+
type: none
32+
name: publiccode-action
33+
nl:
34+
vng:
35+
commonground: []
36+
gemma: []
37+
organisation:
38+
description: "E\xE9n centrale plek voor hergebruik van informatietechnologie binnen\
39+
\ de overheid"
40+
logo: https://avatars.githubusercontent.com/u/106239067?v=4
41+
name: OpenCatalogi
42+
url: OpenCatalogi
43+
platforms:
44+
- web
45+
publiccodeYmlVersion: '0.2'
46+
releaseDate: '2023-10-16'
47+
roadmap: ''
48+
softwareType: standalone/web
49+
softwareVersion: ''
50+
url: https://github.com/OpenCatalogi/publiccode-action
51+
usedBy: []

update_publiccode.py

Lines changed: 69 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,84 @@
1-
# .github/scripts/update_publiccode.py
2-
1+
import os
32
import yaml
4-
import json
53
from datetime import datetime
64

5+
def set_default(d, key, default_value):
6+
if not isinstance(d, dict):
7+
return
8+
if key not in d:
9+
d[key] = default_value
10+
711
# Read existing publiccode.yaml
812
try:
9-
with open("publiccode.yaml", "r") as f:
10-
data = yaml.safe_load(f)
13+
with open("publiccode.yaml", "r") as f:
14+
data = yaml.safe_load(f)
1115
except FileNotFoundError:
12-
data = {}
16+
data = {}
1317

1418
# Convert created_at to date format
15-
# created_at_date = datetime.fromisoformat("$REPO_CREATED_AT".replace("Z", "+00:00")).strftime('%Y-%m-%d')
1619
created_at_date = datetime.now().strftime('%Y-%m-%d')
1720

18-
# Convert topics JSON string to Python list and then to comma-separated string
19-
20-
################################################
21-
# Creating a publiccode array if it is missing #
22-
################################################
23-
24-
# Lets see if we have an nice exmple publiccode and values if they are missing
25-
if 'publiccodeYmlVersion' not in data:
26-
data['publiccodeYmlVersion'] = "0.2"
27-
if 'name' not in data:
28-
data['name'] = ""
29-
if 'url' not in data:
30-
data['url'] = ""
31-
if 'landingURL' not in data:
32-
data['landingURL'] = ""
33-
if 'softwareVersion' not in data:
34-
data['softwareVersion'] = ""
35-
if 'releaseDate' not in data:
36-
data['releaseDate'] = created_at_date
37-
if 'platforms' not in data:
38-
data['platforms'] = ["web"]
39-
if 'categories' not in data:
40-
data['categories'] = ["it-development"]
41-
if 'usedBy' not in data:
42-
data['usedBy'] = []
43-
if 'roadmap' not in data:
44-
data['roadmap'] = ""
45-
if 'developmentStatus' not in data:
46-
data['developmentStatus'] = "development"
47-
if 'softwareType' not in data:
48-
data['softwareType'] = "standalone/web"
49-
50-
# Description
51-
if 'description' not in data:
52-
data['description'] = {"en":[]}
53-
if 'en' not in data['description']:
54-
data['description']['en'] = {}
55-
if 'nl' not in data['description']: #this is just to point out that an NL version is wanted
56-
data['description']['nl'] = {}
57-
if 'localisedName' not in data['description']['en']:
58-
data['description']['en']['localisedName'] = ""
59-
if 'genericName' not in data['description']['en']:
60-
data['description']['en']['genericName'] = ""
61-
if 'shortDescription' not in data['description']['en']:
62-
data['description']['en']['shortDescription'] = ""
63-
if 'longDescription' not in data['description']['en']:
64-
data['description']['en']['longDescription'] =""
65-
if 'documentation' not in data['description']['en']:
66-
data['description']['en']['documentation'] = ""
67-
if 'apiDocumentation' not in data['description']['en']:
68-
data['description']['en']['apiDocumentation'] = ""
69-
if 'features' not in data['description']['en']:
70-
data['description']['en']['features'] = []
71-
if 'screenshots' not in data['description']['en']:
72-
data['description']['en']['screenshots'] = []
73-
if 'videos' not in data['description']['en']:
74-
data['description']['en']['videos'] = []
75-
if 'awards' not in data['description']['en']:
76-
data['description']['en']['awards'] = []
77-
78-
# Legal
79-
if 'legal' not in data:
80-
data['legal'] = []
81-
if 'license' not in data['legal']:
82-
data['legal']['license'] = ""
83-
if 'mainCopyrightOwner' not in data['legal']:
84-
data['legal']['mainCopyrightOwner'] = ""
85-
if 'repoOwner' not in data['legal']:
86-
data['legal']['repoOwner'] = ""
87-
if 'authorsFile' not in data['legal']:
88-
data['legal']['authorsFile'] = ""
89-
90-
# Maintenance
91-
if 'maintenance' not in data:
92-
data['maintenance'] = []
93-
if 'type' not in data['maintenance']:
94-
data['maintenance']['type'] = "none"
95-
if 'contractors' not in data['maintenance']:
96-
data['maintenance']['contractors'] = []
97-
if 'contacts' not in data['maintenance']:
98-
data['maintenance']['contacts'] = []
99-
100-
# Localisation
101-
if 'localisation' not in data:
102-
data['localisation'] = []
103-
if 'localisationReady' not in data['localisation']:
104-
data['localisation']['localisationReady'] = false
105-
if 'availableLanguages' not in data['localisation']:
106-
data['localisation']['availableLanguages'] = ["en"]
107-
108-
# NL Specific
109-
if 'nl' not in data:
110-
data['nl'] = []
111-
## Lets do GEMMA and Commen Ground
112-
if 'vng' not in data['nl']:
113-
data['nl']['vng'] = []
114-
if 'gemma' not in data['nl']['vng']:
115-
data['nl']['vng']['gemma'] = []
116-
if 'commenground' not in data['nl']['vng']:
117-
data['nl']['vng']['commenground'] = []
118-
119-
###########################################
120-
# Updating the values from the repository #
121-
###########################################
21+
# Initialize missing keys with default values
22+
set_default(data, 'publiccodeYmlVersion', "0.2")
23+
set_default(data, 'name', "")
24+
set_default(data, 'url', "")
25+
set_default(data, 'landingURL', "")
26+
set_default(data, 'softwareVersion', "")
27+
set_default(data, 'releaseDate', created_at_date)
28+
set_default(data, 'platforms', ["web"])
29+
set_default(data, 'categories', ["it-development"])
30+
set_default(data, 'usedBy', [])
31+
set_default(data, 'roadmap', "")
32+
set_default(data, 'developmentStatus', "development")
33+
set_default(data, 'softwareType', "standalone/web")
34+
set_default(data, 'description', {'en': {}})
35+
set_default(data['description']['en'], 'localisedName', "")
36+
set_default(data['description']['en'], 'genericName', "")
37+
set_default(data['description']['en'], 'shortDescription', "")
38+
set_default(data['description']['en'], 'longDescription', "")
39+
set_default(data['description']['en'], 'documentation', "")
40+
set_default(data['description']['en'], 'apiDocumentation', "")
41+
set_default(data['description']['en'], 'features', [])
42+
set_default(data['description']['en'], 'screenshots', [])
43+
set_default(data['description']['en'], 'videos', [])
44+
set_default(data['description']['en'], 'awards', [])
45+
set_default(data, 'nl', {'vng': {}})
46+
set_default(data['nl']['vng'], 'gemma', [])
47+
set_default(data['nl']['vng'], 'commonground', [])
48+
set_default(data, 'legal', {})
49+
set_default(data['legal'], 'license', "")
50+
set_default(data['legal'], 'mainCopyrightOwner', "")
51+
set_default(data['legal'], 'repoOwner', "")
52+
set_default(data['legal'], 'authorsFile', "")
53+
set_default(data, 'maintenance', {})
54+
set_default(data['maintenance'], 'type', "none")
55+
set_default(data['maintenance'], 'contractors', [])
56+
set_default(data['maintenance'], 'contacts', [])
57+
set_default(data, 'localisation', {})
58+
set_default(data['localisation'], 'localisationReady', False)
59+
set_default(data['localisation'], 'availableLanguages', ["en"])
60+
set_default(data, 'organisation', {})
12261

12362
# Update or append values
124-
if "$REPO_NAME" != "null" and "$REPO_NAME":
125-
data['name'] = "$REPO_NAME"
126-
if "$REPO_URL" != "null" and "$REPO_URL":
127-
data['url'] = "$REPO_URL"
128-
if "$REPO_DESC" != "null" and "$REPO_DESC":
129-
data['description'] = "$REPO_DESC"
130-
if "$REPO_HOMEPAGE" != "null" and "$REPO_HOMEPAGE":
131-
data['url'] = "$REPO_HOMEPAGE"
132-
#if "$REPO_TOPICS" != "null" and "$REPO_TOPICS":
133-
# data['topics'] = "$REPO_TOPICS"
134-
if "$REPO_LICENSE" != "null" and "$REPO_LICENSE":
135-
data['license'] = "$REPO_LICENSE"
136-
137-
# Create or update nested 'organisation' array
138-
if 'organisation' not in data:
139-
data['organisation'] = {}
140-
if "$ORGANISATION_NAME" != "null" and "$ORGANISATION_NAME":
141-
data['organisation']['name'] = "$ORGANISATION_NAME"
142-
if "$ORGANISATION_AVATAR" != "null" and "$ORGANISATION_AVATAR":
143-
data['organisation']['logo'] = "$ORGANISATION_AVATAR"
144-
if "$ORGANISATION_URL" != "null" and "$ORGANISATION_URL":
145-
data['organisation']['url'] = "$ORGANISATION_URL"
146-
if "$ORGANISATION_DESCRIPTION" != "null" and "$ORGANISATION_DESCRIPTION":
147-
data['organisation']['description'] = "$ORGANISATION_DESCRIPTION"
63+
if os.environ.get('REPO_NAME'):
64+
data['name'] = os.environ['REPO_NAME']
65+
if os.environ.get('REPO_URL'):
66+
data['url'] = os.environ['REPO_URL']
67+
if os.environ.get('REPO_DESC'):
68+
data['description']['en']['genericName'] = os.environ['REPO_DESC']
69+
if os.environ.get('REPO_HOMEPAGE'):
70+
data['url'] = os.environ['REPO_HOMEPAGE']
71+
if os.environ.get('REPO_LICENSE'):
72+
data['legal']['license'] = os.environ['REPO_LICENSE']
73+
if os.environ.get('ORGANISATION_NAME'):
74+
data['organisation']['name'] = os.environ['ORGANISATION_NAME']
75+
if os.environ.get('ORGANISATION_AVATAR'):
76+
data['organisation']['logo'] = os.environ['ORGANISATION_AVATAR']
77+
if os.environ.get('ORGANISATION_URL'):
78+
data['organisation']['url'] = os.environ['ORGANISATION_URL']
79+
if os.environ.get('ORGANISATION_DESCRIPTION'):
80+
data['organisation']['description'] = os.environ['ORGANISATION_DESCRIPTION']
14881

14982
# Write updated publiccode.yaml
15083
with open("publiccode.yaml", "w") as f:
151-
yaml.safe_dump(data, f)
84+
yaml.safe_dump(data, f)

0 commit comments

Comments
 (0)