Skip to content

Change the order of package tags when generate package metadata

What does this MR do and why?

In case when packages are published into multiple projects, there could be duplicate tags. The most common variant is duplicate latest tag. Now when we do a mapping of tag to a package's version, the latest package's version will be always overridden by the earliest since we do a mapping using a Hash.

This MR changes how we get the tags from database to fetch only most recent tags with distinct names.

Screenshots or screen recordings

No.

How to set up and validate locally

Execute the following commands in the Rails console.

  1. Create two packages with the tags in two different projects under the same namespace.

    # stub file upload
    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
    
    g = FactoryBot.create(:group, name: 'test-group')
    p1 = FactoryBot.create(:project, namespace: g)
    p2 = FactoryBot.create(:project, namespace: g)
    
    package1 = FactoryBot.create(:npm_package, project: p1, name: '@test-group/test-package', version: '1.0.0')
    package2 = FactoryBot.create(:npm_package, project: p2, name: '@test-group/test-package', version: '2.0.0')
    
    FactoryBot.create(:packages_tag, package: package1, name: 'latest')
    FactoryBot.create(:packages_tag, package: package2, name: 'latest')
  2. Generate package metadata and check the version marked latest in the dist-tags.

    Packages::Npm::GenerateMetadataService.new('@test-group/test-package', Packages::Package.where(name: '@test-group/test-package')).execute

    If everything works correctly the latest tag should point to the version 2.0.0.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #428626 (closed)

Edited by Dzmitry Meshcharakou

Merge request reports