Skip to content

Commit 1f1efeb

Browse files
author
Greg O'Grady
committed
refactor: update env_name.txt checks to be the same
1 parent 199f709 commit 1f1efeb

4 files changed

Lines changed: 64 additions & 66 deletions

File tree

src/commands/vfcli/vfcli-delete-or-release-env.yml

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,57 @@ steps:
3030
force="<< parameters.force >>"
3131
if [[ $force == true ]]; then
3232
vfcli env delete --name "<< parameters.env-name >>" --interactive false
33-
else
34-
if [[ -f << parameters.env-name-path >> ]]; then
35-
env_name=$(cat << parameters.env-name-path >>)
36-
echo "Env: $env_name will be released"
37-
else
38-
env_name="null"
39-
echo "Env name file was not found. Will proceed to deleting the environment."
40-
fi
41-
if [[ "$env_name" != "null" ]] && [[ -n "$env_name" ]]; then
42-
echo "Releasing the environment..... $env_name"
43-
vfcli pool release-env --env-name "$env_name"
44-
if [[ << parameters.reset-db >> == true ]]; then
45-
echo "Resetting the database for $env_name"
46-
echo "Triggering pipeline with env-name parameter"
47-
response=$(curl -s -w "\n%{http_code}" \
48-
--request POST \
49-
--url "https://circleci.com/api/v2/project/gh/voiceflow/env-release-system/pipeline" \
50-
--header "Circle-Token: ${CIRCLECI_API_TOKEN}" \
51-
--header "content-type: application/json" \
52-
--data "{\"parameters\":{\"e2e_env_name\":\"$env_name\",\"trigger_pipeline\":true}}")
53-
http_status=$(echo "$response" | tail -n1)
54-
response_body=$(echo "$response" | sed '$d')
55-
if [[ $http_status == "201" || $http_status == "200" ]]; then
56-
if echo "$response_body" | jq empty 2>/dev/null; then
57-
pipeline_id=$(echo "$response_body" | jq -r '.id // empty')
58-
pipeline_number=$(echo "$response_body" | jq -r '.number // empty')
59-
if [[ -n $pipeline_number ]]; then
60-
pipeline_url="https://app.circleci.com/pipelines/github/voiceflow/env-release-system/$pipeline_number"
61-
echo "Env Release Pipeline triggered successfully."
62-
echo "Pipeline URL: $pipeline_url"
63-
echo "Pipeline ID: $pipeline_id"
64-
echo "Exiting with success."
65-
exit 0
66-
else
67-
echo "Failed to retrieve pipeline number. Response body: $response_body"
68-
fi
69-
else
70-
echo "Response is not valid JSON. Response body: $response_body"
71-
fi
33+
exit 0
34+
fi
35+
36+
if [ ! -f << parameters.env-name-path >> ] ||
37+
[ "$(cat << parameters.env-name-path >> )" == "null" ] ||
38+
[ -z "$(cat << parameters.env-name-path >> )" ]; then
39+
40+
echo "Env name file was not found. Will proceed to deleting the environment."
41+
echo "Kick-starting the deletion of the environment."
42+
vfcli env delete --name "<< parameters.env-name >>" --interactive false
43+
exit 0
44+
fi
45+
46+
env_name=$(cat << parameters.env-name-path >>)
47+
echo "Env: $env_name will be released"
48+
49+
echo "Releasing the environment..... $env_name"
50+
vfcli pool release-env --env-name "$env_name"
51+
if [[ << parameters.reset-db >> == true ]]; then
52+
echo "Resetting the database for $env_name"
53+
echo "Triggering pipeline with env-name parameter"
54+
response=$(curl -s -w "\n%{http_code}" \
55+
--request POST \
56+
--url "https://circleci.com/api/v2/project/gh/voiceflow/env-release-system/pipeline" \
57+
--header "Circle-Token: ${CIRCLECI_API_TOKEN}" \
58+
--header "content-type: application/json" \
59+
--data "{\"parameters\":{\"e2e_env_name\":\"$env_name\",\"trigger_pipeline\":true}}")
60+
http_status=$(echo "$response" | tail -n1)
61+
response_body=$(echo "$response" | sed '$d')
62+
if [[ $http_status == "201" || $http_status == "200" ]]; then
63+
if echo "$response_body" | jq empty 2>/dev/null; then
64+
pipeline_id=$(echo "$response_body" | jq -r '.id // empty')
65+
pipeline_number=$(echo "$response_body" | jq -r '.number // empty')
66+
if [[ -n $pipeline_number ]]; then
67+
pipeline_url="https://app.circleci.com/pipelines/github/voiceflow/env-release-system/$pipeline_number"
68+
echo "Env Release Pipeline triggered successfully."
69+
echo "Pipeline URL: $pipeline_url"
70+
echo "Pipeline ID: $pipeline_id"
71+
echo "Exiting with success."
72+
exit 0
7273
else
73-
echo "Failed to trigger pipeline. HTTP status code: $http_status"
74-
echo "Response body: $response_body"
74+
echo "Failed to retrieve pipeline number. Response body: $response_body"
7575
fi
76+
else
77+
echo "Response is not valid JSON. Response body: $response_body"
7678
fi
77-
vfcli env resume "$env_name" --interactive false
78-
vfcli track attach --branch master --components all --name "$env_name" --interactive false --no-circleci
79-
vfcli pool free-env --env-name "$env_name"
8079
else
81-
echo "Kick-starting the deletion of the environment."
82-
vfcli env delete --name "<< parameters.env-name >>" --interactive false
80+
echo "Failed to trigger pipeline. HTTP status code: $http_status"
81+
echo "Response body: $response_body"
8382
fi
8483
fi
84+
vfcli env resume "$env_name" --interactive false
85+
vfcli track attach --branch master --components all --name "$env_name" --interactive false --no-circleci
86+
vfcli pool free-env --env-name "$env_name"

src/commands/vfcli/vfcli-suspend-env.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ steps:
1717
- run:
1818
name: Suspend Environment
1919
command: |
20-
echo "Contents of << parameters.env-name-path >>:"
21-
cat << parameters.env-name-path >>
22-
if [[ -f << parameters.env-name-path >> ]]; then
20+
if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >> )" != "null" ]; then
2321
echo "Using env_name from file << parameters.env-name-path >> in the suspend action"
2422
env_name=$(cat << parameters.env-name-path >>)
2523
else
2624
env_name="<< parameters.env-name >>"
2725
fi
28-
if [[ "$env_name" == "null" ]] || [[ -z "$env_name" ]]; then
29-
# If env_name from file is "null" or empty, use the default parameter
30-
env_name="<< parameters.env-name >>"
31-
fi
32-
33-
vfcli env suspend "$env_name" --interactive false --wait --track-file "<< parameters.track-file >>"
26+
echo "Using env: ${env_name-}"
27+
vfcli env suspend "${env_name-}" --interactive false --wait --track-file "<< parameters.track-file >>"

src/jobs/e2e/collect-e2e-logs.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ steps:
4444
echo "Contents of << parameters.env-name-path >>:"
4545
cat << parameters.env-name-path >>
4646
if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >> )" != "null" ]; then
47-
DEV_ENV_NAME=$(cat << parameters.env-name-path >> )
48-
else
49-
DEV_ENV_NAME=<< parameters.e2e-env-name >>
50-
fi
47+
DEV_ENV_NAME=$(cat << parameters.env-name-path >> )
48+
else
49+
DEV_ENV_NAME=<< parameters.e2e-env-name >>
50+
fi
5151
# Gather summary state of all pods in the namespace
5252
echo "Gathering Kubernetes state before run for env $DEV_ENV_NAME"
5353
kubectl get pods -n $DEV_ENV_NAME >> "${LOG_DIR:?}/${KUBE_STATE_DIR:?}/pods-summary-state-before-run.log"
@@ -82,13 +82,13 @@ steps:
8282
COMPONENT_LOG_DIR: *component_log_dir
8383
background: true
8484
command: |
85-
function capture_logs() {
86-
if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >>)" != "null" ]; then
87-
DEV_ENV_NAME=$(cat << parameters.env-name-path >>)
88-
else
89-
DEV_ENV_NAME=<< parameters.e2e-env-name >>
90-
fi
85+
if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >>)" != "null" ]; then
86+
DEV_ENV_NAME=$(cat << parameters.env-name-path >>)
87+
else
88+
DEV_ENV_NAME=<< parameters.e2e-env-name >>
89+
fi
9190
91+
function capture_logs() {
9292
echo "Capturing logs for environment $DEV_ENV_NAME"
9393
9494
# Read components into an array directly from the command output
@@ -126,6 +126,7 @@ steps:
126126
else
127127
DEV_ENV_NAME=<< parameters.e2e-env-name >>
128128
fi
129+
129130
# Read components into an array directly from the command output
130131
components=($(vfcli component list -n "${DEV_ENV_NAME:?}" | awk 'NR>3 {print $1}'))
131132
# Gather summary state of all pods in the namespace

src/jobs/smoke/report_smoke_failures.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ steps:
2626
- run:
2727
name: Report Test Failures
2828
command: |
29-
if [[ -f << parameters.env-name-path >> ]]; then
29+
30+
if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >> )" != "null" ]; then
3031
echo "Using env_name from file << parameters.env-name-path >> in the suspend action"
3132
env_name=$(cat << parameters.env-name-path >>)
3233
else

0 commit comments

Comments
 (0)