-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add a Github Action to automatically generate and update sounds.j…
…son (#31)
- Loading branch information
1 parent
6fcfd5a
commit 34ab39c
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Generate sounds.json | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request_target: | ||
types: [opened, synchronize, reopened, ready_for_review] | ||
merge_group: | ||
branches: [main, development] | ||
|
||
jobs: | ||
generate-sounds: | ||
if: '!github.event.pull_request.draft' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout the Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 | ||
|
||
- name: Generate sounds.json | ||
run: | | ||
chmod +x ./utils/process_sounds.sh | ||
./utils/process_sounds.sh ./src/main/resources/assets/wynnvp/sounds.json | ||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_user_name: 'VoWBot' | ||
commit_user_email: '[email protected]' | ||
commit_message: 'ci: generate sounds.json' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/sh | ||
|
||
# This script processes the sound_info.json file and creates a sounds.json file, | ||
# which is used by Minecraft to load and play sounds. | ||
|
||
# Check if the sound_info.json file is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 path/to/sound_info.json" | ||
exit 1 | ||
fi | ||
|
||
sound_info_file=$1 | ||
|
||
# Check if the provided file exists | ||
if [ ! -f "$sound_info_file" ]; then | ||
echo "File not found: $sound_info_file" | ||
exit 1 | ||
fi | ||
|
||
# Get the directory of the provided sound_info.json file | ||
sound_info_dir=$(dirname "$sound_info_file") | ||
|
||
# Define the output sounds.json file path | ||
sounds_json_file="$sound_info_dir/sounds.json" | ||
|
||
# Process the sound_info.json file and create the sounds.json file | ||
# NOTE: This script can only generate the fileOverride field for the sounds.json file, | ||
# if the NPC name and line info are provided in the sound_info.json file. | ||
# If either of these data is not available, the script fails. Use a unique fileOverride value for these cases. | ||
jq '[ | ||
.content | to_entries | map( | ||
.key as $content | .value.contexts | to_entries | map( | ||
.key as $context | .value.dialogues | map( | ||
.fileOverride as $fileOverride | | ||
{ | ||
"fileName": ($fileOverride // ( | ||
($content | gsub("[^a-zA-Z0-9]"; "") | ascii_downcase) + "-" + | ||
($context | gsub("[^a-zA-Z0-9]"; "") | ascii_downcase) + "-" + | ||
(.lineInfo.npc | gsub("[^a-zA-Z0-9]"; "") | ascii_downcase) + "-" + | ||
(.lineInfo.line.current | tostring) | ||
)) | ||
} | { | ||
(.fileName): { | ||
"category": "voice", | ||
"sounds": [ | ||
{ | ||
"name": "wynnvp:\(.fileName)", | ||
"stream": true | ||
} | ||
] | ||
} | ||
} | ||
) | ||
) | ||
) | flatten | add | ||
] | add | to_entries | sort_by(.key) | from_entries' "$sound_info_file" > "$sounds_json_file" | ||
|
||
# Check if the sounds.json file was created successfully | ||
if [ $? -eq 0 ]; then | ||
echo "sounds.json file has been created successfully at $sounds_json_file" | ||
else | ||
echo "An error occurred while creating the sounds.json file" | ||
exit 1 | ||
fi |