-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
106 lines (85 loc) · 2.94 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: HyperTuner INI upload
description: GitHub Action for INI upload.
author: Piotr Rogowski <[email protected]>
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..."
signature=$(awk -F "=" '/signature/ {print $2}' ${INI_PATH} | tr -d '"' | cut -f1 -d";" | xargs)
echo "Signature: ${signature}"
echo "Compressing..."
filename="gzipped/${signature// /_}.ini"
mkdir gzipped
gzip --best --keep ${INI_PATH}
mv ${INI_PATH}.gz ${filename}
echo "Authenticating..."
token=$(curl --silent \
$auth_url \
--header 'Content-Type: application/json' \
--data-raw "{\"identity\": \"${USERNAME}\", \"password\": \"${PASSWORD}\"}" | jq -r '.token')
echo "Checking if file already exists..."
response=$(curl --silent \
$upload_url \
--get \
--header "Authorization: Bearer ${token}" \
--data-urlencode "filter=signature=\"${signature}\"")
found=$(echo $response | jq '.totalItems')
if [[ $found == 0 ]]; then
echo "Not found"
echo "Trying to create a new record..."
response=$(curl --silent \
$upload_url \
--request POST \
--header "Authorization: Bearer ${token}" \
--form "signature=\"${signature}\"" \
--form "ecosystem=\"${ECOSYSTEM}\"" \
--form file=@"${filename}")
else
echo "Record already exists, trying to update..."
id=$(echo $response | jq -r '.items[0].id')
response=$(curl --silent \
${upload_url}/${id} \
--request PATCH \
--header "Authorization: Bearer ${token}" \
--form "signature=\"${signature}\"" \
--form "ecosystem=\"${ECOSYSTEM}\"" \
--form file=@"${filename}")
fi
error=$(echo $response | jq -r '.code')
if [ -z "$error" ]
then
echo "Error: $response"
exit 1
else
echo "Success"
exit 0
fi