Git Product home page Git Product logo

cake-action's Introduction

Cake for GitHub Actions

GitHub Marketplace GitHub Actions Build GitHub Actions Tests Coveralls

This action allows you to run a Cake script from your GitHub Actions workflow without having to use a bootstrapper.

Usage

Using the Cake action from a GitHub Actions workflow is as simple as referencing this repository from a build step:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2

The Cake action will look for a script named build.cake in your repository's root directory and run it for you using the Cake Tool. All output from the Cake script will be automatically redirected to the build log for inspection.

Inputs

script-path

If your script is in another location, you can specify the path with the script-path input parameter:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      script-path: path/to/script.cake

target

You'll likely want to specify which task to run out of the ones defined in the Cake script. For that, you can use the target parameter:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      target: Task-To-Run

verbosity

You can adjust the amount of information Cake sends to the build log by changing the verbosity level with the verbosity parameter:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      verbosity: Diagnostic

The supported verbosity levels are Quiet, Minimal, Normal, Verbose and Diagnostic. The default level is set to Normal.

dry-run

While developing a script, you'll sometimes want to see which tasks would be triggered by a given target without actually running them. That's exactly what the dry-run parameter is for:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      dry-run: true

When dry-run is set to true, Cake will print out the names of the tasks to run according to the dependency graph, but it won't perform any of the instructions defined in them.

arguments

If your script defines any custom parameters, you can specify arguments for them by using the arguments parameter:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      arguments: |
        name: value
        configuration: Release

The arguments are defined in a multi-line string literal where each argument is on a separate line in the format name: value. Keep in mind that the values you specify here are passed as is to the Cake script; this means that characters like quotes are kept intact (for example, name: 'value' will result in --name='value' being passed to the script).

cake-version

By default, the Cake action will run your script using the latest stable version of the Cake .NET Core Global tool. However, if for some reason you want to use a specific version of Cake (for compatibility with older third-party addins, for example), you can do so by specifying the version number in the cake-version parameter:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      cake-version: 0.30.0

If you're pinning your Cake version using a tool manifest file, then you can have the action restore any local tools, including Cake, by specifying tool-manifest as the argument for cake-version:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      cake-version: tool-manifest

cake-bootstrap

As of Cake 1.0.0, any custom modules that you reference in your script are bootstrapped automatically upon running it.

If you're using an older version of Cake, however, you need to explicitly bootstrap them before running the script. The Cake action can take care of this extra step for you by setting the cake-bootstrap parameter to explicit:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      cake-bootstrap: explicit
      cake-version: 0.38.5

If you're using Cake 1.0.0 or later and wish to opt out of the automatic bootstrapping of modules, you can do so by setting the cake-bootstrap parameter to skip:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v2
    with:
      cake-bootstrap: skip

The default value is auto, which means that the modules will be automatically bootstrapped on Cake 1.0.0 or later.

Cross-platform

Since the Cake Tool is built on .NET Core, the Cake action will run on any of the virtual environments supported by GitHub Actions, namely Linux, Windows and macOS.

This allows you to define your build step exactly once and run it on multiple operating systems in parallel by defining a build matrix:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [windows-latest, ubuntu-latest, macOS-latest]
    steps:
      - name: Get the sources
        uses: actions/checkout@v1
      - name: Run the build script
        uses: cake-build/cake-action@v2
        with:
          target: Build

You can read more about how to define a build matrix in the workflow syntax for GitHub Actions.

cake-action's People

Contributors

baynezy avatar dependabot[bot] avatar devlead avatar ecampidoglio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cake-action's Issues

Add support for the dry run option

Cake offers the option to do a dry run of the build script by passing the --dry-run argument to the Cake executable.

It should be possible to do the same from a GitHub Actions workflow by setting the dry-run input parameter to true:

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@v1
    with:
      dry-run: true

Of course, the default value should be false.

1.1.0 broke version parameter

cbd362d#diff-6a7166c4d6d46136f0efc2a724763a85R37

+    if (version && !targetDirectory.containsToolWithVersion(packageId, version)) {
+          throw new Error(`Failed to uninstall previous version of ${packageId}. Exit code: ${uninstallExitCode}`);
+      await DotNet.uninstallLocalTool(packageId, targetDirectory);

Before it checked if cake was installed and then checked if version was specified and uninstalled.

[Question] I do not understand below error

ITNOA

Hi

I do not understand my error

Run cake-build/cake-action@v1
dotnet tool install --tool-path tools Cake.Tool
You can invoke the tool using the following command: dotnet-cake
Tool 'cake.tool' (version '3.1.0') was successfully installed.
tools/dotnet-cake Build/linux-build.cake --target=JustBuild --verbosity=Diagnostic --version=0.1.0

Error: Flags cannot be assigned a value.

       Build/linux-build.cake --target=JustBuild --verbosity=Diagnostic 
--version=0.1.0
                                                                        
^^^^^^^^^ Can't assign value

Can you help me?

My project is BSVN/IpTables.Api#2

Add support for workingDirectory

I would like to have support to set workingDirectory where the script runs and searches for the toolsDirectory.

Cause I have some trouble when running cake scripts that are not in root of the git repository.
I also use some tools manifest, but this cant be read by the action as its working directory seems to be root of git repository.

Error looks like this:
Run cake-build/cake-action@v1
dotnet tool restore
Es wurde keine Manifestdatei gefunden.

My repository looks like this:
scripts

  • build1.cake
  • build2.cake
  • .config
    • dotnet-tools.json

When i run script without version "tool-manifest" it works, but i would like to stick the cake-version in manifest.
Also it creates 2 tools directories. one in root (with dotnet-cake.exe)
and one in scripts directory (with scripts dependencies) where my cake scripts are located.

Not finding build.cake

Hi,

I have a very simple github workflow that looks like:

name: push-master
run-name: ${{ github.actor }} is pushing to master
on: 
  push:
  pull_request:
    branches:
      - master
jobs:
  test-push-master:
    runs-on: ubuntu-latest
    steps:
      - name: run cake script
        uses: cake-build/cake-action@master
        with:
          verbosity: Diagnostic

When I try to run this I get the following error message:
build.cake, line #0: Could not find script '/home/runner/work/algo-charging/algo-charging/build.cake'.

I do have a build script in the root:
https://github.com/AlgoCharging/algo-charging/blob/master/build.cake

Any ideas what might be the problem?

Update to Node16

Running the action currently produces a warning:

Node.js 12 actions are deprecated. For more information 
see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. 
Please update the following actions to use Node.js 16: cake-build/cake-action

Feature request: csproj / Cake.Frosting support

Would be nice to be able to use the action with Frosting too, something like

steps:
  - name: Run the Cake script
    uses: cake-build/cake-action@vX
    with:
      arguments: |
        name: value
      target: Build
      verbosity: Diagnostic
      csproj: ./build/build.csproj

resulted in something like below being executed

dotnet run --project ./build/build.csproj -- --target="Build" --verbosity="Diagnostic" --name="value"

Can we move this repository into the Cake Organisation?

Things to consider...

Moving the repository

  • Transfer repository to individual user within Cake Team
  • Repository will be transferred to Cake Organiation
  • Invite @ecampidoglio to Cake Organisation, with full permissions to Cake Actions repository
  • Invite @ecampidoglio to Cake Slack Team
  • Follow @ecampidoglio from Cake/Cake-Contrib Twitter Account
  • Update .Net Foundation information adding @ecampidoglio information
  • Update copyright information with @ecampidoglio information

The latest Cake version is not always honoured

Background

Running the action without specifying the --cake-version input parameter implies installing the latest version of the Cake.Tool package. This is achieved by running dotnet tool install without the --version parameter.

The Problem

While this approach works fine in most cases, there's one scenario where it falls short: when the action runs on an agent where a different version of the Cake.Tool package is already installed.

Here's an example workflow:

  1. The Cake action runs with the --cake-version set to x.y.z
  2. Version x.y.z of the Cake.Tool is installed in the tools directory
  3. The Cake action runs again, only this time without the --cake-version input parameter implying that the latest version of Cake should be used
  4. The action sees that the Cake.Tool is already present in the tools directory; however, without a specific version number to compare with, it determines that it shouldn't install any new version of the Cake.Tool and runs with it
  5. The user thinks that the action is running with the latest version of Cake, while in reality it's running with whatever version was alreaady installed in the tools directory

Proposed Solution

When running the action without the --cake-version input parameter, the action should go out and fetch the latest version of the Cake.Tool from the Cake releases on GitHub and use that as the version number.

This way, there will always be a version number to compare with when determining whether any existing installation of the Cake.Tool can be used.

Risks

In the case when fetching the latest version from GitHub fails for some reason (e.g. due to a network error), the action should simply fall back to the previous behavior of installing the Cake.Tool without a version number.

Using the Cake Action multiple times in the same build causes the workflow to fail

Right now, if you use the Cake Action in multiple steps within the same build definition, like in this example:

steps:
  - name: Compile
    uses: ecampidoglio/[email protected]
    with:
      target: Compile
  - name: Run the tests
    uses: ecampidoglio/[email protected]
    with:
      target: Test

The second step will fail with the following error message:

dotnet tool install --tool-path tools Cake.Tool
Tool 'cake.tool' is already installed.
##[error]The process 'dotnet' failed with exit code 1

That's because the Cake Action tries to install the Cake.Tool before every run, which obviously doesn't work if the tool has already been installed by a previous instance.

The action never finishes

Hi,

I'm running into issues that the following script hangs sometimes when trying to run the cake script step. The action never finishes

name: push-master
run-name: ${{ github.actor }} is pushing to master
on: 
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  push-master:
    runs-on: ubuntu-latest
    steps:
      - name: Get the source
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Install .NET SDK 7.0.x
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: '7.0.x'
      - name: run cake script
        uses: cake-build/cake-action@master

Any ideas what might be reason

Allow to specify the verbosity level

When troubleshooting a Cake script, it's often necessary to increase the verbosity level to something like Diagnostic to see what's going on behind the scenes.

This technique is particular useful when the script works locally but fails in a CI environment, since it's impractical to debug a build server.

For these reasons, the Cake Action should allow to specify the verbosity level to pass to the Cake script as an input parameter.

Feature request: inline Cake script support💡

Many GitHub script actions support inline scripts i.e. Azure CLI task

      with:
        inlineScript: |
          az account show
          az storage -h

When doing a Frosting bootstrapper workaround until #43 is solved I did something like

      - name: Create Script Bootstrapper
        run: |
          echo 'DotNetRun("build/Build.csproj", "--target=GitHub-Actions");' > build.cake

      - name: Run Cake script
        uses: cake-build/cake-action@v2
        with:
          cake-version: 4.0.0

and it struck me that it would be really useful for some scenarios to instead of a small utility shell script able to have a Cake script inline, above could then be

      - name: Run Inline Cake script
        uses: cake-build/cake-action@v2
        with:
          cake-version: 4.0.0
          inlineScript: |
            DotNetRun("build/Build.csproj", "--target=GitHub-Actions");

In my mind, it could just work like a pre- & post-processor to the regular script handling, something like

  1. generate temporary file name/path
  2. pass inline script contents into temporary file name/path
  3. pass temporary file name/path as script-path
  4. clean up the temporary path

GitVersion.CommandLine fails to run on Ubuntu

Hi,

It seems GitVersion.CommandLine is always failing when running under latest Ubuntu but not on Windows. See below.

Workflow error:

run-detectors: unable to find an interpreter for /home/runner/work/xxx/xxx/tools/GitVersion.CommandLine.5.1.2/tools/GitVersion.exe

An error occurred when executing task '__UpdateAssemblyVersionInformation'.

Error:
One or more errors occurred. (GitVersion: Process returned an error (exit code 2).)
GitVersion: Process returned an error (exit code 2).

##[error]The process 'tools/dotnet-cake' failed with exit code 1

Workflow snippet:

- name: Run the Cake script
        uses: cake-build/cake-action@v1
        with:
          script-path: build.cake
          target: Build
          verbosity: Verbose
          cake-version: ${{ matrix.cake }}
          cake-bootstrap: true

Cake script snippet:

#tool "nuget:?package=GitVersion.CommandLine&version=5.1.2"

GitVersion(new GitVersionSettings {
         UpdateAssemblyInfo = true,
         UpdateAssemblyInfoFilePath = "./src/Shared/SharedAssemblyInfo.cs",
         OutputType = GitVersionOutput.BuildServer
      });

Does the bootstrapper script takes the selected OS environment under consideration when running third-party Cake tools?

Fadil

Add support for implicit bootstrapping of modules

As of cake-build/cake#2849, modules are automatically bootstrapped before running the script. While it's still possible to do it explicitly with the --bootstrap option, it's no longer necessary. Instead, a new option has been introduced to opt out of the bootstrapping process called --skip-bootstrap.

The Cake action should reflect these changes both in the code and in the documentation.

Cake Action doesn't finish even though cake reports the tasks to be completed and the task time table is printed

We're currently having issues with this action w.r.t. termination after executing a task.
The logs suggest that cake finished execution (see log below) but the step only terminates after seemingly idling for a long time (last run was 45 minutes between the cake log that it finished and the termination of the action)

[execution log omitted]

Finished executing task: Run Unity Integration Tests
Completed in 00:05:15.8458010
Task                                      Duration            
--------------------------------------------------------------
Uninstall Previous Service and Testrunner   00:00:06.2233645    
Build and Install Current Service                  00:02:36.4687967    
Run Unity Integration Tests                          00:05:15.8458115    
--------------------------------------------------------------
Total:                                                             00:07:58.5379727    

We've also had a look at the process monitor to see if there are child-processes that the action might be waiting for but couldn't see any other than the process that is running this action.

z-browser-985362824834-6439944148064-3bbc7039013cd6053a215998e0dc2abf76a31dc2643d5637ef4b19abe3a30d32

This screenshot was taken between the cake task writing the log above and it finishing the execution of the step.


We also tried to run it manually on the build server via the cake command line tool and there it also works flawlessly so we assume it has something to do with this plugin / node...

If you have any more pointers to what we can try please let me know.
We also couldn't reproduce the delay locally on two different machines.

Allow enabling script module bootstrapping

To extend cake internals modules can be used, to fetch these from nuget boostrapping needs to be executed, this is currently done by executing Cake a extra time before executing script.

I've got this working in a feature branch and would be happy to PR this, it's currently builds upon #2 so either that needs to be merged or I'll need to refactor before sending it in.

Allow specifying cake version

As there might be breaking changes between Cake versions, so pinning a specific version is best practice, so an optional parameter to set Cake version would be desirable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.