GitHub Actions, second round

After being capable of running build and test in my GitHub action workflow, it is time to experiment with matrix to have the build run on multiple OSes. This can be tricky if you use (like me) some Docker Images (Mongodb, SqlServer). This because when you choose Windows machine, you are using Windows Container services, not standard Docker for Windows. This means that you are not able to run standard Docker container based on linux, but you need to use Windows Container based image.

GitHub actions Windows based machines are running Windows Container, not Linux ones.

This is especially annoying for me because it seems that there is no SQL Server image available for Windows Server 2019.


Figure 1: Docker image for Sql Server does not support Windows Server 2019.

Ok, I’m forced to use Windows server 2016, when I really have preferred to use Windows 2019, that has a much better support for containers.

Apart these difficulties, GitHub actions saved my day because it allows me to specify new variables depending on matrix values, thus allowing me to use different container commands for different operating systems, as you can see in Figure 2.



Figure 2: Different mssSql and mongContainer variable values depending on operating system.

Thanks to the include directive, I’m able to give different value to job variables, I’m creating two new variables: msssql and mongoContainer, that contain the command line to start MsSql server and MongoDb containers. This is important because, in Windows, the image of MsSql container gaves me problem if I use ‘ instead of “. With include directive I’m able to specify a completely different run command line for different operating system.

This is also fundamental because I need to use two different container images for MsSql, in fact they are different for different operating systems. With linux I can use, while for Windows 2016 (but not for Windows 2019) I should use microsoft/mssql-server-windows-developer.

Thanks to include: condition, I can change value for jobs variable depending on Matrix combinations

The net result was that my action now runs in both operating systems.


Figure 3: Action now runs on both operating systems, I still got error from mongo test because of problem in container in Windows, but this is a different story.

If I want to run my build and test also against .NET Core 3 Rc, I can simply add another value on dotnet matrix, et voilà, now I got 4 different runs of my workflow.


Figure 3: Running actions with matrix, cross product between all variables allows me to run action in different combination of operating system and .NET  Core framework.

Thanks to the max-parallel: setting, I ask to the system to run only two build in parallel, but with fail-fast equal to false I’m asking to GitHub to always run all the combination, even if one previous combination fails. This allows me to always have all four actions run, regardless of the outcome of a previous action.

I can also use Exclude to remove some combination from matrix cross product, in Figure 4 I’m excluding running for .NET core 3 on windows machine


Figure 4: Excluding a specific combination from matrix combination

This will generate a total of three runs, I will build both version of framework in linux machine, but only 2.2.401 .net Framework on windows machine.

Include and exclude are powerful action configurations, that allows to configure differently the job or completely exclude some matrix combination, allowing for fine grained control on job parallelism.

Everything is really good, but here is some problems that I encountered while using Actions, but it is completely understandable because it is still in beta.

Running on Windows Machine is slower than Linux, I do not know if this is a problem of docker images, but in Figure 5 you can see timing of the action in Linux (red square) and in Windows (blue square). I suspect that Windows machine runs in a much slower hardware. Nevertheless, pay attention at timing, if you are building .NET core, probably linux is the best choice (better container support and faster in GitHub actions). 


Figure 5: Timing running the action in Linux and Windows machine

Another area where actions need improvement is the concept of a partially failing action, like we had for Years in Azure DevOps (TFS). The concept is: when I’m running a series of tests, I do not want the entire action job to stop if one of the test run fails, I want it to be reported failed, continue to the next step, and the entire action should be marked as “partially failing” if one of the job marked with continue-on-error failed. This kind of CI workflow is standard, do not stop the script, just continue and mark the single step as failed.

It is true that GitHub actions have a continue-on-error property, but it simply report the step as succeded even if it fails, this is a real annoying missing feature.


Figure 6: Continue-on-error actually mark the step as succeeded even if it fails.

As you can see from Figure 6, step failed (2 test failed), but the it is marked as successful (due to continue-on-error) and the overall execution is green. This is a real missing feature for complex project where you want to execute every steps and visualize which steps failed.

This second wave of test confirmed me that GitHub actions is a powerful build system, but it still need in its early day and need more work to be really usable in complex projects.

Gian Maria.

GitHub Actions Error pushing with workflow modified

After creating a workflow for GitHub Action, if you try to modify the workflow locally then push to GitHub you can incur in strange error.

refusing to allow an integration to create or update .github/workflows/ci.yml


Figure 1: Error in pushing to Git Repository

The reason seems to be a different permission in auth token used for authentication, then to solve the problem you need to clear credentials then try again the operation. In Windows you need to use Credential Manager as I described in that old post. Just delete every entry for GitHub, then try to push again, you will be asked again for credentials and then you should be able to push.


Figure 2: I got the error, then clear credentials in Credential Manager, finally I was able to push again.

Let me know if you still have the error.

Gian Maria.

First Experience with GitHub Actions

GitHub actions is the new CI/CD system created by GitHub that allows you to build and release your software with a simple workflow defined in YAML file. Actually it is in beta, but you can simply request to be enlisted and your account will be enabled so you can try it in preview.

Actions engine is based on a yaml definition that is stored directly in code, there are lots of predefined actions made by GitHub team as well as custom actions that can be developed by the community.The real power rely on the fact that you can use simply use command line and docker commands, making the creation of a release a simple and smooth process.

Adding a new workflow is really simple, just open the Actions tab of the repository, then ask to create a new worfklow:


Figure 1: Create new workflow for GitHub action directly from repository page.

This will simply create a new yml file in a directory called .github and you can immediately start editing the build. The syntax is really simple and it aims to simplicity rather than complexity. The vast majority of tasks can be simple accomplished inserting command line arguments.

My first impression is that the strongest point of GitHub actions is simplicity and easy to use.

Here is the first part of workflow definition:

name: NStore CI

on: [push]

    runs-on: ${{ matrix.os }}
        dotnet: [ '2.2.401', '3.0.100-preview9-014004'] 
        os: ['ubuntu-latest']
    name: Build for .NET ${{ matrix.dotnet }}

You can find complete workflow syntax at this page, but here is the explanation of my workflow. First of all on: [push] directive asks for continuous integration (run action for each push), then a list of jobs follows.

First and only job for this example is called build and it could run on different operating system. This is a nice feature of actions called matrix: you can define array of values and use those arrays in workflow definition to have it run multiple time, once for each parameter combination. Array of values are defined inside the strategy.matrix section, where I defined two distinct set of parameters, dotnet (version of dotnet core used to build) and os (type of machine where my action should be run). For this example I’m going to use only framework version as matrix value.

Runs-on step define OS, for this example I’m using ubuntu-latest. Finally I give a name to the job: Build for .NET following the actual version of matrix.dotnet value. When I push the code I can verify that two distinct jobs are scheduled.


Figure 2: Two distinct job where scheduled, one for each matrix version.

This is a really nice feature because we can specify a single workflow and have GitHub action engine run it with different configuration.

Thanks to Matrix configuration a single job can be run for many different combination of input parameters.

A job is simply composed by different steps, for my solution, I wants only to build my solution and run some tests agains Microsoft Sql Server and MongoDb

    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
        dotnet-version: ${{ matrix.dotnet }}
    - name: Build with dotnet
      run: dotnet build src/NStore.sln --configuration Release
    - name: Start Docker for MSSSql
      run: docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=sqlPw3$secure' -e 'MSSQL_PID=Developer' -p 1433:1433 --name msssql -d
    - name: Start Docker for Mongodb
      run: docker run -d -p 27017:27017 mongo
    - name: Dump mssql docker logs
      run: docker logs msssql
    - name: Run Tests - Core
      run: dotnet test src/NStore.Core.Tests/NStore.Core.Tests.csproj --configuration Release --no-build

    - name: Run Tests - Domain
      run: dotnet test src/NStore.Domain.Tests/NStore.Domain.Tests.csproj --configuration Release --no-build
    - name: Run Tests - MongoDb
        NSTORE_MONGODB: mongodb://localhost/nstore
      run: dotnet test src/NStore.Persistence.Mongo.Tests/NStore.Persistence.Mongo.Tests.csproj --configuration Release --no-build
    - name: Run Tests - MsSql
        NSTORE_MSSQL: Server=localhost;user id=sa;password=sqlPw3$secure
      run: dotnet test src/NStore.Persistence.MsSql.Tests/NStore.Persistence.MsSql.Tests.csproj --configuration Release --no-build
    - name: Dump mssql docker logs after tests
      run: docker logs msssql
    - name: Run Tests - Sql Lite
      run: dotnet test src/NStore.Persistence.Sqlite.Tests/NStore.Persistence.Sqlite.Tests.csproj --configuration Release --no-build 

Workflows starts with actions/checkout@v1 a really standard action that simply clone and checkout the code, it is followed by another action that ensure that a specific version of .NET core SDK is installed and configured in the system. It is declared with the syntax uses: actions/setup-dotnet@v1 and allows me to use a specific version of .NET core; this action supports parameters, and is followed by a with: section used to pass parameters. This is another strong point of GitHub actions, it is really simple to declare and use actions, there is no need to install or reference anything, just reference the action in the right repository and the game is done.

The rest of the repository is a series of steps composed only by a name and a command line instruction. This allows me to simply issue dotnet command to restore, build, test my solution.

Another cool aspect of Actions is that Docker is available inside the machine, this allows me to run a couple of containers: SQL Server and MongoDb, to run my tests during a build. This is super cool, because it allows me to use Docker to create all prerequisites that I need for my build.

Having Docker inside the machine that runs actions is a real blessing because it allows to run integration tests.

My first impression is quite positive, with just a bunch of Yaml code I was able to create a workflow to build and run tests for my project (I spent a quite good amount of time to have MsSql container work, but this is another story).

Another good aspect of Actions is the ability to see real-time log of your run directly from a browser, without the need of installing anything.

A final real nice aspect of Actions is that they are defined by conventions inside a special folder .github/workflows; I’ve developed this build in a fork of the original project, then I issued a pull request and when the pull request was accepted, this new workflows appears in the original repository.


Figure 3: After pull request was merged, immediately the workflow is up and running on target repository..

Clearly this is still a beta and there are still part that should be improved. First of all, if a test run fails, the build is marked as failed and you need to look at test logs to understand which tests failed.


Figure 3: Build failed, but to understand why it failed you need to check the logs.

This is the reason why I included a distinct test step for each test assembly, instead of a simple dotnet run on the entire solution. Using this little trick I can at least understand which test run failed.


Figure 4: Action run result, each failed step is marked with a red cross

Clicking on failed step, you can find the output log of the step, needed to understand which tests failed and why. For those of you used to Azure DevOps pipeline, you will surely miss the nice Test Result page, but I’m expecting GitHub actions to close the gap in this area.


Figure 5: Action step run detail.

Another problem I found (but I need to investigate more) is that docker seems not to be available on MacOS Machine. If I run previous build on MacOS I got a docker command not found.

You only need to enlist in beta and start playing with Actions, you will surely find a good use for them.

Gian Maria.