Giter Site home page Giter Site logo

typesafegithub / github-workflows-kt Goto Github PK

View Code? Open in Web Editor NEW
482.0 5.0 23.0 15.63 MB

Authoring GitHub Actions workflows in Kotlin. You won't go back to YAML!

Home Page: https://typesafegithub.github.io/github-workflows-kt/

License: Apache License 2.0

Kotlin 100.00%
kotlin github-actions dsl library github type-safe kotlin-script workflows

github-workflows-kt's People

Contributors

asemy avatar benkeil avatar dependabot[bot] avatar ema987 avatar github-actions[bot] avatar goooler avatar gradle-update-robot avatar jan-ove avatar jmfayard avatar krzema12 avatar kugo12 avatar leocolman avatar lotharschulz avatar louiscad avatar madhead avatar mfwgenerics avatar msfjarvis avatar nikkyai avatar polarene avatar renovate[bot] avatar vampire 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  avatar

github-workflows-kt's Issues

Add docs

  • how to use
  • how to contribute, especially add new actions
  • deploy automatically on tags publishing? together with the lib

[Core feature request] Custom runner type from string

What feature do you need?
Runners are already supported by the library: https://github.com/krzema12/github-actions-kotlin-dsl/blob/6e7119ed9b55a9fd096b32046fcfa26fd93ad103/library/src/main/kotlin/it/krzeminski/githubactions/domain/RunnerType.kt#L7-L25

but it's not possible to define a custom one in runtime. Use cases:

  • the library lags with adding a new type
  • runner is passed from e.g. strategy matrix as a string, then it's not possible to use it

Proposed implementation
Instead of enum, make it a sealed class, with additional

class Custom(val value) : RunnerType

[Core feature request] `env` on workflow, job and step level

What feature do you need?
Please add a link to GitHub docs (https://docs.github.com/en/actions/using-workflows/) which describes the desired feature.
https://docs.github.com/en/actions/learn-github-actions/environment-variables

Do you have an example usage?
Best if a YAML snippet is pasted here, or if your project is open-source, an URL to your workflow.

some tasks need to call scripts / binaries that expect some env variables

- name: Send Webhook Notification
  if: always()
  env:
    JOB_STATUS: ${{ job.status }}
    WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
    HOOK_OS_NAME: ${{ runner.os }}
    WORKFLOW_NAME: ${{ github.workflow }}
  run: |
    git clone https://github.com/DiscordHooks/github-actions-discord-webhook.git webhook
    bash webhook/send.sh $JOB_STATUS $WEBHOOK_URL
  shell: bash

[Core feature request] Allow accessing step outputs

What feature do you need?
Please add a link to GitHub docs (https://docs.github.com/en/actions/using-workflows/) which describes the desired feature.
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsid

Do you have an example usage?
Best if a YAML snippet is pasted here, or if your project is open-source, an URL to your workflow.

- name: Build and push
  id: docker_build
  uses: docker/build-push-action@v2
  with:
    context: ./
    file: ./Dockerfile
    push: true
    tags: ${{ secrets.DOCKER_HUB_USERNAME }}/discordbot:latest
- name: Image digest
  run: echo ${{ steps.docker_build.outputs.digest }}

even better would be if we could use it somewhat like so:

fun variable(variable: String): String = "\${{ $variable }}"

val dockerBuild = uses(
    name = "Build and push",
    id = "docker_build_push",
    action = DockerBuildPush(
        context = ".",
        file = "./Dockerfile",
        push = true,
        tags = "${variable("secrets.DOCKER_HUB_USERNAME")}/discordbot:latest",
    )
)
run(
    name = "image digest",
    command ="echo ${dockerBuild.outputsVariable("digest")}",
//      command = "echo ${variable("steps.${dockerBuild.id}.outputs.digest")}",
)

but just having access to the id field would let me build the command echo ${{ steps.docker_build.outputs.digest }} myself too

Check consistency of generated YAML against source Kotlin script

Imagine we have two files: workflow.main.kts which uses this library, and workflow.yaml. We'd like to ensure both are in sync.

Proposed approach: in the generated YAML add an extra step that would self-check if the generated YAML was generated from the main.kts file. It can be done by calculating a checksum from the main.kts file, using it in the extra initial step and comparing it with current checksum (compare "expected" with "actual").

Thanks to this, if someone edits just one of these files, the workflow will fail fast.

Add missing parameters to all wrappers

When adding the wrappers, I often implemented only these parameters that I need. It was a mistake, I was too lazy. Let's make the wrappers versatile so that others can use them for their specific cases.

Add a "custom action" builder

If there's no wrapping API yet for a given action, it should not block the user from giving its name and version, along with the arguments, until it gets proper wrapper in the library.

[Bug] Incorrect YAML when value starts with `*`, `[` or `!`

Action

            uses(
                name = "Publish JUnit report",
                action = object : Action("mikepenz", "action-junit-report", "v2") {
                    override fun toYamlArguments() = linkedMapOf(
                        "report_paths" to "**/build/reports/tests/**",
                    )
                },
                condition = "always()",
            )

Expected

Working action.

Actual

I got an error from GitHub Actions:

Invalid workflow file : .github/workflows/build.yaml#L40
You have an error in your yaml syntax on line 40

It resulted in such YAML:

- name: Publish JUnit report
  uses: mikepenz/action-junit-report@v2
  with:
    report_paths: **/build/reports/tests/**

Workaround

Add single quotes in the value:

"report_paths" to "'**/build/reports/tests/**'",

Library version

v0.6.0

Compile and run examples from the docs

It's to ensure it works, especially when there are frequent breaking changes.
Just extract the Kotlin part from the README, put it into a main.kts file, run it and compare actual output with expected one. Make it a separate workflow.

[Core feature request] condition on job

What feature do you need?
Please add a link to GitHub docs (https://docs.github.com/en/actions/using-workflows/) which describes the desired feature.
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif

Do you have an example usage?
Best if a YAML snippet is pasted here, or if your project is open-source, an URL to your workflow.

jobs:
  build:
   .....
  notify:
    name: Discord Notification
    runs-on: ubuntu-latest
    needs: # make sure the notification is sent AFTER the jobs you want included have completed
      - build
    if: ${{ always() }} # You always want to be notified: success, failure, or cancelled
    steps:
    - name: Notify
      uses: nobrayner/discord-webhook@v1
      with:
        github-token: ${{ github.token }}
        discord-webhook: ${{ secrets.WEBHOOK_URL }}
        include-details: true

Provide first-party API to output files directly

Rather than encouraging users to pipe files it'd be easier to to have something like a Workflow.writeToFile(inputPath: Path, outputPath: Path) API. This also allows users like me with a lot of workflows to be able to generate all of the outputs in one go without having to resort to too much shell scripting. Having at least the output path be a property in the workflow would also help simplify this. Ultimately I envision being able to do something like this in a CI workflow to automatically update YAML files without requiring a consistency check job in each individual workflow

#!/usr/bin/env kscript
 
@file:DependsOn("it.krzeminski:github-actions-kotlin-dsl:0.2.0")

//INCLUDE workflow1.kt
//INCLUDE workflow2.kt
//INCLUDE workflow3.kt
//INCLUDE workflow4.kt

arrayOf(workflow1, workflow2, workflow3, workflow4).forEach { workflow ->
  workflow.writeToFile() // implicitly uses an output parameter provided in the workflow itself
}

Make generated YAML more readable and better formatted

Currently the output YAML has some weird empty lines, puts certain keys in weird order, and so on. This is because the library uses kaml library which has its quirks and doesn't give full control over e.g. order of emitted YAML keys.

A proposed solution is to generate the YAML manually. It would also make development easier because on the code level, kaml imposes some limitations as well (e.g. sealed hierarchy has to be used for actions which makes it impossible to divide them into packages).

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.