stages:
- update_copilot
update_copilot_actions:
stage: update_copilot
script:
- >
if git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep -q "swagger.json"; then
echo "Swagger file has changed. Updating Copilot actions..."
# Delete all actions from Copilot using environment variables for ID and token
curl --location --request DELETE "https://api.opencopilot.so/backend/copilot/$COPILOT_ID" \
--header 'Accept: application/json' \
--header "Authorization: Bearer $AUTH_TOKEN"
# Wait a bit for the delete action to propagate
sleep 5
# Import actions from the updated Swagger file using environment variables
curl --location --request PUT "https://api.opencopilot.so/backend/actions/bot/$COPILOT_ID/import-from-swagger" \
--header 'Accept: application/json' \
--header "Authorization: Bearer $AUTH_TOKEN" \
--form 'file=@"./swagger.json"'
echo "Copilot actions updated."
else
echo "Swagger file not changed. No action needed."
fi
only:
- main
image: curlimages/curl:latest