Skip to content

Commit 20b5616

Browse files
committed
fix get licenseid
1 parent b3ea577 commit 20b5616

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

.github/workflows/mlflow-ci.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,34 +193,17 @@ jobs:
193193
CUSTOMER_NAME="${{ needs.create-release.outputs.customer-id }}"
194194
echo "Using customer name: $CUSTOMER_NAME"
195195
196-
# Try to get license ID, with error handling
197-
echo "Attempting to get license ID..."
198-
set +e
196+
# Get license ID using the task
197+
echo "Getting license ID..."
199198
INSTALLATION_ID=$(CUSTOMER_NAME="$CUSTOMER_NAME" task customer:get-license-id)
200-
GET_LICENSE_RESULT=$?
201-
set -e
202-
203-
if [ $GET_LICENSE_RESULT -ne 0 ]; then
204-
echo "Failed to get license ID. Error code: $GET_LICENSE_RESULT"
205-
echo "Output from get-license-id task:"
206-
echo "$INSTALLATION_ID"
207-
# List customers as a diagnostic step
208-
echo "Listing all customers for diagnostic purposes:"
209-
docker run --rm \
210-
-e REPLICATED_API_TOKEN=${{ secrets.REPLICATED_PLATFORM_EXAMPLES_TOKEN }} \
211-
-e REPLICATED_APP=${{ env.APP_SLUG }} \
212-
replicated/vendor-cli:latest \
213-
customer ls
214-
exit 1
215-
fi
216199
217-
# Check that we got a valid looking license ID
218-
if [[ ! "$INSTALLATION_ID" =~ ^[a-zA-Z0-9]+$ ]]; then
219-
echo "License ID doesn't look valid: '$INSTALLATION_ID'"
200+
# Check if we got a result
201+
if [ -z "$INSTALLATION_ID" ]; then
202+
echo "ERROR: Got empty license ID"
220203
exit 1
221204
fi
222205
223-
echo "Successfully retrieved license ID: $INSTALLATION_ID"
206+
echo "License ID: $INSTALLATION_ID"
224207
echo "license_id=$INSTALLATION_ID" >> $GITHUB_OUTPUT
225208
env:
226209
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_PLATFORM_EXAMPLES_TOKEN }}

applications/mlflow/Taskfile.yml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,37 +263,54 @@ tasks:
263263
-e REPLICATED_API_TOKEN=$REPLICATED_API_TOKEN \
264264
-e REPLICATED_APP={{.APP_NAME}} \
265265
replicated/vendor-cli:latest \
266-
customer inspect --customer "{{.CUSTOMER_NAME}}" --output json > $OUTPUT_FILE 2>&1
266+
customer inspect --customer "{{.CUSTOMER_NAME}}" > $OUTPUT_FILE 2>&1
267267
268-
# Check if the output contains valid JSON
269-
if ! grep -q "{" $OUTPUT_FILE; then
270-
echo "ERROR: vendor-cli did not return valid JSON. Output:"
268+
# Check if the command succeeded
269+
if [ $? -ne 0 ]; then
270+
echo "ERROR: vendor-cli command failed. Output:"
271271
cat $OUTPUT_FILE
272272
rm $OUTPUT_FILE
273273
exit 1
274274
fi
275275
276-
# Try to extract installationId from the JSON
277-
if command -v jq >/dev/null 2>&1; then
278-
# If jq is available, use it for proper JSON parsing
279-
INSTALLATION_ID=$(cat $OUTPUT_FILE | jq -r '.installationId // empty')
280-
else
281-
# Fallback to grep/sed if jq is not available
282-
INSTALLATION_ID=$(grep -o '"installationId"[[:space:]]*:[[:space:]]*"[^"]*"' $OUTPUT_FILE | sed 's/.*"\([^"]*\)".*/\1/')
276+
# Try direct extraction using grep pattern for the installationId
277+
INSTALLATION_ID=$(grep -o '"installationId": *"[^"]*"' $OUTPUT_FILE | grep -o '"[^"]*"$' | tr -d '"' || true)
278+
279+
# If grep didn't find it, try as a fallback to parse via jq if the file looks like JSON
280+
if [ -z "$INSTALLATION_ID" ] && grep -q "^{" $OUTPUT_FILE; then
281+
echo "Attempting to extract installation ID with jq..."
282+
set +e # Don't exit on error
283+
if command -v jq >/dev/null 2>&1; then
284+
INSTALLATION_ID=$(cat $OUTPUT_FILE | jq -r '.installationId // empty' 2>/dev/null || true)
285+
fi
286+
set -e
283287
fi
284288
285289
# Check if we got a valid ID
286290
if [ -z "$INSTALLATION_ID" ]; then
287-
echo "Failed to extract installationId from customer JSON"
288-
echo "JSON structure:"
289-
cat $OUTPUT_FILE
290-
rm $OUTPUT_FILE
291-
exit 1
291+
echo "Failed to extract installationId from vendor-cli output"
292+
echo "Output content:"
293+
cat $OUTPUT_FILE | head -n 20
294+
295+
# Special case: If the output appears to be just a plain string already, use that
296+
if [ $(wc -l < $OUTPUT_FILE) -eq 1 ] && [ $(wc -w < $OUTPUT_FILE) -eq 1 ]; then
297+
echo "Output appears to be a single token, using it directly as the license ID"
298+
INSTALLATION_ID=$(cat $OUTPUT_FILE | tr -d '[:space:]')
299+
else
300+
rm $OUTPUT_FILE
301+
exit 1
302+
fi
292303
fi
293304
294305
# Clean up the temporary file
295306
rm $OUTPUT_FILE
296307
308+
# Validate the ID format (alphanumeric)
309+
if ! [[ $INSTALLATION_ID =~ ^[a-zA-Z0-9]+$ ]]; then
310+
echo "ERROR: Extracted installation ID doesn't match expected format: '$INSTALLATION_ID'"
311+
exit 1
312+
fi
313+
297314
# Print the license ID so it can be captured
298315
echo "$INSTALLATION_ID"
299316

0 commit comments

Comments
 (0)