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

Bash code in environment variables is not evaluated in travis-conditions #24

Open
manoharuss opened this issue Dec 8, 2019 · 1 comment

Comments

@manoharuss
Copy link

For example of an environment variable with bash code in it,

env:
 global:
   - test_variable=$(if [ 1 == 1 ]; then echo true; else echo false; fi)

In travis-conditions gem module, the bash code for an environment variable is not evaluated. From the above example, travis-condition takes the entire line as a direct string value i.e;
test_variable='$(if [ 1 == 1 ]; then echo true; else echo false; fi)'

Proof

This commit containing travis conditions replicate this behavior
https://github.com/manoharuss/travis-boolean-conditions/runs/339047922.

These conditions resolve to true in travis-conditions,

  if: env(test_variable) IS true

The behavior of env() IS true condition is that, it checks that the environment variables exists and not a false value. It satisfies for everything else.

  if: env(test_variable)='$(if [ 1 == 1 ]; then echo true; else echo false; fi)'

Because travis-conditions does not evaluate the bash line and takes the env line as is.

Request

If bash code in environment variables is resolved before running travis-conditions on it, I intend to use it this way with git diff.

env:
  global:
     - modified_pipeline = $(if [ $(eval git diff $TRAVIS_COMMIT_RANGE --name-only --stat | grep pipelines/modified_pipeline) ]; then echo true; else echo false; fi)
  if: env(modified_pipeline)=true

This helps better optimize build invocations in mono repos. I am confident this change to travis-conditions will not break any existing builds for other companies because this feature does not exist yet. Please help friends.

@manoharuss
Copy link
Author

For anyone looking for a similar solution, for a mono repo I have used

  • create a githook locally so that the developer commits on PRs append a particular pipeline name into commit message

i.e git commit -m "test" from developer is appended with test [pipeline_names]

  • in travis-ci, this is then used as a regex condition for each pipeline
- name: so_so_pipeline
      env: CACHE_NAME=so_so_pipeline
      if: type = push OR commit_message =~ /(no_filter|master|Master)/ OR commit_message =~ so_so_pipeline
      services:
        - docker
      script:
        - docker-runner.sh  options pipelines/so_so_pipeline

It could definitely be easier if Travis provides a way to write bash code to orchestrate builds before the submission. it gives complete power to the developer to how to use them smartly.

Github Actions has a similar workflow but it looks it is fully formed https://github.com/sdras/awesome-actions

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

1 participant