Skip to content

Commit

Permalink
ci(dhall): build the github actions workflows with dhall πŸ— (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil authored Apr 26, 2021
1 parent 59a1400 commit e87705e
Show file tree
Hide file tree
Showing 236 changed files with 6,107 additions and 1,971 deletions.
27 changes: 27 additions & 0 deletions .bats/common.bats.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#

common::setup() {
load "${BATS_ROOT}/../bats-support/load.bash"

load "${BATS_ROOT}/../bats-assert/load.bash"
load "${BATS_ROOT}/../bats-file/load.bash"

# NODE(douglasduteil): manual bail mode
[ ! -f "${BATS_PARENT_TMPNAME}.skip" ] || skip "skip remaining tests"
}


common::teardown() {
# NODE(douglasduteil): manual bail mode
[ -n "$BATS_TEST_COMPLETED" ] || touch "${BATS_PARENT_TMPNAME}.skip"
}

#

setup() {
common::setup
}

teardown() {
common::teardown
}
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
42 changes: 42 additions & 0 deletions .github/dhall/jobs/ContainerTest.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
let GithubActions =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/github-actions/package.dhall sha256:327d499ebf1ec63e5c3b0b0d5285b78a07be4ad1a941556eb35f67547004545f

let SocailGouvSteps =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/socialgouv/steps.dhall sha256:4428b6517f7b8677a4b93205111c25ae9c2010428677c1b198d5d690216f28e5

let ContainerTest =
Ξ»(args_0 : { package : Text }) β†’
GithubActions.Job::{
, name = Some "Container Test"
, needs = Some [ "Build" ]
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, steps =
[ GithubActions.steps.actions/checkout
, SocailGouvSteps.container-structure-test.`v1.10.0`
( " "
++ " --config ${args_0.package}/tests/container-structure-test.yml -v debug"
++ " --image ghcr.io/socialgouv/docker/${args_0.package}@\${{ needs.Build.outputs.digest }}"
++ " --pull"
)
]
}

let __test__foo =
assert
: ContainerTest { package = "foo" }
≑ GithubActions.Job::{
, name = Some "Container Test"
, needs = Some [ "Build" ]
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, steps =
[ GithubActions.steps.actions/checkout
, SocailGouvSteps.container-structure-test.`v1.10.0`
( " "
++ " --config foo/tests/container-structure-test.yml -v debug"
++ " --image ghcr.io/socialgouv/docker/foo@\${{ needs.Build.outputs.digest }}"
++ " --pull"
)
]
}

in ContainerTest
40 changes: 40 additions & 0 deletions .github/dhall/jobs/DockerBuild.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
let GithubActions =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/github-actions/package.dhall sha256:327d499ebf1ec63e5c3b0b0d5285b78a07be4ad1a941556eb35f67547004545f

let SocailGouvSteps =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/socialgouv/steps.dhall sha256:4428b6517f7b8677a4b93205111c25ae9c2010428677c1b198d5d690216f28e5

in Ξ»(package : Text) β†’
GithubActions.Job::{
, name = Some "Build"
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, needs = Some [ "Lint" ]
, outputs = Some
(toMap { digest = "\${{ steps.docker_push.outputs.digest }}" })
, steps =
[ GithubActions.steps.actions/checkout
, SocailGouvSteps.docker-meta { image_name = package }
β«½ { id = Some "docker_meta" }
, SocailGouvSteps.docker-buildx β«½ { id = Some "docker_buildx" }
, SocailGouvSteps.docker-login
, GithubActions.steps.actions/cache
{ path = "/tmp/.buildx-cache"
, key = "${package}-buildx"
, hashFiles = [ "${package}/Dockerfile" ]
}
, SocailGouvSteps.docker-build-push
{ cache_path = "/tmp/.buildx-cache"
, context = package
, docker_buildx_step_id = "docker_buildx"
, docker_meta_step_id = "docker_meta"
}
β«½ { id = Some "docker_push" }
, GithubActions.Step::{
, name = Some "Image digest"
, run = Some
''
echo "''${{ steps.docker_push.outputs.digest }}"
''
}
]
}
35 changes: 35 additions & 0 deletions .github/dhall/jobs/Hadolint.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
let GithubActions =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/github-actions/package.dhall sha256:327d499ebf1ec63e5c3b0b0d5285b78a07be4ad1a941556eb35f67547004545f

let HadolintJob =
Ξ»(package : Text) β†’
GithubActions.Job::{
, name = Some "Lint"
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, container = Some "hadolint/hadolint:v1.22.1-alpine"
, steps =
[ GithubActions.steps.actions/checkout
, GithubActions.Step::{
, run = Some "hadolint ./Dockerfile"
, working-directory = Some package
}
]
}

let __test__foo =
assert
: HadolintJob "foo"
≑ GithubActions.Job::{
, name = Some "Lint"
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, container = Some "hadolint/hadolint:v1.22.1-alpine"
, steps =
[ GithubActions.steps.actions/checkout
, GithubActions.Step::{
, run = Some "hadolint ./Dockerfile"
, working-directory = Some "foo"
}
]
}

in HadolintJob
32 changes: 32 additions & 0 deletions .github/dhall/jobs/Inception.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
let GithubActions =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/github-actions/package.dhall sha256:327d499ebf1ec63e5c3b0b0d5285b78a07be4ad1a941556eb35f67547004545f

let InceptionJob =
Ξ»(args_0 : { package : Text }) β†’
Ξ»(args_1 : { name : Text, steps : List GithubActions.types.Step }) β†’
GithubActions.Job::{
, name = Some args_1.name
, needs = Some [ "Build" ]
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, container = Some
"docker://ghcr.io/socialgouv/docker/${args_0.package}:sha-\${{ github.sha }}"
, steps = args_1.steps
}

let __test__foo =
assert
: InceptionJob
{ package = "foo" }
{ name = "Test foo version"
, steps = [ GithubActions.Step::{ run = Some "foo --version" } ]
}
≑ GithubActions.Job::{
, name = Some "Test foo version"
, needs = Some [ "Build" ]
, runs-on = GithubActions.RunsOn.Type.ubuntu-latest
, container = Some
"docker://ghcr.io/socialgouv/docker/foo:sha-\${{ github.sha }}"
, steps = [ GithubActions.Step::{ run = Some "foo --version" } ]
}

in InceptionJob
69 changes: 69 additions & 0 deletions .github/dhall/steps/crazy-max/ghaction-docker-meta/Input.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{-
This dhall input is mapping a fixed version of the crazy-max/ghaction-docker-meta
https://github.com/crazy-max/ghaction-docker-meta/tree/v2.3.0
commit/2e1a5c7fa42123697f82d479b551a1bbdb1bef88
-}
let Input/Required = { images : Text }

let Input/Optional =
{ github-token : Optional Text
, flavor : Optional Text
, labels : Optional Text
, sep-labels : Optional Text
, sep-tags : Optional Text
, tags : Optional Text
}

let Input/default =
{ github-token = None Text
, flavor = None Text
, labels = None Text
, sep-labels = None Text
, sep-tags = None Text
, tags = None Text
}

let Input/Type = Input/Required β©“ Input/Optional

let Input = { Type = Input/Type, default = Input/default }

let __test__basic_input =
assert
: Input::{ images = "name/app" }
≑ { flavor = None Text
, github-token = None Text
, images = "name/app"
, labels = None Text
, sep-labels = None Text
, sep-tags = None Text
, tags = None Text
}

let __test__semver_input =
assert
: Input::{
, images = "name/app"
, tags = Some
''
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
''
}
≑ { flavor = None Text
, github-token = None Text
, images = "name/app"
, labels = None Text
, sep-labels = None Text
, sep-tags = None Text
, tags = Some
''
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
''
}

in Input
64 changes: 64 additions & 0 deletions .github/dhall/steps/crazy-max/ghaction-docker-meta/action.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
let GithubActions =
https://raw.githubusercontent.com/SocialGouv/.github/master/dhall/github-actions/package.dhall sha256:327d499ebf1ec63e5c3b0b0d5285b78a07be4ad1a941556eb35f67547004545f

let Input =
./Input.dhall sha256:0f0b7f02193300dd1fb74da365542d2244ad42b5c5b5cbb22968552dfb62fae8

let utils =
../../utils.dhall sha256:52b53ac4f7bfc0ac42b2147a16166eea9b4ed92ab303c1e6ba255c450747d3da

let step
: βˆ€(ref : Text) β†’ βˆ€(opts : Input.Type) β†’ GithubActions.Step.Type
= Ξ»(ref : Text) β†’
Ξ»(opts : Input.Type) β†’
GithubActions.Step::{
, uses = Some "crazy-max/ghaction-docker-meta@${ref}"
, `with` = Some
( utils.withInputs
(toMap opts.{ images })
( toMap
(opts β«½ { images = None Text, action_version = None Text })
)
)
}

let __test__minimal =
assert
: step "vX.Y.Z" Input::{ images = "ghcr.io/foo/bar" }
≑ GithubActions.Step::{
, uses = Some "crazy-max/[email protected]"
, `with` = Some (toMap { images = "ghcr.io/foo/bar" })
}

let __test__tags_options =
assert
: step
"vX.Y.Z"
Input::{ images = "ghcr.io/foo/bar", tags = Some "vX.Y.Z" }
≑ GithubActions.Step::{
, uses = Some "crazy-max/[email protected]"
, `with` = Some
[ { mapKey = "tags", mapValue = "vX.Y.Z" }
, { mapKey = "images", mapValue = "ghcr.io/foo/bar" }
]
}

let __test__step_id =
assert
: step "vX.Y.Z" Input::{ images = "ghcr.io/foo/bar" }
β«½ { id = Some "docker_meta" }
≑ GithubActions.Step::{
, id = Some "docker_meta"
, uses = Some "crazy-max/[email protected]"
, `with` = Some (toMap { images = "ghcr.io/foo/bar" })
}

let `v2.3.0` =
{-
This dhall is mapping a fixed version of the crazy-max/ghaction-docker-meta
https://github.com/crazy-max/ghaction-docker-meta/tree/v2.3.0
commit/2e1a5c7fa42123697f82d479b551a1bbdb1bef88
-}
"2e1a5c7fa42123697f82d479b551a1bbdb1bef88"

in { `v2.3.0` = step `v2.3.0`, step }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./action.dhall sha256:fc9c86ad5e974c57675938e91a566949c644aced362229a0bf16eaa3823b1b2f
∧ { Input =
./Input.dhall sha256:0f0b7f02193300dd1fb74da365542d2244ad42b5c5b5cbb22968552dfb62fae8
}
Loading

0 comments on commit e87705e

Please sign in to comment.