forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
36 lines (31 loc) · 1.37 KB
/
cf-env-unclaim.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
name: Unclaim an environment
on:
workflow_call:
inputs:
environment:
required: true
type: string
toolsmith-env-name:
required: true
type: string
jobs:
cf-env-unclaim:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Unclaim environment
env:
api_token: ${{ secrets.TOOLSMITHS_API_TOKEN }}
hostname: ${{ secrets.TOOLSMITHS_HOSTNAME }}
run: |
while true; do
output=$(curl -s --show-error -D >(tee headers.txt >&2) -H 'Accept: application/json' \
-X POST "https://${hostname}/pooled_gcp_engineering_environments/unclaim" \
--data-urlencode "api_token=${api_token}" \
--data-urlencode "name=${{ inputs.toolsmith-env-name }}")
ERR_500="Sorry, the Toolsmiths Environments app is currently encountering issues. Trying again in 30 seconds..."
grep -q -E "HTTP/[[:digit:]\.]{1,3} 500" headers.txt && echo "$ERR_500" && sleep 30 && continue
grep -q -E "HTTP/[[:digit:]\.]{1,3} 401" headers.txt && echo $(echo "$output" | jq '.messages | join(", ")') && exit 1
grep -q -E "HTTP/[[:digit:]\.]{1,3} 404" headers.txt && echo $(echo "$output" | jq '.messages | join(", ")') && exit 2
grep -q -E "HTTP/[[:digit:]\.]{1,3} 202" headers.txt && break
done