Skip to content

Update sync.yml

Update sync.yml #10

Workflow file for this run

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 }}
REPO_URL: ${{ github.repository }}
COMMIT_HASH: ${{ github.sha }}
run: |
set -e
# Initialize an empty array for the settings
all_settings="[]"
process_directory() {
local branch="$1"
echo "Processing settings for branch: $branch"
for file in "LiquidBounce/settings/$branch"/*; do
if [ -f "$file" ]; then
setting_id=$(basename "$file" | cut -f 1 -d '.')
raw_url="https://raw.githubusercontent.com/${REPO_URL}/${COMMIT_HASH}/${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")
# Append the new setting to the all_settings array
all_settings=$(echo "$all_settings" | jq --arg name "$setting_id" \
--arg branch "$branch" \
--arg url "$raw_url" \
--arg checksum "$checksum" \
--arg timestamp "$timestamp" \
--arg contributors "$contributors" \
'. += [{
"name": $name,
"branch": $branch,
"url": $url,
"checksum": $checksum,
"timestamp": $timestamp,
"contributors": $contributors
}]')
fi
done
}
# Process both branches in one go and add the settings to the combined array
for branch in legacy nextgen; do
process_directory "$branch"
done
# Write the combined settings to a file
echo "$all_settings" > combined-settings.json
# Upload the combined settings for both branches
echo "Uploading combined settings"
curl --fail -X POST \
-H "Authorization: $AUTHORIZATION" \
-H "Content-Type: application/json" \
-d @"combined-settings.json" \
"https://api-testing.liquidbounce.net/api/v3/marketplace/sync" \
&& echo "Combined settings successfully uploaded" \
|| (echo "Failed to upload combined settings" && exit 1)
- name: Upload JSON Files to Artifacts
uses: actions/upload-artifact@v4
with:
name: settings-payloads
path: 'combined-settings.json'