-
Notifications
You must be signed in to change notification settings - Fork 576
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
Add a script to help managing embedded scripts externally #740
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for starting this!
I think it's fine to have it under a test
folder at least for now - eventually we might want some way to make it easier for contributors to include this in their workflow... perhaps a make
target or a shell script.
Eventually we'll need
- unit tests for this python
- a script to trigger this and write the output in the right place
- a CI job to run the script and check that generated YAMLs are up to date
But not in this PR :)
/lgtm
script: "#include script.sh" | ||
``` | ||
|
||
The script will see it and includes the `script.sh` in place of your "#include script.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to document that the result is sent to stdout and that if more than one YAML docs is in the source, all be parsed and separated by ---
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 👍🏻
REGEXP = r"^#include\s*([^$]*)" | ||
|
||
|
||
def replace(filename: str) -> typing.List: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually we should have unit tests 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I added some, i didn't bother because we don't have ways to run them yet 😅
I usually use pytest
but i guess python builtin unittest should be enough for this so we can just python3 the test file directly and it will run them.
The idea of this script is if you have inside your script something like this : It will replace this #include with the content of python/script.py This make it easier to write your tasks and use linters/code checkers from your editor on your included script.
how would that work tho? In main we have the "#include script.py" template files? But users (including ides/tkn hub or even curl people) would expect to be able to run the task directly from main branch, isnt it ? maybe we can have both, we could have a comment above the Maybe that's a bit confusing, so let me rephrase my thinking :
steps:
- name: foo
#include foo.py
script : |
#!/usr/bin/env python
print("helo world")
This allows user to have the latest task working directly and devs being able to develop into a real file for the script portion. Let me know if that make sense 🙇🏻 |
I don't like this approach too much because it means that we need two commits to do a change, and in between commits the repo is in an inconsistent state.
The workflow I had in mind is very much similar to what we have to generated golang files in
steps:
- name: foo
#include foo.py
script : |
#!/usr/bin/env python
print("helo world")
The paths / naming might change, we could have the template defined in a subfolder for instance, to "hide" it from users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great start, thank you!
We'll need to create an infra image that embeds the script, so we can use it to run a CI job.
For that we'll need a docker file and a requirements.txt, but we can add those in a follow up.
/lgtm
@tektoncd/catalog-maintainers it would be nice to move forward on this - can we have a second reviewer? |
spec: | ||
steps: | ||
- name: step1 | ||
script: "#include script.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about keeping it like ⬇️ ?
script: "#include script.sh" | |
script: "#include /path/to/script.sh" |
script: "#include script.sh" | ||
``` | ||
|
||
The "embed_script" script will see it and includes the `script.sh` in place of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "embed_script" script will see it and includes the `script.sh` in place of | |
The "embed_script" script will see it in the specified path and includes the `script.sh` in place of |
# Author: Chmouel Boudjnah <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we change this as well to Tekton Authors?
Issues go stale after 90d of inactivity. /lifecycle stale Send feedback to tektoncd/plumbing. |
/remove-lifecycle stale i didnt see your review @vinamra28 🙇🏻 |
Issues go stale after 90d of inactivity. /lifecycle stale Send feedback to tektoncd/plumbing. |
Stale issues rot after 30d of inactivity. /lifecycle rotten Send feedback to tektoncd/plumbing. |
Rotten issues close after 30d of inactivity. /close Send feedback to tektoncd/plumbing. |
@tekton-robot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/remove-lifecycle rotten |
@vinamra28: Reopened this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@chmouel: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
I don't think it's trivial to do this, this will broke the "kuebctl apply -f https://github.com/tektoncd/catalog/path/to/task.yaml" maybe with this TEP which split the structure from the implementation we may be able to achive that but this probably need something extras on the hub end... |
Not necessarily, it depends on how it's implemented. My suggestion would be:
|
I think it may be a bit cumbersome for non frequent contributor, we have generation on cli for mans/golden etc.. and it's already a source of annoyances since it's easy to forget to run the command before sending the iteration. What about CI job commiting to the repo the final rendered version directly to a branch? alternatively if hub could do this transparently and we say that hub is the "only" trusted source, then we would not have to store the yaml in repo.
|
The idea of this script is if you have inside your script something like this :
It will replace this #include with the content of python/script.py
This make it easier to write your tasks and use linters/code checkers from your
editor on your included script.
This sparked from @afrittoli discussion here #715
Currently this is a helper so this would be up to the contributor to uses it before commit but i think we can maybe think on how to do this post merge so to be transparent.