Skip to content

Commit

Permalink
(maint) added a real simple Cake file
Browse files Browse the repository at this point in the history
to build the image and run tests
  • Loading branch information
nils-a committed Apr 24, 2021
1 parent bd0d0bf commit 46cc5d7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "1.1.0",
"commands": [
"dotnet-cake"
]
}
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tools/
.history/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ It is also possible to run this action locally:

`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`

## Cake targets

* `Build-Image` Creates the image.
* `imageName=some-image-name` to set the image name. Default: `dependabot-cake`
* `Run-Test` Runs a container off the image locally. Settings:
* `--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.

## Maintainers

Expand Down
72 changes: 72 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#tool dotnet:?package=GitVersion.Tool&version=5.6.8
#addin nuget:?package=Cake.Docker&version=1.0.0

///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////

var target = Argument("target", "Default");
var imageName = Argument("imageName", "dependabot-cake");

// test
var testRepositoryName = Argument("test-RepositoryName", "nils-a/Cake.7zip");
var testRepositoryBranch = Argument("test-RepositoryBranch", "develop");

///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////

var imageFullTag = "";
Task("Calculate-Image-Tag")
.Does(() =>
{
var version = GitVersion();
imageFullTag = $"{imageName}:{version.SemVer}";
Information($"calculated tag for image: {imageFullTag}");
});


Task("Build-Image")
.IsDependentOn("Calculate-Image-Tag")
.Does(() =>
{
DockerBuild(new DockerImageBuildSettings
{
Tag = new[] {imageFullTag},
}, "src");
});

Task("Run-Test")
.IsDependentOn("Calculate-Image-Tag")
.IsDependentOn("Build-Image")
.Does(() =>
{
if(string.IsNullOrEmpty(EnvironmentVariable("INPUT_TOKEN")))
{
throw new ArgumentException("'INPUT_TOKEN' not set. Please set INPUT_TOKEN to your GitHub pat");
}

var output = DockerRun(new DockerContainerRunSettings
{
Env = new string []
{
$"GITHUB_REPOSITORY={testRepositoryName}",
$"INPUT_TARGET_BRANCH={testRepositoryBranch}",
$"INPUT_TOKEN",
},
Rm = true,
},
imageFullTag,
"");

Information(output);
});



Task("Default")
.Does(() => {
Warning("Currently there is no default. Chose a better target!");
});

RunTarget(target);

0 comments on commit 46cc5d7

Please sign in to comment.