Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add versioning to sources.json #1069

Merged
merged 6 commits into from
Jan 10, 2025

Conversation

datenreisender
Copy link
Contributor

@datenreisender datenreisender commented Jan 9, 2025

For NCD-1128:

Effect of this change

Before we had an used a file sources.json which looked like this:

{
  "official": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/apps.json"
  "Test": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/test/apps.json"
}

This change introduces that instead a sources-versioned.json is used instead, which will look like this:

{
  "v1": [
    {
      "name": "official",
      "url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/source.json"
    },
    {
      "name": "Test",
      "url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/test/source.json"
    }
  ]
}

If an existing sources.json is found it is left untouched but the content is migrated to a new sources-versioned.json. If an sources-versioned.json is found, no migration is done. If neither a sources.json nor a sources-versioned.json is found, a new sources-versioned.json is created.

After the migration, only the contents of sources-versioned.json are used, any existing sources.json is ignored.

Motivation

With the move to Artifactory, I want to extend sources-versioned.json so that it can look like this:

{
  "v1": [
    {
      "name": "official",
      "url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/source.json"
    },
    {
      "name": "Test",
      "url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/test/source.json"
    }
  ]
  "v2": [
    {
      "name": "official",
      "url": "https://files.nordicsemi.com/ui/api/v1/download?isNativeBrowsing=false&repoKey=swtools&path=external/ncd/apps/official/source.json"
    },
    {
      "name": "Test",
      "url": "https://files.nordicsemi.com/ui/api/v1/download?isNativeBrowsing=false&repoKey=swtools&path=internal/ncd/apps/test/source.json"
    }
  ]
}

The idea is, that new versions of the launcher can use the new version v2 in this file, while old versions of the launcher can continue to use the old information.

It already would have been helpful and simplified the code if we had done a change like this when switching to using the new app meta data in #804. But now it is helpful too and if it already was helpful twice it might prove to be helpful again in the future.

Schema validation

Besides the migration to sources-versioned.json this change also adds schema validation to source.json. So the contents of all JSON files that are read of written there are also validated with zod.

@datenreisender datenreisender added doc not required All PRs either need "doc required" or "doc not required". ui not required All PRs either need "ui required" or "ui not required". labels Jan 9, 2025
@datenreisender datenreisender changed the title Version sources.json Add versioning to sources.json Jan 9, 2025
@datenreisender datenreisender marked this pull request as ready for review January 10, 2025 09:51
Comment on lines -37 to -41
const isLegacyUrl = url.endsWith('/apps.json') && sourceJson.apps == null;
if (isLegacyUrl) {
return downloadSource(url.replace(/apps\.json$/, 'source.json'));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure I get the intention here, but why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost two years after we switched from using apps.json to source.json files, I consider this code to be unneeded and wanted to clean up by removing it.

The only case when it would still be used, would be if someone would add a URL like https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/test/apps.json (instead of …/source.json) in the dialog to add a source.

Copy link
Contributor

@boundlesscalm boundlesscalm left a comment

Choose a reason for hiding this comment

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

Apart from a question I posted this looks nice and clean to me!

@datenreisender datenreisender merged commit 09ac742 into main Jan 10, 2025
6 checks passed
@datenreisender datenreisender deleted the feat/artifactory/versioned_sources.json branch January 10, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc not required All PRs either need "doc required" or "doc not required". ui not required All PRs either need "ui required" or "ui not required".
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants