Skip to content

chore: generate CI config & use context dir - #8241

Merged
shykes merged 3 commits into
dagger:mainfrom
shykes:generate-ci
Sep 5, 2024
Merged

shykes merged 3 commits into
dagger:mainfrom
shykes:generate-ci

Conversation

@shykes

@shykes shykes commented Aug 27, 2024 •

Copy link
Copy Markdown
Contributor

This is a small first step towards eventually generating 100% of our Github Actions config.

  • Docs
  • SDK checks: test, lint, test-publish (on stable and dev engine)

@shykes
shykes force-pushed the generate-ci branch 4 times, most recently from 1255e1f to 9efc3b0 Compare August 27, 2024 19:50
@shykes shykes changed the title chore: generate CI workflow: Docs chore: generate CI workflow Aug 27, 2024
@shykes shykes changed the title chore: generate CI workflow chore: generate CI workflows Aug 27, 2024
@shykes
shykes force-pushed the generate-ci branch 9 times, most recently from 0baecf2 to 7f8aa15 Compare August 29, 2024 00:43

@jedevc jedevc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only major complaint with this PR is that I didn't get to do it 😆 Seriously, it's such a neat approach, I'm a fan 🪭

This isn't a real review, just was reading through and left some thoughts about some future features/fixes - none of them are really blockers. The only more major point is the one around the fact that I think this increases our CI cost by spinning up more workers (but I left a suggestion as to what we might do about that).

I think we should try and get this in... relatively soon? Maybe sometime next week works? I think starting with just the docs and sdk steps is good, since those are "simpler", but also, means that if we turn out to not like the approach (very doubtful in my mind), we can more easily backtrack.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it possible to group multiple dagger commands into a single file? e.g. I think it would be really nice to have all the elixir checks in one single pipeline, but potentially all different jobs, or maybe even steps in a single job?

Not 100% sure, I don't think we need to be optimizing to have a pretty view in github. But mainly, I think it would help avoid spinning up too many new CI workers (which can be pricey).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible but requires some extra implementation work, to "collapse" pipelines that can be collapsed. Either automatically or with a "hint" from the caller. I would love a PR on the gha module with that feature :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedevc thinking about this more:

I think it would be really nice to have all the elixir checks in one single pipeline, but potentially all different jobs

This is possible (with some implementation work) BUT it will NOT change the number of machines started, because each job gets its own machine, regardless of workflow grouping.

or maybe even steps in a single job?

There is no benefit to this. It should be done at the Dagger level.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possible (with some implementation work) BUT it will NOT change the number of machines started, because each job gets its own machine, regardless of workflow grouping.

Yeah, fair enough - I guess it's more just for sorting at the github level. I don't currently have the time to PR this in (reviews + flakes + prep for v0.13 are most of my attention this week) - but can try and find a moment after that's landed if no one else can pick it up.

There is no benefit to this. It should be done at the Dagger level.

Fair. I think I agree - this does mean that if we want lots of tasks done, you need to use your language primitives for it. This is good.

But, I think if we're doing this more, the performance of the traces view in dagger cloud might need some help - when you have a lot of spans together, the performance can really suffer, and the page takes way more time to load than the basic github actions logs view. But hopefully we can feel the pain of this and do something here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, I think if we're doing this more, the performance of the traces view in dagger cloud might need some help - when you have a lot of spans together, the performance can really suffer, and the page takes way more time to load than the basic github actions logs view. But hopefully we can feel the pain of this and do something here.

I believe @vito has been focusing specifically on Traces UI performance :)

Comment thread .github/main.go Resolved
Comment thread .github/main.go
func (gh *Github) withSimplePipeline(name, command string, opts ...dagger.GhaWithPipelineOpts) *Github {
opts = append(opts, dagger.GhaWithPipelineOpts{
OnPushBranches: []string{"main"},
OnPullRequestOpened: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential interface idea - instead of needing to have a bunch of booleans here, we could maybe have a custom enum of event types in the gha module? Then we just pass a list of Events []GhaEvent in (which also lets you more easily programmatically control these).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a great idea. My only concern is: what do we do about the onXYZ arguments that are not boolean? Like onPullRequestBranch etc. How do we avoid making the split feel weird to callers?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what I can tell - the event block here is made up of two things - the thing that can happen to the branch, and the branch target.

So actually it's a bit trickier than an enum - it's almost like we want an event to be:

type GithubEvent struct {
	PullRequest *GithubPullRequestEvent
	Issue *IssueEvent
	... // more events
}

type GithubPullRequestEvent struct {
	Branches []string
	Triggers []GithubPullRequestTrigger
}

type GithubPullRequestTrigger string
const (
	GithubPullRequestOpened = "opened"
	// ...
)

Then, you just pass in a list of GithubEvent to your WithPipeline - maybe constructing them something like:

event := dag.OnPullRequest().WithBranch("main").OnOpen().OnClose()

How does something like that sound? Feels very literate-style, but then each event is it's own dagger object to manipulate (which would be really cool, now you could build little functions to encapsulate the logic for your project).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedevc this is what I initially want to do, it most closely models the reality of the underlying data structure. But, it wouldn't be usable from the CLI. I am setting a constraint for myself to make the API great in both code and the CLI.

@jedevc jedevc Sep 4, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tangent: is this then an argument to make the CLI more powerful, so it can handle construction of more complex objects, i.e. ones that take other objects as parameters?

If we want all modules to be easily usable from code and the CLI, then I think the CLI just needs to be more powerful to be able to handle this - otherwise, we end up in this scenario of making an API worse-for-code, so it works-at-all for the CLI.

cc @helderco

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tangent: is this then an argument to make the CLI more powerful, so it can handle construction of more complex objects, i.e. ones that take other objects as parameters?

Yes :)

Comment thread .github/main.go
Comment on lines +164 to +175
// Generate Github Actions pipelines to call our Dagger pipelines
func (gh *Github) Generate() *dagger.Directory {
return gh.CI.Config().Directory(".github")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little ask - could we also use the dirdiff module to implement a lint action here as well (and maybe have a pre-defined workflow to make sure this in sync?).

I wish there was a way to avoid needing to have these generated files in the repo at all, I might have some fun ideas for that (hackathon project?), but they involve way too much hackery at the github actions level for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually implemented this already 😁 kudos to @kpenfound for helping figure it out. Unfortunately it's not that great, the best gha can do is generate the files and commit/push them for you. Unlike other CIs it doesn't support continuation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh, yeah that's a neat approach. That's annoying it's not great, I think we can just stick with manual invocation for now 😢 (definitely not worth blocking on)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this gap is a possible insertion point for bridging to pocketCI :) But I don't know exactly how. cc @kpenfound @matipan

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedevc I added a Check() function that uses dirdiff. But I wasn't sure where to integrate it in the main module, so I didn't wire it in. I could use your guidance on that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'd add a new github workflow for right now for this - something like github lint? I suppose wiring it into the main module makes sense, but we could also just have a single workflow that directly calls the github module, I'm not hugely biased towards either.

Comment thread .github/workflows/docs.yml Resolved
@shykes
shykes force-pushed the generate-ci branch 3 times, most recently from 7a139f6 to 83133d7 Compare August 30, 2024 00:06

@gerhard gerhard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using Dagger to generate GitHub Actions YAML. I am not excited about removing 180 lines of YAML, and adding 11k lines of generated YAML.

Some of the new scripting is significantly more complex than what we had before. While action.yml would not win any scripting competitions, it was simpler.

The only real blocker that I see to merging this is losing the timeout setting. Restricting GITHUB_TOKEN permissions would be nice to keep, but less of a blocker.

Overall, I am curious to see how well this works in practice. Specifically:

  • When a job fails, is it easier to understand which step failed & why?
  • How well does the workflow dispatch work after the test & lint split?
  • What impact does this split have on scheduling jobs? We will need 2x as many runners.
  • What's it like to live with 2 modules, .dagger and .github ?
image

One thing which I know will hurt is when we hit GitHub's 100 checks limit. After this change, we are at 91. GitHub's UI makes it impossible to make sense of more than 100 checks. I don't think the number goes higher than 100 (this limitation goes back to 2021), and the small scrolling area makes it very difficult to find anything. Also, the Checks tab is getting more difficult to use:

image

I am going to approve this optimistically so that we can merge this (after resolving the conflicts) and try living with this change for a few weeks. YOLO!

Comment thread .github/main.go Resolved
Comment thread .github/main.go Resolved
Comment thread .github/workflows/docs.yml Resolved
Comment thread .github/main.go Resolved
@shykes
shykes force-pushed the generate-ci branch 2 times, most recently from 579f90a to 46bd74b Compare August 30, 2024 20:16
@shykes

shykes commented Aug 30, 2024

Copy link
Copy Markdown
Contributor Author

Thanks Gerhard! A few notes below.

I like the idea of using Dagger to generate GitHub Actions YAML. I am not excited about removing 180 lines of YAML, and adding 11k lines of generated YAML.

A more fair comparison is that I replaced 180 lines of YAML with 196 lines of Go, which can collapse to a 13 line overview:

ci.Gha = dag.Gha(dagger.GhaOpts{
		DaggerVersion: daggerVersion,
		PublicToken:   "dag_dagger_sBIv6DsjNerWvTqt2bSFeigBUqWxp9bhh3ONSSgeFnw",
		Runner:        ci.BronzeRunner(false),
	})
	return ci.
		WithPipeline("Docs", "docs lint", "", false).
		WithSdkPipelines("python").
		WithSdkPipelines("typescript").
		WithSdkPipelines("go").
		WithSdkPipelines("java").
		WithSdkPipelines("elixir").
		WithSdkPipelines("rust").
		WithSdkPipelines("php")

I expect the ratio will only get better as switch more pipelines to be generated.

This would be nicer if Github Actions supported continuations - then the generation step could be hidden better. We'll start with proper .gitattributes. But certainly, to appreciate this change, you need to adopt a mindset where the generated YAML is not source code: it's like a compiled binary.

Some of the new scripting is significantly more complex than what we had before. While action.yml would not win any scripting competitions, it was simpler.

It was not actually simpler. The perceived increase in complexity comes from several things:

  1. Additional features. In particular the markdown report requires a larger shell script. The action.yaml doesn't have that feature, so it looks simpler.
  2. Inlining. Most of the generated shell script is actually identical to the manually edited one, or only slightly tweaked. But it's all shown in one place, instead of spread out across an action YAML, a workflow YAML, and in some cases one or more intermediary workflow YAML.
  3. Simpler YAML. I transferred some of the complexity from proprietary YAML to Bash. This makes the bash script look slightly more complicated (not that much really). But in return we get less context switching between YAML and bash, and more local debugability. For example you can debug the markdown generation feature with COMMAND='echo hello world' ./scripts/exec.sh; less github-summary.md. Same for all the other steps.

Some of the above ☝️ are not specific to generating the YAML. For example, I could generate a workflow that references a shared static action.yaml, or intermediary workflow. I just chose not to, because I like this tradeoff. Operationally one single self-contained YAML, with everything inlined and no fancy runtime abstractions, is ultimately more reliable. But, even if that turns out to be wrong, we can keep the generator model and just change the layout that we generate to. We could even support several layouts, and make it configurable.

The only real blocker that I see to merging this is losing the timeout setting. Restricting GITHUB_TOKEN permissions would be nice to keep, but less of a blocker.

Thanks for catching that. I'm on it.

Overall, I am curious to see how well this works in practice. Specifically:

  • When a job fails, is it easier to understand which step failed & why?

So far it seems the be either the same or better, depending on the situation.

  • The SDK split is nice
  • More standardized layout across workflows is a subtle advantage. I know what to expect across all checks, it's the same structure, so less cognitive load when debugging
  • The markdown summary is very useful, I often never go to the logs at all, I go straight to the summary (sadly github UI makes that 2 clicks from the PR)
  • How well does the workflow dispatch work after the test & lint split?

Not sure what you mean by that.

  • What impact does this split have on scheduling jobs? We will need 2x as many runners.

I don't think so. My understanding is that machines are allocated at the job level, not the workflow level. This is one reason I went for one pipeline per workflow file. It didn't seem to impact the runtime behavior that much.

  • What's it like to live with 2 modules, .dagger and .github ?

I am not attached to 2 modules particularly, but it seems most aligned with the current consensus on how to tackle code generation pipelines with Dagger. That is totally something we can change.

One thing which I know will hurt is when we hit GitHub's 100 checks limit. After this change, we are at 91. GitHub's UI makes it impossible to make sense of more than 100 checks. I don't think the number goes higher than 100 (this limitation goes back to 2021), and the small scrolling area makes it very difficult to find anything. Also, the Checks tab is getting more difficult to use:

I actually think we can bring the number of checks down easily. I didn't mind the increased number of checks (if anything I started to look at the Dagger Cloud checks less, because I get the same granularity from GHA checks now). But I can prioritize bringing the number the checks down.

The easiest way to do this, is to collapse pipelines in Dagger. Lint, test and test-publish for each SDK can be collapsed into a single dagger call. Splitting that across 3 VMs per SDK is overkill anyway.

Separately, we should talk about what this model means for Dagger Cloud checks. Do we still need that granularity in a world where generated CI config is the norm, giving you the granularity for free? Maybe we can switch to a single Dagger Cloud check that links to the entire trace group? cc @vito @aluzzardi @kpenfound @crjm

I am going to approve this optimistically so that we can merge this (after resolving the conflicts) and try living with this change for a few weeks. YOLO!

Thank you, I appreciate the detailed review!

@shykes
shykes force-pushed the generate-ci branch 2 times, most recently from 2a1a8d0 to cd8ff2d Compare August 30, 2024 23:57
@wingyplus

Copy link
Copy Markdown
Contributor

@jedevc From what I can tell. The test failed on mounted cache test. And from this failure, it looks like cache volume is stored from the previous run somehow cause it gets double result. I open a PR to fix this at #8317 by using LOCKED mode but I'm also not sure if it's the right fix.

@shykes

shykes commented Sep 3, 2024

Copy link
Copy Markdown
Contributor Author

@jedevc From what I can tell. The test failed on mounted cache test. And from this failure, it looks like cache volume is stored from the previous run somehow cause it gets double result. I open a PR to fix this at #8317 by using LOCKED mode but I'm also not sure if it's the right fix.

Is it possible that my PR caused the issue? Maybe a subtle change in the YAML config?

@shykes
shykes force-pushed the generate-ci branch 4 times, most recently from 910e1c2 to 869f9b7 Compare September 4, 2024 07:04
Comment thread dagger.json Resolved
Comment thread .dagger/main.go Resolved
@shykes
shykes force-pushed the generate-ci branch 2 times, most recently from 41f3684 to af2b5e0 Compare September 4, 2024 22:07
@shykes

shykes commented Sep 4, 2024

Copy link
Copy Markdown
Contributor Author

@gerhard in an effort to make you happy, we are now down to 3k lines of YAML instead of 11k :)

@shykes

shykes commented Sep 4, 2024

Copy link
Copy Markdown
Contributor Author

Force-pushing a small change to re-run all failed workflows...

@shykes
shykes requested a review from a team as a code owner September 5, 2024 06:28
@shykes shykes changed the title chore: generate CI workflows chore: generate CI config & use context dir Sep 5, 2024
@shykes

shykes commented Sep 5, 2024

Copy link
Copy Markdown
Contributor Author

FYI I am combining #8284 into this, it's too much work to maintain both in parallel.

@shykes
shykes force-pushed the generate-ci branch 3 times, most recently from 10c8596 to bb1f236 Compare September 5, 2024 07:22
Comment thread .github/workflows/elixir-dev.gen.yml Resolved
This uses the new "context directory" feature in Dagger 0.12.6

Signed-off-by: Solomon Hykes <[email protected]>
This is a small first step towards eventually generating 100% of our Github Actions config.

- Docs lint
- SDK lint and test (on stable and dev engine)

Signed-off-by: Solomon Hykes <[email protected]>
@shykes
shykes merged commit 728f6b7 into dagger:main Sep 5, 2024
gerhard added a commit that referenced this pull request Sep 12, 2024
We added a bunch of new workflows that we have not been tracing. This
fixes it. Follow-up to:
- #8407
- #8241

Signed-off-by: Gerhard Lazu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants