forked from tabler/tabler-icons
-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (83 loc) · 3.28 KB
/
sync-icons.yml
File metadata and controls
105 lines (83 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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@v5
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 "═══════════════════════════════════════════════════════════"