@@ -55,17 +55,36 @@ runs:
55
55
with :
56
56
name : pr
57
57
58
- - name : Create preview environment
58
+ - name : Setup preview name
59
59
shell : bash
60
60
run : |
61
61
prId=$(<pr-id.txt)
62
- # TODO: make preview name configurable!
63
- previewName=preview-$prId
62
+ repoName=$GITHUB_REPOSITORY
63
+ repoNameCleaned=$(echo -n "$repoName" | tr -c '[:alnum:]' '-')
64
+ previewName=preview-$repoNameCleaned-$prId
65
+ echo "previewName=$previewName" >> $GITHUB_ENV
64
66
67
+ - name : Create preview environment
68
+ shell : bash
69
+ run : |
65
70
autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"
66
71
extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}"
67
72
lifetime="${{ inputs.lifetime }}"
68
73
74
+ list_response=$(curl -X GET \
75
+ -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
76
+ -H "content-type: application/json" \
77
+ https://api.localstack.cloud/v1/compute/instances)
78
+
79
+ instance_exists=$(echo "$list_response" | jq --arg NAME "$previewName" '.[] | select(.instance_name == $NAME)')
80
+
81
+ if [ -n "$instance_exists" ]; then
82
+ del_response=$(curl -X DELETE \
83
+ -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
84
+ -H "content-type: application/json" \
85
+ https://api.localstack.cloud/v1/compute/instances/$previewName)
86
+ fi
87
+
69
88
response=$(curl -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime} ,\"env_vars\": {\"AUTO_LOAD_POD\": \"${autoLoadPod}\", \"EXTENSION_AUTO_INSTALL\": \"${extensionAutoInstall}\"}}"\
70
89
-H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
71
90
-H "content-type: application/json" \
0 commit comments