Giter Club home page Giter Club logo

github-actions-dhall's Introduction

github-actions-dhall

Typecheck, template and modularize your Github Action definitions with Dhall.

Usage

Import the github actions definitions as a Dhall package using:

let GithubActions =
      https://regadas.dev/github-actions-dhall/package.dhall

Workflow definition can be done by using the schema pattern and setting the appropriate values.

Examples

curl https://regadas.dev/github-actions-dhall/examples/hello-world.dhall | dhall-to-yaml
curl https://regadas.dev/github-actions-dhall/examples/scala.dhall | dhall-to-yaml
curl https://regadas.dev/github-actions-dhall/examples/release-scala.dhall | dhall-to-yaml

github-actions-dhall's People

Contributors

aglover-zendesk avatar alvintang avatar cattruscott avatar douglasduteil avatar funbringer avatar ggilmore avatar gregziegan avatar gvolpe avatar ivankovnatsky avatar jackkelly-bellroy avatar joedevivo avatar lrworth avatar michael-wisely-gravwell avatar regadas avatar seancribbs avatar timbertson avatar tristancacqueray avatar vvv avatar zeeshanlakhani 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

github-actions-dhall's Issues

Add types for Release Action (can PR)

Thanks for this library. Would you accepted a PR for adding support for the "release" event?

Example from the GitHub Actions docs:

on:
  release:
    types: [published]

If so, would you prefer:

{ types : (List Text) }

or would you prefer a union type?

Rename `actions/foo` to `actions.foo`?

There are an increasing number of record keys of the form actions/foo. This gives a quasi-namespacing effect but maybe we want to push them into a separate record, since AFAIK we can't assemble record keys from Text or anything.

Should we have actions = { setup-haskell = ..., setup-java = ... } etc instead?

License of repo?

I have been evaluating using dhall to generate github actions. Under what license is the code under?
As there is no license stated, I'm guessing regular copyright would be in effect, and as such any usage of the code needs to be granted in some way.

Reusable workflows support

Hi @regadas! Thanks for all your work on this. I have an issue and would like your thoughts on it.

I currently have an open PR to support reusable workflows but it only adds the types needed. To call a reusable workflow, it has to be done on the job level so a uses key will be used instead of steps. My initial thought is to make jobs.steps and jobs.runs-on Optional but this will break existing workflows (including ours) since they have to be changed to Optional values. What's your take on this?

My current work around is to merge the records e.g.

GithubActions.Workflow::{
...
, jobs = [] : List { mapKey : Text, mapValue : GithubActions.Job.Type }
}
//  { jobs = toMap { job1.uses = "my-reusable-workflow@master" } }

Allow for github expressions

Hi! Quite new to Dhall so sorry if this is a dumb question. I'm in the process of converting our entire GH CICD to Dhalll.

Github workflow files extend the standard YAML syntax, in that they allow you to add expressions which can be used to programmatically set variables and inputs for jobs. For example, in our use-case we generate a list of services that need to be re-deployed (call this job A), which is then used as the deployment field in the strategy.matrix key of a later job (call this job B). The strategy in GH workflow syntax looks like:

jobs:
  jobA:
    outputs:
      deployment-matrix: ...
  jobB:
    strategy:
      matrix:
        deployment: ${{ fromJson(needs.jobA.outputs.deployment-matrix) }}

However with the current definition of Strategy a value in a matrix needs to be of type List Text, which makes the above impossible.

This isn't specific to strategy.matrix: from what I gather, almost any value in a workflow file can be replaced with a github expression. This is fine when the value is of type Text or Optional Text, but for any other type (like List Text above) it's impossible to use an expression.

Generic solution idea: we could wrap problematic types in a new polymorphic type, e.g.

-- OrGHExpression.dhall
λ(a : Type)  < GHExpression : Text | Value : a >

-- Strategy.dhall
let OrGHExpression = ./OrGHExpression.dhall

in  { matrix : List { mapKey : Text, mapValue : OrGHExpression (List Text) }
    , fail-fast : Optional Bool
    , max-parallel : Optional Natural 
    }

-- Example.dhall
Some GithubActions.Strategy::{
, matrix = 
  { deployment = ListTextOrGH.GHExpression "\${{ fromJson(needs.jobA.outputs.deployment-matrix) }}"
  , something-else = ListTextOrGH.Value [ "ubuntu-latest" ] 
  } 
} 

continue-on-error type should be `Optional <Bool | Text>`?

There are instances where you'd like the continue-on-error field in a job to reference a matrix variable for example that can itself be true or false. However, with the current type being Optional Bool, there's no way to take-in a \${{matrix.blah}} Text/String.

I thought about adding a PR, but wanted to throw up an issue first and get your thoughts.

steps.cache should accept multiple patterns

The hashFiles function in the Github Actions expression language can support multiple patterns: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#hashfiles

It would be nice for the cache step in this repo to support that also, by taking a List Text instead of a single Text. I started to prepare a PR for this but got lost in apparent duplication: what is the design intent between steps/cache.dhall and steps/actions/cache.dhall? dhall hash says that they're identical. Is one deprecated?

actions/cache produces failure given empty hashFiles

GithubActions.steps.actions/cache
  { path = "my-path", key = "my-key", hashFiles = [] : List Text }

produces this job:

      - name: my-path cache
        uses: "actions/cache@v2"
        with:
          key: "${{ runner.os }}-my-key-${{ hashFiles() }}"
          path: my-path
          restore-keys: |
            ${{ runner.os }}-my-key-

but GitHub Actions fails with Too few parameters supplied: '(' due to hashFiles().

Type RunsOn too strict

First of all: Awesome work, many thanks!

I think the type of RunsOn is too strict as it only permits one of the github provided runners.

There is the possibility to define a matrix for the runners, e.g. like that https://github.com/sengaya/aws-micro-cli/blob/master/.github/workflows/main.yml#L18-L21 so i would need to put something like ${{ matrix.os }} for runs-on.

Also there is the possibility for custom runners. I have no experience with this but I guess that's also not possible with the current type restriction.

Scala example doesn't seem to work

Hi,

I gave this a try and after running the following command:

$ curl https://raw.githubusercontent.com/regadas/github-actions-dhall/master/examples/scala.dhall | dhall-to-yaml

I got the following error:

Error: Invalid input

(stdin):27:28:
   |
27 | in  GithubActions.Workflow::{
   |                            ^^^
unexpected ":{<newline>    ,"
expecting expression or whitespace

Here's my shell.nix specifying my dependencies:

let
  pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs-channels/archive/nixos-20.03.tar.gz") {};
  stdenv = pkgs.stdenv;

in stdenv.mkDerivation rec {
  name = "neutron";
  buildInputs = [
    pkgs.dhall-json # v1.6.2
    pkgs.openjdk # v1.8.0_222
    pkgs.sbt  # v1.3.8
  ];
}

Is this behavior expected using dhall-json-v1.6.2?

Strategy matrix doesn't support excluding some combinations

Currently, Strategy::matrix is defined as a List { mapKey : Text, mapValue : List Text }:

https://github.com/regadas/github-actions-dhall/blob/master/types/Strategy.dhall

However, Github Actions supports having an exclude key that is a list of records (not Text):

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-excluding-configurations-from-a-matrix

Currently it's not possible to specify an exclude field in the matrix, because it doesn't match the type.

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.