Update sync.yml #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync settings | |
on: | |
push: | |
branches: | |
- '**' | |
jobs: | |
upload_settings: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Process and Upload Settings | |
id: process_and_upload | |
env: | |
AUTHORIZATION: ${{ secrets.AUTHORIZATION }} | |
run: | | |
set -e | |
process_directory() { | |
local branch="$1" | |
local safe_branch_name=$(echo "$branch" | tr '/' '-') | |
echo "Processing settings for branch: $branch" | |
echo "[]" > "${safe_branch_name}-settings.json" | |
for file in "LiquidBounce/settings/$branch"/*; do | |
if [ -f "$file" ]; then | |
setting_id=$(basename "$file" | cut -f 1 -d '.') | |
data=$(base64 -w 0 "$file") | |
checksum=$(sha256sum "$file" | cut -d ' ' -f 1) | |
timestamp=$(git log -1 --format=%ai -- "$file" | cut -d ' ' -f 1,2 | tr ' ' 'T')Z | |
contributors=$(git log -1 --format='%an <%ae>' -- "$file") | |
jq --arg name "$setting_id" \ | |
--arg data "$data" \ | |
--arg checksum "$checksum" \ | |
--arg timestamp "$timestamp" \ | |
--arg contributors "$contributors" \ | |
'. += [{ | |
"name": $name, | |
"data": $data, | |
"checksum": $checksum, | |
"timestamp": $timestamp, | |
"contributors": $contributors | |
}]' "${safe_branch_name}-settings.json" > temp.json && mv temp.json "${safe_branch_name}-settings.json" | |
fi | |
done | |
} | |
upload_settings() { | |
local branch="$1" | |
local safe_branch_name=$(echo "$branch" | tr '/' '-') | |
settings_file="${safe_branch_name}-settings.json" | |
if [ -s "$settings_file" ]; then | |
echo "Uploading settings for branch: $branch" | |
response=$(curl -s -w "%{http_code}" -o /tmp/curl_output \ | |
-X POST \ | |
-H "Authorization: $AUTHORIZATION" \ | |
-H "Content-Type: application/json" \ | |
-d @"$settings_file" \ | |
"https://api-testing.liquidbounce.net/api/v1/client/$branch/settings/sync") | |
if [ "$response" -eq 200 ] || [ "$response" -eq 204 ]; then | |
echo "Settings successfully uploaded for branch: $branch" | |
else | |
echo "Failed to upload settings for branch: $branch" | |
echo "HTTP Status Code: $response" | |
echo "Response Body:" | |
cat /tmp/curl_output | |
exit 1 | |
fi | |
else | |
echo "No settings to upload for branch: $branch" | |
fi | |
} | |
find "LiquidBounce/settings" -mindepth 1 -maxdepth 1 -type d | while read -r dir; do | |
branch=$(basename "$dir") | |
process_directory "$branch" | |
upload_settings "$branch" | |
done | |
- name: Upload JSON Files to Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: settings-payloads | |
path: '*-settings.json' |