diff --git a/README.md b/README.md index c22f914..8d47e2a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A github action for running dependabot on repositories using cake-build. This action provides the features, as developed for https://github.com/dependabot/dependabot-core/pull/1848 (a PR for https://github.com/dependabot/dependabot-core/issues/733): **To have dependabot check cake-references**. -Currently dependabot does not support this and sadly merging https://github.com/dependabot/dependabot-core/pull/1848 might take some time. In the meantime it is possibe to use the code provided in the PR to do the checking "manually". +Currently dependabot does not support this and sadly merging https://github.com/dependabot/dependabot-core/pull/1848 might take some time. In the meantime it is possible to use the code provided in the PR to do the checking "manually". This action provides the means to do so. @@ -92,7 +92,7 @@ It is also possible to run this action locally: `cd src && docker build -t dependabot-cake:develop .` * run the container and give the needed environment-vars - `docker run --rm -e GITHUB_REPOSITORY=nils-a/Cake.7zip -e INPUT_TARGET_BRANCH=develop -e INPUT_TOKEN=your-github-api-token dependabot-cake:develop` + `docker run --rm -e DRY_RUN=1 -e GITHUB_REPOSITORY=nils-a/Cake.7zip -e INPUT_TARGET_BRANCH=develop -e INPUT_TOKEN=your-github-api-token dependabot-cake:develop` ## Cake targets @@ -102,6 +102,7 @@ It is also possible to run this action locally: * `--test-RepositoryName=owner/repo` to set a repository. Default: `nils-a/Cake.7zip` * `--test-RepositoryBranch=branch` to set a branch. Default: `develop` * Environment variable `INPUT_TOKEN` must be set to a personal access token. + * `--test-no-dryrun=true` if set, real PRs are created. ## Maintainers diff --git a/build.cake b/build.cake index 9d38613..2ef492a 100644 --- a/build.cake +++ b/build.cake @@ -11,6 +11,7 @@ var imageName = Argument("imageName", "dependabot-cake"); // test var testRepositoryName = Argument("test-RepositoryName", "nils-a/Cake.7zip"); var testRepositoryBranch = Argument("test-RepositoryBranch", "develop"); +var testNoDryRun = Argument("test-no-dryrun", false); /////////////////////////////////////////////////////////////////////////////// // TASKS @@ -46,26 +47,32 @@ Task("Run-Test") throw new ArgumentException("'INPUT_TOKEN' not set. Please set INPUT_TOKEN to your GitHub pat"); } - var output = DockerRun(new DockerContainerRunSettings + var envArgs = new List + { + $"GITHUB_REPOSITORY={testRepositoryName}", + $"INPUT_TARGET_BRANCH={testRepositoryBranch}", + "INPUT_TOKEN", + }; + + if (!testNoDryRun) { - Env = new string [] - { - $"GITHUB_REPOSITORY={testRepositoryName}", - $"INPUT_TARGET_BRANCH={testRepositoryBranch}", - $"INPUT_TOKEN", - }, + envArgs.Add("DRY_RUN=1"); + } + + DockerRunWithoutResult(new DockerContainerRunSettings + { + Env = envArgs.ToArray(), Rm = true, }, imageFullTag, ""); - - Information(output); }); Task("Default") .Does(() => { + Information($"test no dry-run is: {testNoDryRun}"); Warning("Currently there is no default. Chose a better target!"); }); diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..21821d2 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,13 @@ +$ErrorActionPreference = 'Stop' + +Set-Location -LiteralPath $PSScriptRoot + +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1' +$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' +$env:DOTNET_NOLOGO = '1' + +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +dotnet cake @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..31be886 --- /dev/null +++ b/build.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euox pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" + +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_NOLOGO=1 + +dotnet tool restore + +dotnet cake "$@" diff --git a/src/app/dependabot.rb b/src/app/dependabot.rb index 198c813..e9b0bbf 100755 --- a/src/app/dependabot.rb +++ b/src/app/dependabot.rb @@ -36,6 +36,9 @@ exit(1) end +# DryRun - does not create real PRs +dry_run = ENV["DRY_RUN"] && !ENV["DRY_RUN"].empty? + credentials_repository = [ { "type" => "git_source", @@ -45,7 +48,7 @@ } ] -def update(source, credentials_repository) +def update(source, credentials_repository, dry_run) # Hardcode the package manager to cake package_manager = "cake" @@ -61,6 +64,14 @@ def update(source, credentials_repository) files = fetcher.files commit = fetcher.commit + if (files.empty?) + puts " - no files found" + else + files.each do |f| + puts " - found: #{f.name} " + end + end + ############################## # Parse the dependency files # ############################## @@ -104,7 +115,7 @@ def update(source, credentials_repository) ##################################### # Generate updated dependency files # ##################################### - print " - Updating #{dep.name} (from #{dep.version})…" + puts " - Updating #{dep.name} (from #{dep.version})" updater = Dependabot::FileUpdaters.for_package_manager(package_manager).new( dependencies: updated_deps, dependency_files: files, @@ -112,22 +123,29 @@ def update(source, credentials_repository) ) updated_files = updater.updated_dependency_files - - ######################################## - # Create a pull request for the update # - ######################################## - pr_creator = Dependabot::PullRequestCreator.new( - source: source, - base_commit: commit, - dependencies: updated_deps, - files: updated_files, - credentials: credentials_repository, - label_language: false, - ) - pull_request = pr_creator.create - puts " - submitted" - - next unless pull_request + updated_files.each do |f| + puts " - file:#{f.name}" + end + + + if (dry_run) + puts " - dry run (no PR)" + next + else + ######################################## + # Create a pull request for the update # + ######################################## + pr_creator = Dependabot::PullRequestCreator.new( + source: source, + base_commit: commit, + dependencies: updated_deps, + files: updated_files, + credentials: credentials_repository, + label_language: false, + ) + pull_request = pr_creator.create + puts " - PR submitted: #{pull_request}" + end end end @@ -136,13 +154,18 @@ def update(source, credentials_repository) directory.split("\n").each do |dir| puts " - Checking #{dir} ..." - source = Dependabot::Source.new( - provider: "github", - repo: repo_name, - directory: dir.strip, - branch: target_branch, - ) - update source, credentials_repository + begin + source = Dependabot::Source.new( + provider: "github", + repo: repo_name, + directory: dir.strip, + branch: target_branch, + ) + update source, credentials_repository, dry_run + rescue Dependabot::DependencyFileNotFound + puts "ERROR: no files found in dir: #{dir}" + exit(1) + end end puts " - Done" \ No newline at end of file