2022-11-03 14:27:23 -07:00
|
|
|
name: HyperTuner INI upload
|
|
|
|
description: GitHub Action for INI upload.
|
|
|
|
author: Piotr Rogowski <piotr.rogowski0@gmail.com>
|
|
|
|
branding:
|
|
|
|
icon: cpu
|
|
|
|
color: blue
|
|
|
|
inputs:
|
|
|
|
api-url:
|
|
|
|
description: 'HyperTuner API URL'
|
|
|
|
required: true
|
|
|
|
username:
|
|
|
|
description: 'HyperTuner admin username'
|
|
|
|
required: true
|
|
|
|
|
|
|
|
password:
|
|
|
|
description: 'HyperTuner admin password'
|
|
|
|
required: true
|
|
|
|
|
|
|
|
path:
|
|
|
|
description: 'Path to INI file'
|
|
|
|
required: true
|
|
|
|
|
|
|
|
ecosystem:
|
|
|
|
description: 'Either "speeduino" or "rusefi"'
|
|
|
|
required: true
|
|
|
|
|
|
|
|
runs:
|
|
|
|
using: composite
|
|
|
|
steps:
|
|
|
|
- name: Upload
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
API_URL=${{ inputs.api-url }}
|
|
|
|
USERNAME=${{ inputs.username }}
|
|
|
|
PASSWORD=${{ inputs.password }}
|
|
|
|
INI_PATH=${{ inputs.path }}
|
|
|
|
ECOSYSTEM=${{ inputs.ecosystem }}
|
|
|
|
|
|
|
|
upload_url="${API_URL}/api/collections/iniFiles/records"
|
|
|
|
auth_url="${API_URL}/api/admins/auth-with-password"
|
|
|
|
|
|
|
|
echo "Parsing signature..."
|
|
|
|
|
2023-05-15 16:15:46 -07:00
|
|
|
signature=$(awk -F "=" '/signature/ {print $2}' ${INI_PATH} | tr -d '"' | cut -f1 -d";" | xargs)
|
2022-11-03 14:27:23 -07:00
|
|
|
|
|
|
|
echo "Signature: ${signature}"
|
|
|
|
|
|
|
|
echo "Compressing..."
|
|
|
|
|
2022-11-03 14:48:40 -07:00
|
|
|
filename="gzipped/${signature// /_}.ini"
|
|
|
|
|
2022-11-03 14:27:23 -07:00
|
|
|
mkdir gzipped
|
|
|
|
gzip --best --keep ${INI_PATH}
|
2022-11-03 14:48:40 -07:00
|
|
|
mv ${INI_PATH}.gz ${filename}
|
2022-11-03 14:27:23 -07:00
|
|
|
|
|
|
|
echo "Authenticating..."
|
|
|
|
|
2022-11-03 15:48:37 -07:00
|
|
|
token=$(curl --silent \
|
|
|
|
$auth_url \
|
|
|
|
--header 'Content-Type: application/json' \
|
|
|
|
--data-raw "{\"identity\": \"${USERNAME}\", \"password\": \"${PASSWORD}\"}" | jq -r '.token')
|
2022-11-03 14:27:23 -07:00
|
|
|
|
|
|
|
echo "Checking if file already exists..."
|
|
|
|
|
2022-11-03 15:48:37 -07:00
|
|
|
response=$(curl --silent \
|
|
|
|
$upload_url \
|
|
|
|
--get \
|
|
|
|
--header "Authorization: Bearer ${token}" \
|
|
|
|
--data-urlencode "filter=signature=\"${signature}\"")
|
2022-11-03 14:27:23 -07:00
|
|
|
|
|
|
|
found=$(echo $response | jq '.totalItems')
|
|
|
|
|
|
|
|
if [[ $found == 0 ]]; then
|
|
|
|
echo "Not found"
|
|
|
|
echo "Trying to create a new record..."
|
|
|
|
|
2022-11-03 15:48:37 -07:00
|
|
|
response=$(curl --silent \
|
|
|
|
$upload_url \
|
|
|
|
--request POST \
|
|
|
|
--header "Authorization: Bearer ${token}" \
|
|
|
|
--form "signature=\"${signature}\"" \
|
|
|
|
--form "ecosystem=\"${ECOSYSTEM}\"" \
|
|
|
|
--form file=@"${filename}")
|
2022-11-03 14:27:23 -07:00
|
|
|
else
|
|
|
|
echo "Record already exists, trying to update..."
|
|
|
|
id=$(echo $response | jq -r '.items[0].id')
|
|
|
|
|
2022-11-03 15:48:37 -07:00
|
|
|
response=$(curl --silent \
|
|
|
|
${upload_url}/${id} \
|
|
|
|
--request PATCH \
|
|
|
|
--header "Authorization: Bearer ${token}" \
|
|
|
|
--form "signature=\"${signature}\"" \
|
|
|
|
--form "ecosystem=\"${ECOSYSTEM}\"" \
|
|
|
|
--form file=@"${filename}")
|
2022-11-03 14:27:23 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
error=$(echo $response | jq -r '.code')
|
|
|
|
|
|
|
|
if [ -z "$error" ]
|
|
|
|
then
|
|
|
|
echo "Error: $response"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Success"
|
|
|
|
exit 0
|
|
|
|
fi
|