bregman-arie / devops-exercises

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a command to run `run_ci.sh` in CONTRIBUTING.md

kevinadhiguna opened this issue · comments

Hi, I would like to ask about this section.

Before submitting the pull request

You can test your changes locally with the script run_ci.sh in scripts directory.


I would like to add a command to run run_ci.sh :

Before submitting the pull request

You can test your changes locally with the script run_ci.sh in scripts directory. Run the command below in project root directory :

$ sh scripts/run_ci.sh

Reason

This is the content of run_ci.sh :

#!/bin/bash
# These are the same steps we are running in Travis CI

python tests/syntax_lint.py
flake8 --max-line-length=100 . && echo "PEP8 Passed"

If I execute sh run_ci.sh in scripts directory, it will throw an error :

/home/user/pyenv/versions/3.8.12/bin/python: can't open file 'tests/syntax_lint.py': [Errno 2] No such file or directory
PEP8 Passed

Proposed Solution

Either :

  1. Ask users to execute sh scripts/run_ci.sh in project root directory.

or

  1. Change run_ci.sh :
#!/bin/bash
# These are the same steps we are running in Travis CI

-python tests/syntax_lint.py
+python ../tests/syntax_lint.py
flake8 --max-line-length=100 . && echo "PEP8 Passed"

Thank you. Any suggestion is appreciated.

@kevinadhiguna if you make the path relative to the script then it could be run from anywhere, something like this:

python $(dirname "$0")/syntax_lint.py

$0 is how the user referenced the script, i.e. scripts/run_ci.sh and dirname gets rid of the filename.


Also, in your proposed change, you recommend running the script with sh but the file has a shebang for bash. In this case it doesn't matter much but it's best to stay consistent because (in most systems) they are slightly different.

@kevinadhiguna do you plan to work on this issue? so we know who to assign it to

@bolshoytoster Thanks for the suggestion. However, do you mind telling what's wrong with this ?

run_ci.sh :

#!/bin/bash
# These are the same steps we are running in Travis CI

# python tests/syntax_lint.py
python $(dirname "$0")/syntax_lint.py
flake8 --max-line-length=100 . && echo "PEP8 Passed"

since the output gives an error saying :

/home/user/.pyenv/versions/3.8.13/bin/python: can't open file './syntax_lint.py': [Errno 2] No such file or directory
PEP8 Passed

@bregman-arie Sure, I am working on it.

@kevinadhiguna sorry, I must've read it wrong. I think it should be

python $(dirname "$0")/../tests/syntax_lint.py

run_ci.sh