Skip to content

Commit

Permalink
(maint) added some testing capabilities
Browse files Browse the repository at this point in the history
so that not everytime a test is run, a PR is created.
  • Loading branch information
nils-a committed Apr 25, 2021
1 parent 4fee129 commit 9ab3519
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 36 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
25 changes: 16 additions & 9 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("test-no-dryrun", false);

///////////////////////////////////////////////////////////////////////////////
// TASKS
Expand Down Expand Up @@ -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<string>
{
$"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!");
});

Expand Down
13 changes: 13 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -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 }
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
73 changes: 48 additions & 25 deletions src/app/dependabot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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 #
##############################
Expand Down Expand Up @@ -104,30 +115,37 @@ 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,
credentials: 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
Expand All @@ -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"

0 comments on commit 9ab3519

Please sign in to comment.