image: nyxonite89/javafx:latest


build:
    script:
        - mvn package -B
        
release:
    script:
        - mvn package -B
        - FILE=$(ls target/ | grep '\.zip$' | head -n 1)
        - echo ${FILE}
        - echo ${CI_PROJECT_ID}
        - echo ${CI_COMMIT_TAG}
        - echo ${CI_API_V4_URL}
        - echo ${CI_PROJECT_URL}
        - 'UPLOAD_RESULT=$(curl --request POST --header "Private-Token: ${TOKEN}" --form "file=@target/${FILE}" ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/uploads)'
        - echo ${UPLOAD_RESULT}
        - FILE_URL=$(echo ${UPLOAD_RESULT} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["url"]')
        - echo ${FILE_URL}
        - 'DATA="{\"name\": \"Release ${CI_COMMIT_TAG}\", \"tag_name\": \"${CI_COMMIT_TAG}\", \"description\": \"RegionChooser Release\", \"assets\": { \"links\": [{ \"name\": \"${FILE}\", \"url\": \"${CI_PROJECT_URL}${FILE_URL}\"}] } }"'
        - echo ${DATA}
        - 'curl --header "Content-Type: application/json" --header "Private-Token: ${TOKEN}" --data "${DATA}" --request POST ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases'
    only:
        refs:
            - tags
        
