Skip to content

更新文档,增强主题描述,修正许可证信息为AGPL v3,并新增主题变体说明 #4

更新文档,增强主题描述,修正许可证信息为AGPL v3,并新增主题变体说明

更新文档,增强主题描述,修正许可证信息为AGPL v3,并新增主题变体说明 #4

name: Sync Theme to READMEs
on:
push:
paths:
- "themes/maple-neon.css"
branches:
- main
- master
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Update README files
run: |
#!/bin/bash
set -e
# Read CSS content from the theme file
if [[ ! -f "themes/maple-neon.css" ]]; then
echo "Error: themes/maple-neon.css not found"
exit 1
fi
CSS_CONTENT=$(cat themes/maple-neon.css)
# Function to update a single README file
update_readme() {
local file=$1
echo "Processing $file..."
if [[ ! -f "$file" ]]; then
echo "Warning: $file not found, skipping..."
return 1
fi
# Create a temporary file for the new content
local temp_file=$(mktemp)
local in_css_block=false
local changes_made=false
local found_css_block=false
while IFS= read -r line || [[ -n "$line" ]]; do
if [[ "$line" == '```css' ]]; then
echo "$line" >> "$temp_file"
echo "$CSS_CONTENT" >> "$temp_file"
in_css_block=true
found_css_block=true
changes_made=true
elif [[ "$line" == '```' ]] && [[ "$in_css_block" == true ]]; then
echo "$line" >> "$temp_file"
in_css_block=false
elif [[ "$in_css_block" == false ]]; then
echo "$line" >> "$temp_file"
fi
# Skip lines inside CSS block (between ```css and ```)
done < "$file"
# Replace the original file if changes were made
if [[ "$changes_made" == true ]]; then
mv "$temp_file" "$file"
echo "✓ Updated CSS block in $file"
return 0
else
rm -f "$temp_file"
if [[ "$found_css_block" == false ]]; then
echo "- No CSS block found in $file"
else
echo "- No changes needed in $file"
fi
return 1
fi
}
# Track if any files were updated
files_updated=false
# List of README files to update
readme_files=(
"README.md"
"docs/README.zh.md"
"docs/README.fr.md"
"docs/README.ja.md"
)
# Update all README files
for readme in "${readme_files[@]}"; do
if update_readme "$readme"; then
files_updated=true
fi
done
# Set output for next step
if [[ "$files_updated" == true ]]; then
echo "FILES_UPDATED=true" >> $GITHUB_ENV
else
echo "FILES_UPDATED=false" >> $GITHUB_ENV
fi
- name: Check for changes
id: git-check
run: |
# Check if there are any changes in git
if git diff --quiet && git diff --cached --quiet; then
echo "No changes detected"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
else
echo "Changes detected"
echo "HAS_CHANGES=true" >> $GITHUB_ENV
# Show what changed
echo "Changed files:"
git diff --name-only
git diff --cached --name-only
fi
- name: Configure Git
if: env.HAS_CHANGES == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Commit and push changes
if: env.HAS_CHANGES == 'true'
run: |
# Add all modified README files
git add README.md docs/README.*.md 2>/dev/null || true
# Check if there are staged changes
if git diff --cached --quiet; then
echo "No staged changes to commit"
exit 0
fi
# Commit changes
git commit -m "docs: sync CSS content from maple-neon.css to README files [skip ci]"
# Push changes
git push origin ${{ github.ref_name }}
echo "✅ Successfully synced CSS content to README files"