Skip to content

Commit

Permalink
Merge pull request #9 from nils-org/feature/GH-8
Browse files Browse the repository at this point in the history
(#8) added ignore to action
  • Loading branch information
nils-a authored Apr 27, 2021
2 parents 4fee129 + b5eafa7 commit 0ac97d5
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 57 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"cSpell.words": [
"asciidoctorj",
"cakebuild",
"dependabot",
"dryrun"
]
}
56 changes: 39 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ A github action for running dependabot on repositories using cake-build.

## Table of Contents

- [Background](#background)
- [Goal](#goal)
- [Install](#install)
- [Usage](#usage)
- [Limitations](#limitations)
- [Idea / Attribution](#idea--attribution)
- [Full Example](#full-example)
- [Background](#background)
- [Idea / Attribution](#idea--attribution)
- [Running Locally](#running-locally)
- [Alternatives](#alternatives)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)

## Background

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**.
## Goal

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".
The goal of this project is two-fold:
- Enable users of dependabot to have a dependabot-like way to keep Cake dependencies up-to-date.
- To keep the code for integrating Cake as a new ecosystem in dependabot up-to-date and tested.

This action provides the means to do so.
To that end, I have forked the original PR into a [custom repo](https://github.com/nils-org/dependabot-core/tree/cake/main)
where I try to keep the original code from [dependabot-PR 1848](https://github.com/dependabot/dependabot-core/pull/1848) up-to-date
and error-free.

## Install

Expand Down Expand Up @@ -51,19 +55,19 @@ Use the action in your workflow yaml by adding a step with `uses: nils-org/depen
# [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
# default: ${{ github.token }}
token: ""

# List of dependencies that will not be updated
# Example:
# ignore: |
# Cake.7zip
# Cake.asciidoctorj
# default: none
ignore: ""
```
## Limitations
This not a real dependabot, so there so "commands" to give (like `@dependabot rebase` and such). If you need to rebase the PR, you'll have to do that manually.

TODOs:
* Check what happens when a PR is not merged and closed. Will it simply be re-created every run?
* How to "ignore" dependencies?

## Idea / Attribution

Most of this was shamelessly copied from https://github.com/patrickjahns/dependabot-terraform-action/
This not a real dependabot, so there are no "commands" to give (like `@dependabot rebase` and such). If you need to rebase the PR, you'll have to do that manually.

## Full Example
Save the following content in you're repo under `.github/workflows/dependabot-cake.yml`
Expand All @@ -83,6 +87,16 @@ jobs:
uses: nils-org/dependabot-cake-action@v1
```

## Background

The original code was 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 has postponed adding new ecosystems and sadly merging https://github.com/dependabot/dependabot-core/pull/1848 might take some time.

## Idea / Attribution

Most of this was shamelessly copied from https://github.com/patrickjahns/dependabot-terraform-action/

## Running Locally
It is also possible to run this action locally:

Expand All @@ -92,7 +106,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 +116,14 @@ 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-folder=subfolder` to set a folder to search. Can be given multiple times. Default: `["/"]`
* `--test-no-dryrun` if set, real PRs are created.
* `--test-ignore=Cake.7zip` ignore a dependency. Can be given multiple times. Default: `[]`

## Alternatives

One alternative to dependabot is [Renovate](https://www.whitesourcesoftware.com/free-developer-tools/renovate/)
which fully supports Cake. See the [post on cakebuild.net](https://cakebuild.net/blog/2021/04/cake-support-in-renovate) for a sample integration.

## Maintainers

Expand Down
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ inputs:
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
default: ${{ github.token }}
required: false
ignore:
description: >
List of dependencies that will not be updated
Example:
ignore: |
Cake.7zip
Cake.asciidoctorj
required: false

runs:
using: 'docker'
image: 'docker://nilsa/dependabot-cake:v1.0.1'
image: 'docker://ghcr.io/nils-org/dependabot-cake-action:1.1.0-GH-8.1'
branding:
icon: 'package'
color: 'orange'
53 changes: 44 additions & 9 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var imageName = Argument("imageName", "dependabot-cake");
// test
var testRepositoryName = Argument("test-RepositoryName", "nils-a/Cake.7zip");
var testRepositoryBranch = Argument("test-RepositoryBranch", "develop");
var testFolders = Arguments<string>("test-folder", null).Where(x => x != null).ToList();
var testIgnore = Arguments<string>("test-ignore", null).Where(x => x != null).ToList();
var testNoDryRun = HasArgument("test-no-dryrun");

///////////////////////////////////////////////////////////////////////////////
// TASKS
Expand Down Expand Up @@ -41,31 +44,63 @@ Task("Run-Test")
.IsDependentOn("Build-Image")
.Does(() =>
{
Information($"running test on RepositoryName:{testRepositoryName} branch:{testRepositoryBranch}");
if(testFolders.Count > 0)
{
Information($"searching in folders: {string.Join(", ", (IEnumerable<string>)testFolders)}");
}
if(testIgnore.Count > 0)
{
Information($"ignoring packages: {string.Join(", ", (IEnumerable<string>)testIgnore)}");
}
if(testNoDryRun)
{
Warning("NO-DRY-RUN is set. Real PRs will be created.");
}

var branches = string.Join("\n", testRepositoryBranch);

var envArgs = new List<string>
{
$"GITHUB_REPOSITORY={testRepositoryName}",
$"INPUT_TARGET_BRANCH={branches}",
"INPUT_TOKEN",
};

if (testFolders.Count > 0)
{
envArgs.Add($"INPUT_DIRECTORY={string.Join("\n", (IEnumerable<string>)testFolders)}");
}

if (!testNoDryRun)
{
envArgs.Add("DRY_RUN=1");
}

if(testIgnore.Count > 0)
{
envArgs.Add($"INPUT_IGNORE={string.Join("\n", (IEnumerable<string>)testIgnore)}");
}

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
DockerRunWithoutResult(new DockerContainerRunSettings
{
Env = new string []
{
$"GITHUB_REPOSITORY={testRepositoryName}",
$"INPUT_TARGET_BRANCH={testRepositoryBranch}",
$"INPUT_TOKEN",
},
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 "$@"
Loading

0 comments on commit 0ac97d5

Please sign in to comment.