aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/mk-phosh-rel
blob: fd3e193fdcc4b86cd90b2f9e4ff59bc9c4240403 (plain)
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
#!/usr/bin/python3
#
# Create a phosh release in gitlab
# TODO: Use a hugo template so we can add images, etc easily
# TODO: Push and pop headline levels instead of hardcoding in lots of places
#
# Later:
# TODO: add phosh backgrounds ?`
# TODO: livi?

import argparse
import datetime
import gitlab
import os
import sys


URL = "https://gitlab.gnome.org"
_debug = False

projects = {
    'phosh': {
        'project-id': 16747,
        'description': 'A graphical shell for mobile devices',
        'category': 'core',
    },
    'phoc': {
        'project-id': 16763,
        'description': 'A Wayland compositor for mobile devices',
        'category': 'core',
    },
    'squeekboard': {
        'project-id': 16777,
        'description': 'An on-screen-keyboard input method for Wayland',
        'category': 'core',
    },
    'phosh-mobile-settings': {
        'project-id': 21486,
        'description': 'A Mobile (and Phosh specific) Settings Application',
        'category': 'util',
    },
    'phosh-tour': {
        'project-id': 22337,
        'description': 'A short introduction to Phosh',
        'category': 'util',
    },
    # libraries
    'libcall-ui': {
        'project-id': 16368,
        'description': 'Common user interface parts for call handling',
        'category': 'libraries',
    },
    'gmobile': {
        'project-id': 22559,
        'description': 'Bits useful in mobile related, glib based projects',
        'category': 'libraries',
    },
    # optional components
    'phom': {
        'project-id': 21912,
        'description': 'A virtual mouse prototype',
        'category': 'optional',
    },
    'phosh-osk-stub': {
        'project-id': 19269,
        'description': 'An experimental alternative on screen keyboard',
        'category': 'optional',
    },
    'phosh-osk-data': {
        'project-id': 25718,
        'description': 'Completion data for Phosh\'s on screen keyboards',
        'category': 'optional',
    },
}


base = {
    'wlroots': {
        'version': '0.17.1',
        'url': 'https://gitlab.freedesktop.org/wlroots/wlroots',
    },
    'GNOME': {
        'version': '45',
        'url': 'https://download.gnome.org/core/45/',
    },
    'feedbackd': {
        'version': '0.2.1',
        'url': 'https://source.puri.sm/Librem5/feedbackd'
    },
    'feedbackd-device-themes': {
        'version': '0.1.0',
        'url': 'https://source.puri.sm/Librem5/feedbackd-device-themes'
    },
    'callaudiod': {
        'version': '0.1.7',
        'url': 'https://gitlab.com/mobian1/callaudiod/'
    },
    'wys': {
        'version': '0.1.12',
        'url': 'https://source.puri.sm/Librem5/wys',
    },
    'mmsd-tng': {
        'version': '2.5.0',
        'url': 'https://gitlab.com/kop316/mmsd',
    },
}

recommended = {
    'phog': {
        'version': '0.1.6',
        'description': "A display manager using Phosh's UI",
        'url': 'https://gitlab.com/mobian1/phog',
    },
    'phosh-antispam': {
        'version': '3.3.1',
        'description': 'Avoid spam calls',
        'url': 'https://gitlab.com/kop316/phosh-antispam',
    },
    'vvmd': {
        'version': '0.16',
        'description': 'Visual Voice Mail',
        'url': 'https://gitlab.com/kop316/vvmd',
    },
    'livi': {
        'version': '0.0.5',
        'description': 'A simple video player for mobile',
        'url': 'https://gitlab.gnome.org/guidog/livi',
    },
    'chatty': {
        'version': '0.8.0',
        'description': 'A messaging app for SMS and MMS',
        'url': 'https://gitlab.gnome.org/World/Chatty',
    },
}

headlines = {
    'core': ['Core components', ''],
    'util': ['Recommended components', ''],
    'libraries': ['Libraries', ''],
    'optional': ['Related components', 'These components are purely optional:']
}


def debug(arg):
    if (_debug):
        print(arg)


def format_component(name, version, description, gl_release):
    """
    Format a single component based on a gitlab release entry. We
    assume that the detailed list of changes starts with `Detailed
    changes`.
    """
    txt = f"""<section class="phosh-component">

### {name} {version}
**{description}**\n
"""

    for line in gl_release.description.split('\n'):
        if line.lower().startswith("detailed changes"):
            break
        elif line.lower().startswith("summary of changes"):
            add = f"#### {line}\n"
        elif line.lower().startswith("maybe noteworthy"):
            add = f"#### {line}\n"
        elif line.lower().startswith("important changes"):
            add = f"#### {line}\n"
        elif line.lower().startswith("new features"):
            add = f"#### {line}\n"
        elif line.lower().startswith("i18n updates"):
            add = f"#### {line}\n"
        elif line.startswith("==="):
            add = ''
        else:
            add = f"{line}\n"
        txt += add

    txt += f"""
[Detailed list of changes]({gl_release._links['self']})\n
</section>
"""
    return txt


def format_missing_component(name, version, description, gl_release):
    if gl_release.tag_name[0] == 'v':
        latest_version = gl_release.tag_name[1:]
    else:
        latest_version = gl_release.tag_name

    txt = f"""<section class="phosh-component phosh-unreleased">

### {name} {latest_version}
**{description}**\n
"""
    txt += f"*Not released in the {version} cycle, latest is {latest_version}*\n"

    txt += f"""
[Detailed list of changes]({gl_release._links['self']})
</section>
"""
    return txt


def main(argv):
    global _debug
    today = datetime.datetime.today().strftime("%Y-%m-%d")

    parser = argparse.ArgumentParser(os.path.basename(argv[0]),
                                     description='''Make a release''')

    parser.add_argument('--debug', action="store_true", default=False,
                        help='Enable debug output')
    parser.add_argument('--out', type=str, default=None,
                        help='Output file')
    parser.add_argument('--date', type=str, default=today,
                        help='Release date')
    parser.add_argument(dest='version', type=str)
    args = parser.parse_args(argv[1:])

    _debug = args.debug

    tag_name = f"v{args.version}"
    gl = gitlab.Gitlab(URL)

    release_notes = f'''+++
authors = ["Guido Günther"]
title = "Phosh {args.version}"
date = "{args.date}"
description = "The Phosh {args.version} Release"
tags = [
    "phosh",
    "release",
]
featuredImage = "phosh-release-{args.version}.png"
+++
'''

    release_notes += f"""# Phosh {args.version}

A new major release of Phosh is out. See below for a list of changes in
individual components:
"""

    headline = ''
    # This assumes the projects dict keeps it's sorting order:
    for (name, data) in projects.items():
        debug(f"Fetching {name}")
        gl_project = gl.projects.get(data['project-id'])
        last = gl_project.releases.list(get_all=True)[0]

        if headline != headlines[data['category']][0]:
            headline = headlines[data['category']][0]
            release_notes += f'\n## {headline}\n\n'
            description = headlines[data['category']][1]
            if description:
                release_notes += f'{description}\n'

        # TODO: add version to header too
        if (last.tag_name == tag_name):
            debug(f"{name} released with {tag_name}")
            comp_notes = format_component(name, args.version, data['description'], last)
        else:
            debug(f"{name} not released with {tag_name}, latest is {last.tag_name}")
            comp_notes = format_missing_component(name, args.version, data['description'], last)

        release_notes += f"{comp_notes}"

    # Dependencies
    release_notes += "\n# Dependencies\nWithout these the above wouldn't be possible. This release is based on:\n\n"
    for (name, data) in base.items():
        release_notes += f"* [{name}]({data['url']}) {data['version']}\n"

    release_notes += "\nFor more details on dependencies and required patches see the detailed list of changes of the individual components."

    # Related Software
    release_notes += "\n# Related Software\n\nOther components often used with Phosh but not mandatory:\n\n"
    for (name, data) in recommended.items():
        release_notes += f"* [{name}]({data['url']}) {data['version']}: {data['description']}\n"

    # Links a the very bottom:
    release_notes += '''\n# Links
* [Future milestones](https://gitlab.gnome.org/groups/World/Phosh/-/milestones)
* [Wiki](https://gitlab.gnome.org/World/Phosh/phosh/-/wikis/home)
* [Getting in touch](https://gitlab.gnome.org/World/Phosh/phosh#getting-in-touch)
* Found any errors? Please send corrections to `releases at phosh.mobi`.
'''

    if args.out:
        with open(args.out, 'w') as f:
            print(release_notes, file=f)
    else:
        print(release_notes)
    return 0


if __name__ == '__main__':
    sys.exit(main(sys.argv))