-
Notifications
You must be signed in to change notification settings - Fork 58
107 lines (87 loc) · 3.33 KB
/
convert.yml
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
106
107
name: Convert to ico
on:
# push:
# branches: [main]
# pull_request:
# branches: [main]
workflow_dispatch:
branches: [main]
jobs:
convert:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v2
with:
path: svg
- name: Checkout ico repo
uses: actions/checkout@v2
with:
path: ico
token: ${{ secrets.ACTION_TOKEN }}
repository: icon11-community/Folder11-ico
- name: Convert
run: |
svg_repo="./svg"
ico_repo="./ico"
input_path="$svg_repo/svg"
output_path="$ico_repo/ico"
output_hash_path="$ico_repo/hash"
temp_path="./temp"
changed=false
install_dependencies() {
if [[ "$changed" != "true" ]]; then
npm i -g svgexport
fi
}
mkdir -p "$temp_path"
mkdir -p "$input_path"
mkdir -p "$output_path"
mkdir -p "$output_hash_path"
for i in $(ls "$input_path" | grep '\.svg$'); do
name="$(echo $i | sed -E 's/^(.+)\.svg$/\1/')"
hash="$(git -C "$svg_repo" hash-object ".github/workflows/convert.yml")"
input_name="$input_path/$name.svg"
temp_name="$temp_path/$name.png"
output_name="$output_path/$name.ico"
output_hash_name="$output_hash_path/$name.ico"
echo "Converting $name..."
if [[ -f "$output_name" && -f "$output_hash_name" && "$hash" == "$(cat $output_hash_name)" ]]; then
echo "$name is already exist."
continue
fi
install_dependencies
changed=true
[[ -f "$output_name" ]] && rm "$output_name"
[[ -f "$output_hash_name" ]] && rm "$output_hash_name"
svgexport "$input_name" "$temp_name" png 1024:1024
convert -background transparent "$temp_name" -define icon:auto-resize="256,128,96,64,48,32,16" "$output_name"
echo "$hash" >$output_hash_name
echo "$name successfully converted."
done
for name in $(echo $(ls "$output_path") $(ls "$output_hash_name") | grep -E '\.ico$' | sed -E 's/^(.*)\.ico$/\1/' | uniq); do
input_name="$input_path/$name.svg"
output_name="$output_path/$name.ico"
output_hash_name="$output_hash_path/$name.ico"
if [[ ! -f "$input_name" ]]; then
echo "Removing $name..."
[[ -f "$output_name" ]] && rm "$output_name"
[[ -f "$output_hash_name" ]] && rm "$output_hash_name"
fi
done
echo "Cleaning temp..."
rm -rf "$temp_path"
if [[ "$changed" == 'true' ]]; then
echo "Push changes..."
commit_name="gen: $(git -C "$svg_repo" show -q | grep "commit" | awk '{print $2}')"
echo "$commit_name"
git -C "$ico_repo" config user.name github-actions
git -C "$ico_repo" config user.email github-actions@github.com
echo test config
git -C "$ico_repo" add .
echo test add
git -C "$ico_repo" commit -m "$commit_name"
echo test commit
git -C "$ico_repo" push
echo test commit
fi