From c99eb17850e51327449e6fac5572c6cfc436d21c Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Tue, 24 Mar 2020 10:18:14 +0100 Subject: vars: fix `clever_base_env` by removing a variable if not necessary The `CC_RUN_COMMAND` variable was defined in case we use haskell binary as entrypoints. However if the `clever_haskell_entry_point` variable is not defined we shouldn't define the `CC_RUN_COMMAND` env variable. --- .travis.yml | 6 ++++++ defaults/main.yml | 4 ++-- templates/env.j2 | 8 +++++++- tests/fake.sh | 14 ++++++++++++++ tests/inventory | 2 +- tests/test.yml | 6 +++++- vars/main.yml | 3 --- 7 files changed, 35 insertions(+), 8 deletions(-) create mode 100755 tests/fake.sh diff --git a/.travis.yml b/.travis.yml index 22e80b3..0fcb053 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,12 @@ script: - ansible-lint . - shellcheck **/*.sh - scripts/dhall_check.sh + # Run integration test + - mkdir -p ~/.local/bin + - cp tests/fake.sh ~/.local/bin/clever + - cp tests/fake.sh ~/.local/bin/git + - ansible-playbook tests/test.yml -i tests/inventory notifications: slack: fretlink:pTIylIN7zkwRFuL3aHERmsbB + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/defaults/main.yml b/defaults/main.yml index d4aa86d..0e4bada 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,12 +1,12 @@ --- # defaults file for clever -clever_cli_version: 1.4.2 +clever_cli_version: 1.6.3 clever_user_path: .local/bin clever_app_root: "{{ app_root | default(playbook_dir + '/..') }}" clever_app_confdir: "{{ clever_app_root }}/.clever_cloud" clever_login_file: "{{ clever_app_confdir }}/login" -clever_haskell_entry_point: "{{ clever_entry_point | default('') }}" +clever_haskell_entry_point: "{{ clever_entry_point | default(None) }}" clever_env: {} clever_disable_metrics: false diff --git a/templates/env.j2 b/templates/env.j2 index d2bf446..66e5508 100644 --- a/templates/env.j2 +++ b/templates/env.j2 @@ -1,3 +1,9 @@ {% for key, value in (clever_base_env | combine(clever_env)).items() %} -{{ key }}="{{ value | tojson }}" +{{ key }}="{{ value | to_json }}" {% endfor %} + +{%- if clever_haskell_entry_point %} +{# Haskell only #} +{# https://www.clever-cloud.com/doc/get-help/reference-environment-variables/#haskell #} +CC_RUN_COMMAND="{{'~/.local/bin/' + clever_haskell_entry_point | to_json }}" +{% endif %} diff --git a/tests/fake.sh b/tests/fake.sh new file mode 100755 index 0000000..2835e85 --- /dev/null +++ b/tests/fake.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +binary="${0/*\/}" +fakeCommit="aaa000aaa000aaa000aaa000aaa000aaa000aaa0" + +if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then + echo "1.6.3" +elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then + echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${fakeCommit} Git" +elif [ "${binary}" = "git" ]; then + echo "${fakeCommit}" +else + echo "${binary} called with arguments: ${*}" +fi diff --git a/tests/inventory b/tests/inventory index 878877b..49d4fe2 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1,2 +1,2 @@ -localhost +localhost ansible_connection=local diff --git a/tests/test.yml b/tests/test.yml index 3e3c57f..663bc6b 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -2,4 +2,8 @@ - hosts: localhost remote_user: root roles: - - clever \ No newline at end of file + - role: clever + vars: + clever_token: 123abc + clever_secret: cba321 + clever_app: app_00000000-0000-0000-0000-000000000000 diff --git a/vars/main.yml b/vars/main.yml index 94ee792..a9625f0 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,9 +2,6 @@ # vars file for clever clever_base_env: CACHE_DEPENDENCIES: "true" - # Haskell only - # https://www.clever-cloud.com/doc/get-help/reference-environment-variables/#haskell - CC_RUN_COMMAND: "~/.local/bin/{{ clever_haskell_entry_point }}" CC_DISABLE_METRICS: "{{ clever_disable_metrics | lower }}" PORT: "8080" -- cgit v1.2.3