@@ -88,38 +88,44 @@ jobs:
8888
8989 echo "NICKNAME=$NICKNAME" >> "$GITHUB_ENV"
9090
91- - name : Check if AppBundle exists
92- run : |
93- HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
94- "$DA_BASE_URL/appbundles/$APPBUNDLE_NAME" \
95- -H "Authorization: Bearer $APS_TOKEN")
96- echo "APPBUNDLE_STATUS=$HTTP_STATUS" >> "$GITHUB_ENV"
97-
9891 - name : Create or version AppBundle
9992 run : |
100- if [ "$APPBUNDLE_STATUS" = "404" ]; then
101- echo "Creating new AppBundle..."
102- RESPONSE=$(curl -s -X POST \
103- "$DA_BASE_URL/appbundles" \
104- -H "Authorization: Bearer $APS_TOKEN" \
105- -H "Content-Type: application/json" \
106- -d "{\"id\":\"$APPBUNDLE_NAME\",\"engine\":\"$ENGINE\",\"description\":\"deploy $GITHUB_SHA\"}")
107- else
108- echo "Creating new AppBundle version..."
109- RESPONSE=$(curl -s -X POST \
93+ # Create-first: POST /appbundles creates the bundle. If it already
94+ # exists DA returns 409, in which case we POST a new version instead.
95+ # (A GET-existence probe is unreliable here: DA can answer 400 for a
96+ # not-yet-created bundle, which previously sent us down the wrong path.)
97+ BODY=$(mktemp)
98+ STATUS=$(curl -s -o "$BODY" -w "%{http_code}" -X POST \
99+ "$DA_BASE_URL/appbundles" \
100+ -H "Authorization: Bearer $APS_TOKEN" \
101+ -H "Content-Type: application/json" \
102+ -d "{\"id\":\"$APPBUNDLE_NAME\",\"engine\":\"$ENGINE\",\"description\":\"deploy $GITHUB_SHA\"}")
103+
104+ if [ "$STATUS" = "409" ]; then
105+ echo "AppBundle exists, creating new version..."
106+ STATUS=$(curl -s -o "$BODY" -w "%{http_code}" -X POST \
110107 "$DA_BASE_URL/appbundles/$APPBUNDLE_NAME/versions" \
111108 -H "Authorization: Bearer $APS_TOKEN" \
112109 -H "Content-Type: application/json" \
113110 -d "{\"engine\":\"$ENGINE\",\"description\":\"deploy $GITHUB_SHA\"}")
111+ else
112+ echo "Creating new AppBundle..."
114113 fi
115114
116- VERSION=$(echo "$RESPONSE" | jq -r '.version')
117- UPLOAD_URL=$(echo "$RESPONSE" | jq -r '.uploadParameters.endpointURL')
118- FORM_DATA=$(echo "$RESPONSE" | jq -c '.uploadParameters.formData')
115+ if [ "$STATUS" -lt 200 ] || [ "$STATUS" -ge 300 ]; then
116+ echo "::error::Failed to create AppBundle/version (HTTP $STATUS)"
117+ cat "$BODY"
118+ exit 1
119+ fi
119120
120- if [ "$VERSION" = "null" ] || [ "$UPLOAD_URL" = "null" ]; then
121- echo "::error::Failed to create AppBundle version"
122- echo "$RESPONSE" | jq .
121+ RESPONSE=$(cat "$BODY")
122+ VERSION=$(echo "$RESPONSE" | jq -r '.version // empty')
123+ UPLOAD_URL=$(echo "$RESPONSE" | jq -r '.uploadParameters.endpointURL // empty')
124+ FORM_DATA=$(echo "$RESPONSE" | jq -c '.uploadParameters.formData // empty')
125+
126+ if [ -z "$VERSION" ] || [ -z "$UPLOAD_URL" ] || [ -z "$FORM_DATA" ]; then
127+ echo "::error::AppBundle response missing version or upload parameters"
128+ echo "$RESPONSE" | jq . || echo "$RESPONSE"
123129 exit 1
124130 fi
125131
0 commit comments