Merge pull request #6 from Yugveer06/main #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: Consolidate JSON Files | |
on: | |
push: | |
paths: | |
- "public/data/**" | |
permissions: | |
contents: write | |
jobs: | |
consolidate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install jq (for JSON manipulation) | |
run: sudo apt-get install -y jq | |
- name: Consolidate JSON files | |
run: | | |
mkdir -p public/consolidated | |
echo "[" > public/consolidated/all_snippets.json | |
find public/data -name "*.json" ! -name "_index.json" -exec sh -c ' | |
for file; do | |
jq -c ".[]" "$file" | \ | |
sed "s/^/{\"language\": \"$(basename "$file" .json)\", /" | \ | |
sed "s/}$/}/" >> public/consolidated/all_snippets.json | |
done | |
' _ {} + | |
sed -i '$ s/,$//' public/consolidated/all_snippets.json | |
echo "]" >> public/consolidated/all_snippets.json | |
- name: Commit and push changes | |
run: | | |
git config --global user.name "GitHub Action" | |
git config --global user.email "action@github.com" | |
git add public/consolidated/all_snippets.json | |
git commit -m "Update consolidated snippets" | |
git push |