Skip to content

Commit

Permalink
support SingletonManifest versions after 1.1.0
Browse files Browse the repository at this point in the history
previously all singleton manifests were parsed according to the v1.1.0
schema, which lacked a lot of fields and support for newer winget
features. Now singleton manifests can be of any schema version from
1.1.0 to 1.6.0 including, just like multi-file manifests.
  • Loading branch information
jantari committed Feb 18, 2024
1 parent 2083f15 commit cc13067
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 25 deletions.
52 changes: 28 additions & 24 deletions manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ingestManifestsWorker(autoInternalize bool, autoInternalizePath string, aut
if basemanifest.PackageIdentifier != "" && basemanifest.PackageVersion != "" &&
basemanifest.ManifestType != "" && basemanifest.ManifestVersion != "" {
if basemanifest.ManifestType == "singleton" {
var manifest = parseFileAsSingletonManifest(filepath.Join(path, file.Name()))
var manifest = parseFileAsSingletonManifest(basemanifest.ManifestVersion, filepath.Join(path, file.Name()))
logging.Logger.Debug().Str("package", basemanifest.PackageIdentifier).Str("packageversion", basemanifest.PackageVersion).Msgf("found singleton manifest")

// Singleton manifests can only contain version of a package each
Expand Down Expand Up @@ -537,43 +537,47 @@ func parseFileAsBaseManifest (path string) (*models.BaseManifest, error) {
return manifest, err
}

func parseFileAsSingletonManifest (path string) models.API_ManifestInterface {
func parseFileAsSingletonManifest (manifestVersion string, path string) models.API_ManifestInterface {
yamlFile, err := os.ReadFile(path)
if err != nil {
logging.Logger.Error().Err(err).Msg("error opening yaml file")
}

singleton := &models.Manifest_SingletonManifest_1_1_0{}
err = yaml.Unmarshal(yamlFile, singleton)
var singleton models.Manifest_SingletonManifestInterface
singleton, err = unmarshalSingletonManifest(manifestVersion, yamlFile)
if err != nil {
logging.Logger.Error().Err(err).Msg("error unmarshalling singleton")
}

manifest := singletonToStandardManifest(singleton)
manifest := singleton.ToApiManifest()

return manifest
}

func singletonToStandardManifest (singleton *models.Manifest_SingletonManifest_1_1_0) *models.API_Manifest_1_1_0 {
manifest := &models.API_Manifest_1_1_0 {
PackageIdentifier: singleton.PackageIdentifier,
Versions: []models.API_ManifestVersionInterface{ models.API_ManifestVersion_1_1_0 {
PackageVersion: singleton.PackageVersion,
DefaultLocale: models.API_DefaultLocale_1_1_0 {
PackageLocale: singleton.PackageLocale,
PackageName: singleton.PackageName,
Publisher: singleton.Publisher,
ShortDescription: singleton.ShortDescription,
License: singleton.License,
},
Channel: "",
Locales: []models.API_Locale_1_1_0{},
Installers: []models.API_Installer_1_1_0{singleton.Installers[0].ToApiInstaller()},
},
},
}
func unmarshalSingletonManifest (manifestVersion string, yamlData []byte) (models.Manifest_SingletonManifestInterface, error) {
var smanifest models.Manifest_SingletonManifestInterface

return manifest
switch manifestVersion {
case "1.1.0":
smanifest = &models.Manifest_SingletonManifest_1_1_0{}
case "1.2.0":
smanifest = &models.Manifest_SingletonManifest_1_2_0{}
case "1.4.0":
smanifest = &models.Manifest_SingletonManifest_1_4_0{}
case "1.5.0":
smanifest = &models.Manifest_SingletonManifest_1_5_0{}
case "1.6.0":
smanifest = &models.Manifest_SingletonManifest_1_6_0{}
default:
return nil, errors.New("unsupported SingletonManifest version " + manifestVersion)
}

err := yaml.Unmarshal(yamlData, smanifest)
if err != nil {
return nil, err
}

return smanifest, nil
}

func caseInsensitiveHasSuffix(s, substr string) bool {
Expand Down
21 changes: 21 additions & 0 deletions models/manifests_1_1_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ type Manifest_SingletonManifest_1_1_0 struct {
ManifestVersion string `yaml:"ManifestVersion"`
}

func (in *Manifest_SingletonManifest_1_1_0) ToApiManifest() API_ManifestInterface {
return &API_Manifest_1_1_0{
PackageIdentifier: in.PackageIdentifier,
Versions: []API_ManifestVersionInterface{
&API_ManifestVersion_1_1_0{
PackageVersion: in.PackageVersion,
DefaultLocale: API_DefaultLocale_1_1_0{
PackageLocale: in.PackageLocale,
PackageName: in.PackageName,
Publisher: in.Publisher,
ShortDescription: in.ShortDescription,
License: in.License,
},
Channel: "",
Locales: []API_Locale_1_1_0{},
Installers: []API_Installer_1_1_0{in.Installers[0].ToApiInstaller()},
},
},
}
}

// The struct for a separate version manifest file
// https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.1.0/manifest.version.1.1.0.json
type Manifest_VersionManifest_1_1_0 struct {
Expand Down
21 changes: 21 additions & 0 deletions models/manifests_1_2_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ type Manifest_SingletonManifest_1_2_0 struct {
ManifestVersion string `yaml:"ManifestVersion"`
}

func (in *Manifest_SingletonManifest_1_2_0) ToApiManifest() API_ManifestInterface {
return &API_Manifest_1_4_0{
PackageIdentifier: in.PackageIdentifier,
Versions: []API_ManifestVersionInterface{
&API_ManifestVersion_1_4_0{
PackageVersion: in.PackageVersion,
DefaultLocale: API_DefaultLocale_1_4_0{
PackageLocale: in.PackageLocale,
PackageName: in.PackageName,
Publisher: in.Publisher,
ShortDescription: in.ShortDescription,
License: in.License,
},
Channel: "",
Locales: []API_Locale_1_4_0{},
Installers: []API_Installer_1_4_0{in.Installers[0].ToApiInstaller()},
},
},
}
}

// The struct for a separate version manifest file
// https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.1.0/manifest.version.1.1.0.json
type Manifest_VersionManifest_1_2_0 struct {
Expand Down
21 changes: 21 additions & 0 deletions models/manifests_1_4_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ type Manifest_SingletonManifest_1_4_0 struct {
ManifestVersion string `yaml:"ManifestVersion"`
}

func (in *Manifest_SingletonManifest_1_4_0) ToApiManifest() API_ManifestInterface {
return &API_Manifest_1_4_0{
PackageIdentifier: in.PackageIdentifier,
Versions: []API_ManifestVersionInterface{
&API_ManifestVersion_1_4_0{
PackageVersion: in.PackageVersion,
DefaultLocale: API_DefaultLocale_1_4_0{
PackageLocale: in.PackageLocale,
PackageName: in.PackageName,
Publisher: in.Publisher,
ShortDescription: in.ShortDescription,
License: in.License,
},
Channel: "",
Locales: []API_Locale_1_4_0{},
Installers: []API_Installer_1_4_0{in.Installers[0].ToApiInstaller()},
},
},
}
}

// The struct for a separate version manifest file
// https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.4.0/manifest.version.1.4.0.json
type Manifest_VersionManifest_1_4_0 struct {
Expand Down
21 changes: 21 additions & 0 deletions models/manifests_1_5_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ type Manifest_SingletonManifest_1_5_0 struct {
ManifestVersion string `yaml:"ManifestVersion"`
}

func (in *Manifest_SingletonManifest_1_5_0) ToApiManifest() API_ManifestInterface {
return &API_Manifest_1_5_0{
PackageIdentifier: in.PackageIdentifier,
Versions: []API_ManifestVersionInterface{
&API_ManifestVersion_1_5_0{
PackageVersion: in.PackageVersion,
DefaultLocale: API_DefaultLocale_1_5_0{
PackageLocale: in.PackageLocale,
PackageName: in.PackageName,
Publisher: in.Publisher,
ShortDescription: in.ShortDescription,
License: in.License,
},
Channel: "",
Locales: []API_Locale_1_5_0{},
Installers: []API_Installer_1_5_0{in.Installers[0].ToApiInstaller()},
},
},
}
}

// The struct for a separate version manifest file
// https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.5.0/manifest.version.1.5.0.json
type Manifest_VersionManifest_1_5_0 struct {
Expand Down
21 changes: 21 additions & 0 deletions models/manifests_1_6_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ type Manifest_SingletonManifest_1_6_0 struct {
ManifestVersion string `yaml:"ManifestVersion"`
}

func (in *Manifest_SingletonManifest_1_6_0) ToApiManifest() API_ManifestInterface {
return &API_Manifest_1_6_0{
PackageIdentifier: in.PackageIdentifier,
Versions: []API_ManifestVersionInterface{
&API_ManifestVersion_1_6_0{
PackageVersion: in.PackageVersion,
DefaultLocale: API_DefaultLocale_1_6_0{
PackageLocale: in.PackageLocale,
PackageName: in.PackageName,
Publisher: in.Publisher,
ShortDescription: in.ShortDescription,
License: in.License,
},
Channel: "",
Locales: []API_Locale_1_6_0{},
Installers: []API_Installer_1_6_0{in.Installers[0].ToApiInstaller()},
},
},
}
}

// The struct for a separate version manifest file
// https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.6.0/manifest.version.1.6.0.json
type Manifest_VersionManifest_1_6_0 struct {
Expand Down
4 changes: 4 additions & 0 deletions models/manifests_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (basemanifest BaseManifest) ToMultiFileManifest() MultiFileManifest {
}
}

type Manifest_SingletonManifestInterface interface {
ToApiManifest() API_ManifestInterface
}

type Manifest_VersionManifestInterface interface {
GetPackageVersion() string
}
Expand Down
3 changes: 2 additions & 1 deletion packages/bottom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Installers:
InstallerUrl: "https://github.com/ClementTsang/bottom/releases/download/0.6.8/bottom_x86_64_installer.msi"
InstallerSha256: "43A860A1ECAC287CAF9745D774B0B2CE9C0A2A79D4048893E7649B0D8048EE58"
#SignatureSha256: ""
DownloadCommandProhibited: true
ManifestType: singleton
ManifestVersion: 1.1.0
ManifestVersion: 1.6.0

0 comments on commit cc13067

Please sign in to comment.