github action
name: Update the Delft-FEWS Configuration with the Admin Interface API
#
on:
push:
branches:
- main
paths:
- 'DelftFewsProject/Config/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Zip the Delft-FEWS Configuration and Upload
run: |
adminInterfaceUser="${{ secrets.AI_USER }}"
adminInterfacePassword="${{ secrets.AI_SECRET }}"
adminInterfaceApiUrl="${{ secrets.AI_API_URL }}"
gitMessage=`git show -s --format=%B | tr -d '\n' | cut -c1-180`
commentText="Version: #${GITHUB_SHA:0:7} - ${gitMessage}"
cd "DelftFewsProject"
zip -r ./config.zip Config
echo 'AI login'
curl -u "${adminInterfaceUser}:${adminInterfacePassword}" -k --dump-header /tmp/headers.txt --cookie /tmp/cookie.txt --cookie-jar /tmp/cookie.txt "${adminInterfaceApiUrl}/login"
csrfToken=$(cat /tmp/headers.txt | grep -i X-CSRF-TOKEN: | cut -c15- | tr -d '\n' | tr -d '\r' )
echo "Uploading the Delft-FEWS Config zip"
echo "Message length: $(echo -n "${commentText}" | wc -c)"
echo "${commentText}"
result=$(curl -s --fail --max-time 6000 -k -H "X-CSRF-TOKEN: ${csrfToken}" --cookie /tmp/cookie.txt -F "description=$commentText" -F file=@./config.zip "${adminInterfaceApiUrl}/configmanagement/fewsconfig")
status=$?
curl --cookie /tmp/cookie.txt -k "${adminInterfaceApiUrl}/logout"
echo "$result"
# Check if the errors array is not empty
[ $status -ne 0 ] && echo "Upload of the Delft-FEWS Config zip failed with status ${status} and message ${result}" && exit $status
if echo "$result" | jq '.errors | length == 0' | grep -q true; then
echo "Upload was succesful."
else
echo "Errors detected in response."
exit 1
fi
rm -rf /tmp/cookie.txt /tmp/headers.txt
shell: bash