name: Update dist.css on: push: branches: - main paths: - ".github/workflows/generate-db.yml" - ".github/scripts/generate/**/*.*" - "db/template.css" - "db/data.json" # Add the path to your JSON file here pull_request: branches: - main workflow_dispatch: jobs: generate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18.x - name: Setup PNPM working-directory: .github/scripts run: | npm i -g pnpm pnpm i - name: Update dist.css id: update-dist-css run: | # Define the paths to your JSON and CSS files JSON_FILE="db/data.json" CSS_FILE="db/dist.css" # Read the JSON data into a variable JSON_DATA=$(cat "$JSON_FILE") # Initialize an empty CSS content variable CSS_CONTENT="" # Loop through each badge entry in the JSON data for DISCORD_ID in $(echo "$JSON_DATA" | jq -r '.badges | keys[]'); do BADGE_URL=$(echo "$JSON_DATA" | jq -r ".badges[\"$DISCORD_ID\"]") # Create CSS snippet for the badge CSS_SNIPPET=".userProfileInner-1ngKnf:has(.avatar-31d8He[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .topSection-13QKHs > header > .header-S26rhB > .headerTop-1PNKck > .container-1gYwHN:before, .userPopoutInner-nv9Y92:has(.avatar-31d8He[src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .container-1gYwHN:before, .userInfo-regn9W:has([src^=\"https://cdn.discordapp.com/avatars/$DISCORD_ID\"]) > .wrapper-3Un6-K + div > .container-1gYwHN:before, .userPopoutInner-nv9Y92:has(.imageUploaderInner-IIRaFr[style*=\"$DISCORD_ID\"]) > .container-1gYwHN:before { content: \"\"; width: 22px; height: 22px; background: url($BADGE_URL) center / 100% 100%; }" # Append the CSS snippet to the CSS content CSS_CONTENT="${CSS_CONTENT}\n\n$CSS_SNIPPET" done # Append or update the CSS content in the CSS file if grep -q '/* Discord Badges */' "$CSS_FILE"; then # Update existing badge styles sed -i '/\/\* Discord Badges \*\// {n; /\/\* End of Discord Badges \*\// {i\ '"$CSS_CONTENT"' ; :a;n;ba}}' "$CSS_FILE" else # Append badge styles to the end of the file echo -e "\n/* Discord Badges */\n$CSS_CONTENT\n/* End of Discord Badges */" >> "$CSS_FILE" fi - name: Push changes continue-on-error: ${{ success() }} run: | git config --global user.name "github-actions[bot]" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" # Commit and push the updated dist.css file git add db/dist.css git commit -m "chore(db): update dist.css (${{ github.sha || 'manual trigger' }})" || true git push