Skip to content

Commit

Permalink
Initial dotnet_sdk updater (#10756)
Browse files Browse the repository at this point in the history
* Initial `dotnet_sdk` updater

Closes #2442

* Apply suggestions from code review

Co-authored-by: Martin Costello <[email protected]>

* Document that we are consciously using semver for .NET SDK versioning

* Use `File.basename` for comparison

* Use `gsub` to update `global.json` instead of parsing JSON

* implement `look_up_source` in `MetadataFinder`

* regenerate `Gemfile.lock`

* bump `file_updater` from `strict` to `strong`

* Remove unnecessary  comments

* `bundle install`

* Regnerate `Gemfile.lock`

---------

Co-authored-by: Martin Costello <[email protected]>
Co-authored-by: Hariharan Thavachelvam <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2024
1 parent b760eb8 commit 0d9864e
Show file tree
Hide file tree
Showing 53 changed files with 16,085 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/ci-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ devcontainers:
docker:
- *shared
- 'docker/**'
dotnet_sdk:
- *shared
- 'dotnet_sdk/**'
elm:
- *shared
- 'elm/**'
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- changed-files:
- any-glob-to-any-file: docker/**

"L: dotnet-sdk":
- changed-files:
- any-glob-to-any-file: dotnet_sdk/**

"L: elm":
- changed-files:
- any-glob-to-any-file: elm/**
Expand Down
3 changes: 3 additions & 0 deletions .github/smoke-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ devcontainers:
docker:
- *common
- 'docker/**'
dotnet_sdk:
- *common
- 'dotnet_sdk/**'
elm:
- *common
- 'elm/**'
Expand Down
5 changes: 5 additions & 0 deletions .github/smoke-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"test": "docker",
"ecosystem": "docker"
},
{
"core": "dotnet_sdk",
"test": "dotnet-sdk",
"ecosystem": "dotnet-sdk"
},
{
"core": "elm",
"test": "elm",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- { path: common, name: common, ecosystem: common}
- { path: composer, name: composer, ecosystem: composer }
- { path: docker, name: docker, ecosystem: docker }
- { path: dotnet_sdk, name: dotnet_sdk, ecosystem: dotnet-sdk }
- { path: elm, name: elm, ecosystem: elm }
- { path: git_submodules, name: git_submodules, ecosystem: gitsubmodule }
- { path: github_actions, name: github_actions, ecosystem: github-actions }
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/images-branch.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Branch images
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
Expand Down Expand Up @@ -55,6 +55,7 @@ jobs:
- { name: cargo, ecosystem: cargo }
- { name: composer, ecosystem: composer }
- { name: docker, ecosystem: docker }
- { name: dotnet_sdk, ecosystem: dotnet-sdk }
- { name: elm, ecosystem: elm }
- { name: git_submodules, ecosystem: gitsubmodule }
- { name: github_actions, ecosystem: github-actions }
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/images-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- { name: cargo, ecosystem: cargo }
- { name: composer, ecosystem: composer }
- { name: docker, ecosystem: docker }
- { name: dotnet_sdk, ecosystem: dotnet-sdk }
- { name: elm, ecosystem: elm }
- { name: git_submodules, ecosystem: gitsubmodule }
- { name: github_actions, ecosystem: github-actions }
Expand Down
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"request": "launch",
"command": "rspec",
"cwd": "${workspaceRoot}/${input:ecosystem}",
"useBundler": true,
"script": "${file}",
"args": ["--tag", "focus"]
"rdbgPath": "bundle exec rdbg"
},
{
"name": "Debug dry run",
Expand Down Expand Up @@ -85,6 +84,7 @@
"composer",
"dep",
"docker",
"dotnet_sdk",
"elm",
"github_actions",
"go_modules",
Expand All @@ -110,6 +110,7 @@
"common",
"composer",
"docker",
"dotnet_sdk",
"elm",
"github_actions",
"go_modules",
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.updater-core
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ COPY --chown=dependabot:dependabot cargo/.bundle cargo/dependabot-cargo.gemspec
COPY --chown=dependabot:dependabot composer/.bundle composer/dependabot-composer.gemspec composer/
COPY --chown=dependabot:dependabot devcontainers/.bundle devcontainers/dependabot-devcontainers.gemspec devcontainers/
COPY --chown=dependabot:dependabot docker/.bundle docker/dependabot-docker.gemspec docker/
COPY --chown=dependabot:dependabot dotnet_sdk/.bundle dotnet_sdk/dependabot-dotnet_sdk.gemspec dotnet_sdk/
COPY --chown=dependabot:dependabot elm/.bundle elm/dependabot-elm.gemspec elm/
COPY --chown=dependabot:dependabot git_submodules/.bundle git_submodules/dependabot-git_submodules.gemspec git_submodules/
COPY --chown=dependabot:dependabot github_actions/.bundle github_actions/dependabot-github_actions.gemspec github_actions/
Expand All @@ -103,7 +104,7 @@ COPY --chown=dependabot:dependabot swift/.bundle swift/dependabot-swift.gemspec
COPY --chown=dependabot:dependabot terraform/.bundle terraform/dependabot-terraform.gemspec terraform/

# prevent having all the source in every ecosystem image
RUN for ecosystem in git_submodules terraform github_actions hex elm docker nuget maven gradle cargo composer go_modules python pub npm_and_yarn bundler silent swift devcontainers; do \
RUN for ecosystem in git_submodules terraform github_actions hex elm docker nuget maven gradle cargo composer go_modules python pub npm_and_yarn bundler silent swift devcontainers dotnet_sdk; do \
mkdir -p $ecosystem/lib/dependabot; \
touch $ecosystem/lib/dependabot/$ecosystem.rb; \
done
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "dependabot-common", path: "common"
gem "dependabot-composer", path: "composer"
gem "dependabot-devcontainers", path: "devcontainers"
gem "dependabot-docker", path: "docker"
gem "dependabot-dotnet_sdk", path: "dotnet_sdk"
gem "dependabot-elm", path: "elm"
gem "dependabot-github_actions", path: "github_actions"
gem "dependabot-git_submodules", path: "git_submodules"
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ PATH
dependabot-docker (0.283.0)
dependabot-common (= 0.283.0)

PATH
remote: dotnet_sdk
specs:
dependabot-dotnet_sdk (0.283.0)
dependabot-common (= 0.283.0)

PATH
remote: elm
specs:
Expand Down Expand Up @@ -377,6 +383,7 @@ DEPENDENCIES
dependabot-composer!
dependabot-devcontainers!
dependabot-docker!
dependabot-dotnet_sdk!
dependabot-elm!
dependabot-git_submodules!
dependabot-github_actions!
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GEMSPECS = %w(
silent/dependabot-silent.gemspec
swift/dependabot-swift.gemspec
devcontainers/dependabot-devcontainers.gemspec
dotnet_sdk/dependabot-dotnet_sdk.gemspec
).freeze

def run_command(command)
Expand Down
5 changes: 5 additions & 0 deletions bin/docker-dev-shell
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ docker run --rm -ti \
-v "$(pwd)/docker/lib:$CODE_DIR/docker/lib" \
-v "$(pwd)/docker/script:$CODE_DIR/docker/script" \
-v "$(pwd)/docker/spec:$CODE_DIR/docker/spec" \
-v "$(pwd)/dotnet_sdk/.rubocop.yml:$CODE_DIR/dotnet_sdk/.rubocop.yml" \
-v "$(pwd)/dotnet_sdk/dependabot-dotnet_sdk.gemspec:$CODE_DIR/dotnet_sdk/dependabot-dotnet_sdk.gemspec" \
-v "$(pwd)/dotnet_sdk/lib:$CODE_DIR/dotnet_sdk/lib" \
-v "$(pwd)/dotnet_sdk/script:$CODE_DIR/dotnet_sdk/script" \
-v "$(pwd)/dotnet_sdk/spec:$CODE_DIR/dotnet_sdk/spec" \
-v "$(pwd)/dry-run:$CODE_DIR/dry-run" \
-v "$(pwd)/elm/.rubocop.yml:$CODE_DIR/elm/.rubocop.yml" \
-v "$(pwd)/elm/dependabot-elm.gemspec:$CODE_DIR/elm/dependabot-elm.gemspec" \
Expand Down
3 changes: 3 additions & 0 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# - pub
# - swift
# - devcontainers
# - dotnet_sdk

# rubocop:disable Style/GlobalVars

Expand All @@ -55,6 +56,7 @@
$LOAD_PATH << "./composer/lib"
$LOAD_PATH << "./devcontainers/lib"
$LOAD_PATH << "./docker/lib"
$LOAD_PATH << "./dotnet_sdk/lib"
$LOAD_PATH << "./elm/lib"
$LOAD_PATH << "./git_submodules/lib"
$LOAD_PATH << "./github_actions/lib"
Expand Down Expand Up @@ -100,6 +102,7 @@
require "dependabot/composer"
require "dependabot/devcontainers"
require "dependabot/docker"
require "dependabot/dotnet_sdk"
require "dependabot/elm"
require "dependabot/git_submodules"
require "dependabot/github_actions"
Expand Down
1 change: 1 addition & 0 deletions common/lib/dependabot/config/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def self.parse(config)
"composer" => "composer",
"devcontainer" => "devcontainers",
"docker" => "docker",
"dotnet-sdk" => "dotnet_sdk",
"elm" => "elm",
"github-actions" => "github_actions",
"gitsubmodule" => "submodules",
Expand Down
1 change: 1 addition & 0 deletions dotnet_sdk/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BUNDLE_GEMFILE: "../dependabot-updater/Gemfile"
5 changes: 5 additions & 0 deletions dotnet_sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.bundle/
!.bundle/config
/.env
/tmp
/dependabot-*.gem
4 changes: 4 additions & 0 deletions dotnet_sdk/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inherit_from: ../.rubocop.yml

Sorbet/StrictSigil:
Enabled: true
7 changes: 7 additions & 0 deletions dotnet_sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ghcr.io/dependabot/dependabot-updater-core

USER dependabot

COPY --chown=dependabot:dependabot dotnet_sdk $DEPENDABOT_HOME/dotnet_sdk
COPY --chown=dependabot:dependabot common $DEPENDABOT_HOME/common
COPY --chown=dependabot:dependabot updater $DEPENDABOT_HOME/dependabot-updater
18 changes: 18 additions & 0 deletions dotnet_sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## `dependabot-dotnet-sdk`

.NET SDK support for [`dependabot-core`][core-repo].

### Running locally

1. Start a development shell

```
$ bin/docker-dev-shell dotnet-sdk
```

2. Run tests
```
[dependabot-core-dev] ~ $ cd dotnet-sdk && rspec
```

[core-repo]: https://github.com/dependabot/dependabot-core
33 changes: 33 additions & 0 deletions dotnet_sdk/dependabot-dotnet_sdk.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
common_gemspec =
Bundler.load_gemspec_uncached("../common/dependabot-common.gemspec")

spec.name = "dependabot-dotnet_sdk"
spec.summary = "Provides Dependabot support for .NET SDK"
spec.description = "dependabot-dotnet_sdk provides support for managing .NET SDK versioning via Dependabot."

spec.author = common_gemspec.author
spec.email = common_gemspec.email
spec.homepage = common_gemspec.homepage
spec.license = common_gemspec.license

spec.metadata = {
"bug_tracker_uri" => common_gemspec.metadata["bug_tracker_uri"],
"changelog_uri" => common_gemspec.metadata["changelog_uri"]
}

spec.version = common_gemspec.version
spec.required_ruby_version = common_gemspec.required_ruby_version
spec.required_rubygems_version = common_gemspec.required_ruby_version

spec.require_path = "lib"
spec.files = Dir["lib/**/*"]

spec.add_dependency "dependabot-common", Dependabot::VERSION

common_gemspec.development_dependencies.each do |dep|
spec.add_development_dependency dep.name, *dep.requirement.as_list
end
end
20 changes: 20 additions & 0 deletions dotnet_sdk/lib/dependabot/dotnet_sdk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# typed: strong
# frozen_string_literal: true

# These all need to be required so the various classes can be registered in a
# lookup table of package manager names to concrete classes.
require "dependabot/dotnet_sdk/file_fetcher"
require "dependabot/dotnet_sdk/file_parser"
require "dependabot/dotnet_sdk/update_checker"
require "dependabot/dotnet_sdk/file_updater"
require "dependabot/dotnet_sdk/metadata_finder"
require "dependabot/dotnet_sdk/requirement"
require "dependabot/dotnet_sdk/version"

require "dependabot/pull_request_creator/labeler"
Dependabot::PullRequestCreator::Labeler
.register_label_details("dotnet_sdk", name: "dotnet_sdk_package_manager", colour: "512BD4")

require "dependabot/dependency"
Dependabot::Dependency
.register_production_check("dotnet_sdk", ->(_) { true })
46 changes: 46 additions & 0 deletions dotnet_sdk/lib/dependabot/dotnet_sdk/file_fetcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# typed: strong
# frozen_string_literal: true

require "dependabot/file_fetchers"
require "dependabot/file_fetchers/base"
require "sorbet-runtime"

module Dependabot
module DotnetSdk
class FileFetcher < Dependabot::FileFetchers::Base
extend T::Sig

sig { override.params(filenames: T::Array[String]).returns(T::Boolean) }
def self.required_files_in?(filenames)
filenames.any? { |f| File.basename(f) == "global.json" }
end

sig { override.returns(String) }
def self.required_files_message
"Repo must contain a global.json file."
end

sig { override.returns(T::Array[Dependabot::DependencyFile]) }
def fetch_files
fetched_files = []
fetched_files << root_file

return fetched_files if fetched_files.any?

raise Dependabot::DependencyFileNotFound.new(
nil,
"global.json not found in #{directory}"
)
end

private

sig { returns(T.nilable(Dependabot::DependencyFile)) }
def root_file
fetch_file_if_present("global.json")
end
end
end
end

Dependabot::FileFetchers.register("dotnet_sdk", Dependabot::DotnetSdk::FileFetcher)
Loading

0 comments on commit 0d9864e

Please sign in to comment.