Skip to content

Commit 6f4e9f7

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

File tree

4 files changed

+71
-65
lines changed

4 files changed

+71
-65
lines changed

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

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