-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
314 lines (284 loc) · 11.6 KB
/
action.yaml
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
name: 'Create or Update publiccode.yaml'
author: 'Open Catalogi'
description: 'Creates or updates the publiccode.yaml or publicorganisation.yml file with repository metadata'
branding:
icon: 'file-plus'
color: 'blue'
inputs:
repository:
description: 'Git url of the remote repository you want to check'
required: false
type: string
default: ''
path:
description: 'publiccode.yaml path'
required: false
type: string
default: 'publiccode.yaml'
opencatalogi:
description: 'create an opencatalogi file instead of a publiccode'
required: false
type: boolean
default: false
federlize:
description: 'Wheter to send an update event to the federilized open catalogi network'
required: false
type: boolean
default: true
save:
description: 'Wheter to actually save the file to github'
required: false
type: boolean
default: true
# Git Configuration
git_name:
description: 'Git name configuration for the commit'
required: false
type: string
default: 'Open Catalogi bot'
git_mail:
description: 'Git mail configuration for the commit'
required: false
type: string
default: '[email protected]'
git_commit_message:
description: 'The description for the commit'
required: false
type: string
default: ${{ github.event.repository.html_url }}
github_organization_url:
description: 'The repository to which the results are limited (used to only look in your own organization)'
required: false
type: string
default: 'https://github.com/${{ github.repository_owner }}'
outputs:
version:
description: 'New version of softwareVersion field in publiccode.yml'
releaseDate:
description: 'New release date of releaseDate field in publiccode.yml'
runs:
using: "composite"
steps:
# Check out the code
- name: Checkout code
uses: actions/checkout@v2
# Install Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
# Fetch repositories of the github organization
- name: Get Repositories for github organization
uses: raven-actions/[email protected]
if: (contains(github.repository, '.github'))
id: get-repos
# Transfer the repossitory data to the container
- name: Transfer the repossitory data to the container
shell: bash
run: |
echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
echo "REPO_DESC=${{ github.event.repository.description }}" >> $GITHUB_ENV
echo "REPO_URL=${{ github.event.repository.html_url }}" >> $GITHUB_ENV
echo "REPO_HOMEPAGE=${{ github.event.repository.homepage }}" >> $GITHUB_ENV
echo "REPO_LICENSE=${{ github.event.repository.license.key }}" >> $GITHUB_ENV
echo "REPO_CREATED_AT=${{ github.event.repository.created_at }}" >> $GITHUB_ENV
echo "ORGANISATION_NAME=${{ github.event.organization.login }}" >> $GITHUB_ENV
echo "ORGANISATION_DESCRIPTION=${{ github.event.organization.description }}" >> $GITHUB_ENV
echo "ORGANISATION_GITID=${{ github.event.organization.id}}" >> $GITHUB_ENV
echo "ORGANISATION_URL=${{ github.event.organization.login }}" >> $GITHUB_ENV
echo "ORGANISATION_AVATAR=${{ github.event.organization.avatar_url }}" >> $GITHUB_ENV
echo 'ORGANIZATION_REPOS=${{ steps.get-repos.outputs.repos }}' >> $GITHUB_ENV
echo "Installing PyYAML..."
pip install PyYAML
# Create changes if it is a normal repository
- name: Create or update the publiccode file
if: (!contains(github.repository, '.github'))
shell: bash
run: |
python - <<END
import os
import yaml
from datetime import datetime
def set_default(d, key, default_value):
if not isinstance(d, dict):
return
if key not in d:
d[key] = default_value
# Read existing publiccode.yaml
filename = "publiccode.yaml"
try:
with open(filename, "r") as f:
data = yaml.safe_load(f)
except FileNotFoundError:
data = {}
if (data == {}):
try:
with open("publiccode.yml", "r") as f:
data = yaml.safe_load(f)
filename = "publiccode.yml"
except FileNotFoundError:
data = data
# Convert created_at to date format
created_at_date = datetime.now().strftime('%Y-%m-%d')
# Initialize missing keys with default values
set_default(data, 'publiccodeYmlVersion', "0.2")
set_default(data, 'name', "")
set_default(data, 'url', "")
set_default(data, 'landingURL', "")
set_default(data, 'softwareVersion', "")
set_default(data, 'releaseDate', created_at_date)
set_default(data, 'platforms', ["web"])
set_default(data, 'categories', ["it-development"])
set_default(data, 'usedBy', [])
set_default(data, 'roadmap', "")
set_default(data, 'developmentStatus', "development")
set_default(data, 'softwareType', "standalone/web")
set_default(data, 'description', {'en': {}})
set_default(data['description']['en'], 'localisedName', "")
set_default(data['description']['en'], 'genericName', "")
set_default(data['description']['en'], 'shortDescription', "")
set_default(data['description']['en'], 'longDescription', "")
set_default(data['description']['en'], 'documentation', "")
set_default(data['description']['en'], 'apiDocumentation', "")
set_default(data['description']['en'], 'features', [])
set_default(data['description']['en'], 'screenshots', [])
set_default(data['description']['en'], 'videos', [])
set_default(data['description']['en'], 'awards', [])
set_default(data, 'nl', {'vng': {}})
set_default(data['nl']['vng'], 'gemma', [])
set_default(data['nl']['vng'], 'commonground', [])
set_default(data, 'legal', {})
set_default(data['legal'], 'license', "")
set_default(data['legal'], 'mainCopyrightOwner', "")
set_default(data['legal'], 'repoOwner', "")
set_default(data['legal'], 'authorsFile', "")
set_default(data, 'maintenance', {})
set_default(data['maintenance'], 'type', "none")
set_default(data['maintenance'], 'contractors', [])
set_default(data['maintenance'], 'contacts', [])
set_default(data, 'localisation', {})
set_default(data['localisation'], 'localisationReady', False)
set_default(data['localisation'], 'availableLanguages', ["en"])
set_default(data, 'organisation', {})
# Update or append values
if os.environ.get('REPO_NAME'):
data['name'] = os.environ['REPO_NAME']
if os.environ.get('REPO_URL'):
data['url'] = os.environ['REPO_URL']
if os.environ.get('REPO_DESC'):
data['description']['en']['genericName'] = os.environ['REPO_DESC']
if os.environ.get('REPO_HOMEPAGE'):
data['url'] = os.environ['REPO_HOMEPAGE']
if os.environ.get('REPO_LICENSE'):
data['legal']['license'] = os.environ['REPO_LICENSE']
if os.environ.get('ORGANISATION_NAME'):
data['organisation']['name'] = os.environ['ORGANISATION_NAME']
if os.environ.get('ORGANISATION_AVATAR'):
data['organisation']['logo'] = os.environ['ORGANISATION_AVATAR']
if os.environ.get('ORGANISATION_URL'):
data['organisation']['url'] = os.environ['ORGANISATION_URL']
if os.environ.get('ORGANISATION_DESCRIPTION'):
data['organisation']['description'] = os.environ['ORGANISATION_DESCRIPTION']
# Write updated publiccode.yaml
with open(filename, "w") as f:
yaml.safe_dump(data, f)
END
# Create changes if it is an organisation repository
- name: Create or update the publicorganisation file
if: (contains(github.repository, '.github'))
shell: bash
run: |
python - <<END
import os
import yaml
import json
import copy
from datetime import datetime
def set_default(d, key, default_value):
if not isinstance(d, dict):
return
if key not in d:
d[key] = default_value
repositories = json.loads(os.environ.get('ORGANIZATION_REPOS'))
repositoryUrls = [repository['html_url'] for repository in repositories]
support = []
for repository in repositoryUrls:
support.append({"software": repository, "type": "community"})
# Read existing opencatalogi.yaml
filename = "opencatalogi.yaml"
try:
with open(filename, "r") as f:
data = yaml.safe_load(f)
except FileNotFoundError:
data = {}
if (data == {}):
try:
with open("openCatalogi.yaml", "r") as f:
data = yaml.safe_load(f)
filename = "openCatalogi.yaml"
except FileNotFoundError:
data = data
if (data == {}):
try:
with open("opencatalogi.yml", "r") as f:
data = yaml.safe_load(f)
filename = "opencatalogi.yml"
except FileNotFoundError:
data = data
if (data == {}):
try:
with open("openCatalogi.yml", "r") as f:
data = yaml.safe_load(f)
filename = "openCatalogi.yml"
except FileNotFoundError:
data = data
# Convert created_at to date format
created_at_date = datetime.now().strftime('%Y-%m-%d')
# Initialize missing keys with default values
set_default(data, 'publiccodeYmlVersion', "0.2")
set_default(data, 'name', "")
set_default(data, 'website', "")
set_default(data, 'contact', {})
set_default(data['contact'], 'email', "")
set_default(data['contact'], 'phone', "")
set_default(data, 'softwareOwned', copy.copy(repositoryUrls))
set_default(data, 'softwareUsed', copy.copy(repositoryUrls))
set_default(data, 'softwareSupported', support)
# Write updated opencatalogi.yaml
with open(filename, "w") as f:
yaml.safe_dump(data, f)
END
# Commit changes if it is a normal repository
- name: Commit changes
if: (!contains(github.repository, '.github') && inputs.save)
shell: bash
run: |
git config --local user.email "${{ inputs.git-mail }}"
git config --local user.name "${{ inputs.git-name }}"
git pull
git add publiccode.y*ml
git commit -m "${{ inputs.git-commit-message }}" || echo "No changes to commit"
git push
# Commit changes if it is an organisation repository
- name: Commit changes
if: (contains(github.repository, '.github') && inputs.save)
shell: bash
run: |
git config --local user.email "${{ inputs.git_mail }}"
git config --local user.name "${{ inputs.git_name }}"
git pull
git add open*atalogi.y*ml
git commit -m "${{ inputs.git_commit_message }}" || echo "No changes to commit"
git push
# Post Repository URL to OpenCatalogi API
- name: Post Repository URL to OpenCatalogi API
if: (inputs.federlize)
shell: bash
run: |
curl -X POST "https://api.opencatalogi.nl/api/github_events" \
-H "Content-Type: application/json" \
-d '{
"repository": {
"html_url": "'${{ github.event.repository.html_url }}'"
}
}'