Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct way to create a fix that always runs? #153

Open
rubberduck203 opened this issue Oct 15, 2024 · 3 comments
Open

Correct way to create a fix that always runs? #153

rubberduck203 opened this issue Oct 15, 2024 · 3 comments

Comments

@rubberduck203
Copy link
Collaborator

According to the documentation

In the event there are no defined check [sic], the fix will always run.

https://oscope-dev.github.io/scope/docs/models/ScopeDoctorGroup#actions

but creating an action without a check results in a schema validation failure

apiVersion: scope.github.com/v1alpha
kind: ScopeDoctorGroup
metadata:
  name: mvce
spec:
  actions:
    - name: always-run
      fix:
        commands:
          - echo 'hello world!'
scope doctor run -v --progress plain
 WARN Resource 'ScopeDoctorGroup/mvce' didn't match the schema for ScopeDoctorGroup. "check" is a required property
 WARN Could not find any tasks to execute
Summary: 0 groups succeeded
 INFO More detailed logs at /tmp/scope/scope-root-20241015-oyOG.log

I tried various other ways of not specifying a check as well.

  actions:
    - name: always-run
      check:
      fix:
        commands:
          - echo 'hello world!'
 WARN Resource 'ScopeDoctorGroup/mvce' didn't match the schema for ScopeDoctorGroup. null is not of type "object"

Which led me to this config, which does work as expected.

apiVersion: scope.github.com/v1alpha
kind: ScopeDoctorGroup
metadata:
  name: mvce
spec:
  actions:
    - name: always-run
      check: {}
      fix:
        commands:
          - echo 'hello world!'
scope doctor run -v --progress plain
mvce/always-run:  hello world!
 INFO Fix ran successfully, group: "mvce", name: "always-run"
Summary: 1 groups succeeded

It feels like either check shouldn't be required or the documentation needs to be updated.

@noizwaves
Copy link
Contributor

Hey @rubberduck203 , thanks for reporting this. There's definitely a mismatch between the docs and the implementation here. The typing around the core data type implies the check is required, but In the event there are no defined check [sic], the fix will always run. does imply it's optional.

I think we should relax the typing here to make check optional. Out of curiosity, what kind of fix are you trying to run all the time? Are there more you foresee? Wondering if there's an alternative path here.

@rubberduck203
Copy link
Collaborator Author

I initially wanted to run poetry env use python3.9 every time to ensure the right python environment was activated.

I eventually implemented an appropriate check but, to be honest, I'm still not entirely sure it was worth the effort.
The env use command is fast and idempotent.

I don't have other examples off the top of my head, but I think the use case is:

This fix is fast and idempotent so there's no reason not to just run it every time, particular when an appropriate check is complex and/or slow.

@rubberduck203
Copy link
Collaborator Author

Just noting this for later.
I'm fairly confident we should be making the check field an Option here.

pub struct DoctorGroupAction {
pub name: String,
pub description: String,
pub fix: DoctorGroupActionFix,
pub check: DoctorGroupActionCheck,
pub required: bool,
}

And then, obviously, dealing with the fact that it's optional everywhere it's used.

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

No branches or pull requests

2 participants