|
1 | | -name: "Cleanup leftovers" |
2 | | -description: "Cleanup any leftovers of e2e test" |
| 1 | +name: Cleanup leftovers |
| 2 | +description: Cleanup any leftovers of e2e test |
3 | 3 | inputs: |
4 | 4 | api_url: |
5 | 5 | required: false |
6 | | - description: "Full URL of the API service to use. Defaults to the production API endpoint https://api.clickhouse.cloud/v1" |
| 6 | + description: Full URL of the API service to use. Defaults to the production API endpoint https://api.clickhouse.cloud/v1 |
7 | 7 | default: "" |
8 | 8 | organization_id: |
9 | 9 | required: true |
10 | | - description: "The clickhouse organization ID" |
| 10 | + description: The clickhouse organization ID |
11 | 11 | token_key: |
12 | 12 | required: true |
13 | | - description: "The clickhouse token key" |
| 13 | + description: The clickhouse token key |
| 14 | + type: secret |
14 | 15 | token_secret: |
15 | 16 | required: true |
16 | | - description: "The clickhouse token secret" |
| 17 | + description: The clickhouse token secret |
| 18 | + type: secret |
17 | 19 | token: |
18 | 20 | required: true |
19 | | - description: "The unique token assigned to this e2e run" |
| 21 | + description: The unique token assigned to this e2e run |
20 | 22 |
|
21 | 23 | runs: |
22 | | - using: "composite" |
| 24 | + using: composite |
23 | 25 | steps: |
24 | | - - name: cleanup clickhouse |
| 26 | + - name: Cleanup ClickHouse Instances |
25 | 27 | shell: bash |
| 28 | + env: |
| 29 | + API_URL: ${{ inputs.api_url }} |
| 30 | + ORGANIZATION_ID: ${{ inputs.organization_id }} |
| 31 | + TOKEN_KEY: ${{ inputs.token_key }} |
| 32 | + TOKEN_SECRET: ${{ inputs.token_secret }} |
| 33 | + SUFFIX: ${{ inputs.token }} |
26 | 34 | run: | |
27 | | - api_url="${{ inputs.api_url }}" |
28 | | - if [ "$api_url" == "" ] |
29 | | - then |
30 | | - api_url="https://api.clickhouse.cloud/v1" |
31 | | - fi |
32 | | - organization_id="${{ inputs.organization_id }}" |
33 | | - token_key="${{ inputs.token_key }}" |
34 | | - token_secret="${{ inputs.token_secret }}" |
35 | | - suffix="${{ inputs.token }}" |
36 | | -
|
37 | | - echo "Deleting any service with suffix ${suffix}" |
38 | | -
|
39 | | - while :; do |
40 | | - output="$(curl -su ${token_key}:${token_secret} ${api_url}/organizations/${organization_id}/services)" |
41 | | - ids=$(echo "$output"|jq --arg suffix "${suffix}" -r '.result[]| select(.name | endswith($suffix)) |(.id + "," + .state)') |
42 | | -
|
43 | | - if [ "$ids" == "" ] |
44 | | - then |
45 | | - break |
46 | | - fi |
47 | | -
|
48 | | - count="$(echo "$ids"|wc -l)" |
49 | | - echo "There are ${count} services to be cleaned up" |
50 | | -
|
51 | | - for idandstatus in $ids |
52 | | - do |
53 | | - id="$(echo "${idandstatus}" | cut -d"," -f1)" |
54 | | - status="$(echo "${idandstatus}" | cut -d"," -f2)" |
55 | | -
|
56 | | - case "$status" in |
57 | | - stopped) |
58 | | - echo "Deleting service ${id}" |
59 | | - curl -su ${token_key}:${token_secret} -XDELETE "${api_url}/organizations/${organization_id}/services/${id}" -o /dev/null |
60 | | - ;; |
61 | | - stopping) |
62 | | - echo "Service ${id} is stopping, waiting" |
63 | | - ;; |
64 | | - *) |
65 | | - echo "Stopping service ${id}" |
66 | | - curl -su ${token_key}:${token_secret} -XPATCH "${api_url}/organizations/${organization_id}/services/${id}/state" --data '{"command": "stop"}' -H 'Content-Type: application/json' -o /dev/null |
67 | | - ;; |
68 | | - esac |
69 | | - done |
70 | | -
|
71 | | - sleep 5 |
72 | | - done |
73 | | -
|
74 | | - echo "Cleanup complete" |
| 35 | + ./.github/actions/cleanup-clickhouse/cleanup.sh |
0 commit comments