diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..6cf141e --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "1.1.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67cac62 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tools/ +.history/ diff --git a/README.md b/README.md index 449c579..c22f914 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..9d38613 --- /dev/null +++ b/build.cake @@ -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);