-
Notifications
You must be signed in to change notification settings - Fork 11
126 lines (107 loc) · 4.05 KB
/
icon-add.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: icon-add
on:
push:
branches:
- main
paths:
- 'packages/core/src/raw-svgs/**'
pull_request:
branches:
- main
paths:
- 'packages/core/src/raw-svgs/**'
jobs:
update-and-rebuild:
runs-on: ubuntu-latest
steps:
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 10
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: bun install
- name: Identify New SVG Files
id: files
run: |
SVG_FILES=$(git diff --name-only HEAD^ HEAD | grep 'packages/core/src/raw-svgs/' | tr '\n' ',')
echo "SVG_FILES=${SVG_FILES%,}" >> $GITHUB_ENV
echo "New SVG Files: $SVG_FILES"
echo "New Token Icons: $newTokenIcons"
echo "New Network Icons: $newNetworkIcons"
- name: Validate New SVG Files
if: env.SVG_FILES
run: bun run ./packages/utils/src/scripts/validate-svgs.ts ${{ env.SVG_FILES }}
- name: Update Metadata
if: env.SVG_FILES
run: |
newTokenIcons=$(git diff --name-only HEAD^ HEAD | grep 'packages/core/src/raw-svgs/tokens/' | xargs basename -a | sed 's/.svg//' | sort -u | tr '\n' ', ' | sed 's/, $//')
newNetworkIcons=$(git diff --name-only HEAD^ HEAD | grep 'packages/core/src/raw-svgs/networks/' | xargs basename -a | sed 's/.svg//' | sort -u | tr '\n' ', ' | sed 's/, $//')
echo "newTokenIcons=$newTokenIcons" >> $GITHUB_ENV
echo "newNetworkIcons=$newNetworkIcons" >> $GITHUB_ENV
bun run ./packages/utils/src/scripts/update-metadata.ts ${{ env.SVG_FILES }}
- name: Create Changeset
run: |
if [ -n "$newTokenIcons" ] || [ -n "$newNetworkIcons" ]; then
changesetContent="---
\"@token-icons/core\": minor
\"@token-icons/react\": minor
---
"
[ -n "$newTokenIcons" ] && changesetContent+="New Token icons: $newTokenIcons\n"
[ -n "$newNetworkIcons" ] && changesetContent+="New Network icons: $newNetworkIcons\n"
echo "$changesetContent" > .changeset/$(date +%s).md
fi
bun changeset version
- name: Build Packages
run: |
bun run build:core
bun run build:react
- name: Commit Changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
commitMessage=""
description=""
if [ -n "$newTokenIcons" ] && [ -n "$newNetworkIcons" ]; then
commitMessage="core: add new token icons & network icons"
description+="token icons: $newTokenIcons\nnetwork icons: $newNetworkIcons"
elif [ -n "$newTokenIcons" ]; then
commitMessage="core: add new token icons"
description+="token icons: $newTokenIcons"
elif [ -n "$newNetworkIcons" ]; then
commitMessage="core: add new network icons"
description+="network icons: $newNetworkIcons"
fi
if [ -n "$description" ]; then
git commit -m "$commitMessage" -m "$description" || echo "No changes to commit"
else
echo "No new icons to commit"
fi
git push origin ${GITHUB_HEAD_REF:-${GITHUB_REF}}
publish:
needs: update-and-rebuild
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: bun install
- name: Publish to npm
run: bun changeset publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}