Add GitHub Actions workflow to sync icons to CDN (#1435)

Introduces a workflow that syncs the 'icons' directory to a dedicated 'icons' branch and creates a versioned tag on each update. The workflow triggers on changes to the 'icons' folder in the main branch or via manual dispatch, and outputs CDN URLs for accessing the synced icons.
This commit is contained in:
Abdul-Kadir Coskun 2025-12-14 23:00:37 +11:00 committed by GitHub
parent a6b1937fa3
commit 48280d7eb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 105 additions and 0 deletions

105
.github/workflows/sync-icons.yml vendored Normal file
View File

@ -0,0 +1,105 @@
name: Sync Icons to CDN
on:
push:
branches:
- main
paths:
- 'icons/**'
workflow_dispatch:
jobs:
sync-icons:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync icons and create release tag
id: sync
run: |
CDN_BRANCH="icons"
SOURCE_FOLDER="icons"
if [ ! -d "$SOURCE_FOLDER" ]; then
echo "No $SOURCE_FOLDER folder found"
exit 0
fi
# Get version from package.json
VERSION=$(node -p "require('./package.json').version")
VERSION_TAG="icons-v${VERSION}"
echo "Package version: $VERSION"
echo "Tag: $VERSION_TAG"
# Check if tag already exists
if git ls-remote --tags origin | grep -q "refs/tags/${VERSION_TAG}$"; then
echo "Tag $VERSION_TAG already exists, skipping"
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
# Store icons in temp location
mkdir -p /tmp/icons-sync
cp -r $SOURCE_FOLDER/* /tmp/icons-sync/
MAIN_SHA=$(git rev-parse --short HEAD)
# Setup CDN branch
if git ls-remote --heads origin $CDN_BRANCH | grep -q $CDN_BRANCH; then
git checkout $CDN_BRANCH
find . -maxdepth 1 ! -name '.git' ! -name '.' -exec rm -rf {} +
else
git checkout --orphan $CDN_BRANCH
git rm -rf .
fi
# Copy icons to root
cp -r /tmp/icons-sync/* .
git add -A
if git diff --staged --quiet; then
echo "No changes to sync"
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
git commit -m "v${VERSION}"
git push -u origin $CDN_BRANCH --force-with-lease
# Create versioned tag
git tag $VERSION_TAG
git push origin $VERSION_TAG
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "version_tag=$VERSION_TAG" >> $GITHUB_OUTPUT
- name: Output CDN URLs
if: steps.sync.outputs.has_changes == 'true'
run: |
REPO="${{ github.repository }}"
TAG="${{ steps.sync.outputs.version_tag }}"
echo "═══════════════════════════════════════════════════════════"
echo " CDN URLs"
echo "═══════════════════════════════════════════════════════════"
echo ""
echo " https://cdn.jsdelivr.net/gh/${REPO}@${TAG}/<filename>"
echo ""
echo " Browse: https://cdn.jsdelivr.net/gh/${REPO}@${TAG}/"
echo ""
echo "═══════════════════════════════════════════════════════════"