Skip to content

Add Desktop Entry and AppStream - #236

Open
JakobDev wants to merge 6 commits into
liftoff-app:masterfrom
JakobDev:linuxmeta
Open

Add Desktop Entry and AppStream#236
JakobDev wants to merge 6 commits into
liftoff-app:masterfrom
JakobDev:linuxmeta

Conversation

@JakobDev

@JakobDev JakobDev commented Jul 3, 2023

Copy link
Copy Markdown

This are needed for the Linux Desktop e.g. Flatpak. Please include this files in the Linux build together with the SVG image.

Please always update the Version in the AppStream file before releasing a Update.

@shocklateboy92

Copy link
Copy Markdown
Collaborator

Please always update the Version in the AppStream file before releasing a Update.

Could you add a script to do so that'll be invoked as part of our release scripts?
@zachatrocity can point to which ones exactly.

@zachatrocity

Copy link
Copy Markdown
Collaborator

It should be added to the release job in the release workflow:

https://github.com/liftoff-app/liftoff/blob/master/.github/workflows/release.yml#L135

@JakobDev

JakobDev commented Jul 4, 2023

Copy link
Copy Markdown
Author

So this CI will run before releasing a new Update?

@shocklateboy92

Copy link
Copy Markdown
Collaborator

Yep. If you make it edit the AppStream file, there's no risk of us forgetting.

@JakobDev

JakobDev commented Jul 5, 2023

Copy link
Copy Markdown
Author

Does the CI also commit the changed files to the Repo, so builds from source will also work?

@shocklateboy92 shocklateboy92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, it turns out @zachatrocity runs this script locally when releasing:
https://github.com/liftoff-app/liftoff/blob/master/scripts/release.dart

Please update that to modify the appstream file. Then it'll always get done on every release.

@JakobDev

JakobDev commented Jul 6, 2023

Copy link
Copy Markdown
Author

The AppStream can also contains the Changelog. Is the changelog always a Markdown Bullet List, so I can convert it to the Format used by AppStream?

@zachatrocity

Copy link
Copy Markdown
Collaborator

There is quite a bit of changelog handling code in that release.dart file, that script parses the markdown and builds a release log. It writes it to fastlane, you should be able to add something similar for app stream around here:

https://github.com/liftoff-app/liftoff/blob/master/scripts/release.dart#L115

@JakobDev

JakobDev commented Jul 6, 2023

Copy link
Copy Markdown
Author

I have modified the script. Just save the AppStream file as test.xml to test this:

Future<void> updateChangelog(Version version) async {
  final changelogFile = File('CHANGELOG.md');
  final changelogContents = await changelogFile.readAsString();

  var currentChangelog =
      RegExp(r'^## Unreleased$.+?^##[^#]', multiLine: true, dotAll: true)
          .stringMatch(changelogContents);

  if (currentChangelog == null) {
    printError('No changelog found');
  }

  currentChangelog = currentChangelog.substring(0, currentChangelog.length - 4);

  final date = DateTime.now();
  final dateString =
      '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';

  currentChangelog = currentChangelog.replaceFirst(
      'Unreleased', 'v${version.toStringNoCode()} - $dateString');

  confirm('Changelog looks good?\n$currentChangelog\n');

  //await changelogFile.writeAsString(changelogContents.replaceFirst(
  //    'Unreleased', 'v${version.toStringNoCode()} - $dateString'));

  //await File('fastlane/metadata/android/en-US/changelogs/${version.code}.txt')
  //    .writeAsString(currentChangelog.split('\n').skip(2).join('\n'));

  String appStreamRelease =
      '    <release version="v${version.toStringNoCode()}" date="${dateString}" type="stable">\n';
  appStreamRelease +=
      '      <url>https://github.com/liftoff-app/liftoff/releases/tag/v${version.toStringNoCode()}</url>\n';
  appStreamRelease += '      <description>\n';
  appStreamRelease += '        <ul>\n';
  currentChangelog.split('\n').forEach((String element) {
    if (!element.isEmpty && element.startsWith("-")) {
      appStreamRelease += '          <li>' + element.substring(2) + '</li>\n';
    }
  });
  appStreamRelease += '        </ul>\n';
  appStreamRelease += '      </description>\n';
  appStreamRelease += '    </release>';

  final appStreamFile = File('test.xml');
  final appStreamContent = await appStreamFile.readAsString();
  final releaseIndex =
      appStreamContent.indexOf("<releases>") + "<releases>".length.toInt();
  final newAppStreamContent = appStreamContent.substring(0, releaseIndex) +
      "\n" +
      appStreamRelease +
      appStreamContent.substring(releaseIndex);
  print(newAppStreamContent);
}

I don't know if dart includes a XML parser (First time I worked with Dart), so I just used strings, which is a bit hacky. Is this script OK for you? If yes, I can use the correct path and write to the File instead of printing.

@shocklateboy92

Copy link
Copy Markdown
Collaborator

To be honest, I'd prefer you use the dart xml package:
https://pub.dev/packages/xml

It looks reasonably easy to use (even supports XPath), and will be much more robust than strings.
I'd hate for you to have to come back here and make a fix to appstream because some formatting changed in the xml.

@JakobDev

Copy link
Copy Markdown
Author

Here is the version using the xml package (they should add better documentation):

Future<void> updateChangelog(Version version) async {
  final changelogFile = File('CHANGELOG.md');
  final changelogContents = await changelogFile.readAsString();

  var currentChangelog =
      RegExp(r'^## Unreleased$.+?^##[^#]', multiLine: true, dotAll: true)
          .stringMatch(changelogContents);

  if (currentChangelog == null) {
    printError('No changelog found');
  }

  currentChangelog = currentChangelog.substring(0, currentChangelog.length - 4);

  final date = DateTime.now();
  final dateString =
      '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';

  currentChangelog = currentChangelog.replaceFirst(
      'Unreleased', 'v${version.toStringNoCode()} - $dateString');

  confirm('Changelog looks good?\n$currentChangelog\n');

  //await changelogFile.writeAsString(changelogContents.replaceFirst(
  //    'Unreleased', 'v${version.toStringNoCode()} - $dateString'));

  //await File('fastlane/metadata/android/en-US/changelogs/${version.code}.txt')
  //    .writeAsString(currentChangelog.split('\n').skip(2).join('\n'));

  var appStreamList = new XmlElement(new XmlName('ul'));
  currentChangelog.split('\n').forEach((String element) {
    if (element.isNotEmpty && element.startsWith("-")) {
      var appStreamListElement = new XmlElement(new XmlName('li'));
      appStreamListElement.innerText = element.substring(2);
      appStreamList.children.add(appStreamListElement);
    }
  });

  var appStreamDescription = new XmlElement(new XmlName('description'));
  appStreamDescription.children.add(appStreamList);

  var appStreamURL = new XmlElement(new XmlName('url'));
  appStreamURL.innerText =
      'https://github.com/liftoff-app/liftoff/releases/tag/v${version.toStringNoCode()}';

  var currentRelaseTag = new XmlElement(new XmlName('release'));
  currentRelaseTag.setAttribute('version', 'v${version.toStringNoCode()}');
  currentRelaseTag.setAttribute('date', dateString);
  currentRelaseTag.setAttribute('type', 'stable');
  currentRelaseTag.children.add(appStreamURL);
  currentRelaseTag.children.add(appStreamDescription);

  final appStreamFile = File('test.xml');
  var appStreamXML = XmlDocument.parse(await appStreamFile.readAsString());
  var releasesTag = appStreamXML.rootElement.getElement('releases');
  if (releasesTag != null) {
    releasesTag.children.insert(0, currentRelaseTag);
  } else {
    print("Can't find releases tag");
  }
  print(appStreamXML.toXmlString(pretty: true));
}

Another big problem that needs to be solved before merging is, what the App ID should be. liftof currently uses com.liftoffapp.liftoff, but this is not valid, as liftofapp.com is not owned by the Devs. For discussions take a look at #37.

@shocklateboy92

Copy link
Copy Markdown
Collaborator

@zachatrocity you good to test this?

@zachatrocity

Copy link
Copy Markdown
Collaborator

Yeah I can test this

@zachatrocity

Copy link
Copy Markdown
Collaborator

@JakobDev can you actually commit the changes to your branch? Also we'll need to tweak the dbus name even though its considered bad practice, we have too many users on ios/android to change the app id now.

@JakobDev

Copy link
Copy Markdown
Author

@JakobDev can you actually commit the changes to your branch?

Done

Also we'll need to tweak the dbus name even though its considered bad practice, we have too many users on ios/android to change the app id now.

If you can do that for Linux Desktop, then that's no problem. Just make sure, everything uses the same ID under Linux. Tell em your new ID, so I can update the files in this PR.

These files also needed to be included in the linux.tar.gz archive, but i don't know how to do this.

@JakobDev JakobDev mentioned this pull request Aug 28, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants