You can use the following GitLab CI/CD actions to automate your workflow:
- Whenever there is a change on the swagger file, the copilot actions will be updated automatically.
- Make sure to replace the environment variables (
$COPILOT_ID
, $AUTH_TOKEN
) with your own values.
- If you want access to our API, please check this link.
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..."
curl --location --request DELETE "https://api.opencopilot.so/backend/actions/bot/$COPILOT_ID" \
--header 'Accept: application/json' \
--header "Authorization: Bearer $AUTH_TOKEN"
sleep 5
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