-
Notifications
You must be signed in to change notification settings - Fork 14
174 lines (153 loc) · 6.96 KB
/
fetch-icons.yaml
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
###
#
# Regularly create a pull request with up-to-date icons
#
# This workflow has access to secrets and
# therefore will not run from a fork.
#
###
name: Fetch Icons
on:
workflow_dispatch:
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
- cron: '0 0 * * 0' # the job will run every Sunday at 0:00
jobs:
fetch:
runs-on: ubuntu-latest
if: github.repository_owner == 'swisspost'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup
uses: ./.github/actions/setup-pnpm
- name: Get Date
id: current-date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Create Branch
id: current-branch
run: |
git checkout -b $BRANCH_NAME origin/release/v8
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
env:
BRANCH_NAME: ${{ steps.current-date.outputs.date }}-update-icons
- name: Install icons & dependencies
run: pnpm --filter design-system-icons... --filter design-system-styles... install
- name: Fetch Icons
run: pnpm --filter design-system-icons fetchSVGs
env:
CEN_USERNAME: ${{ secrets.CEN_USERNAME }}
CEN_PASSWORD: ${{ secrets.CEN_PASSWORD }}
CEN_URL: ${{ secrets.CEN_URL }}
- name: Build styles
run: pnpm --filter design-system-styles... build
- 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 .
git commit -am "chore(icons): update icon SVGs"
git push -u origin ${{ steps.current-branch.outputs.branch }}
- name: Get Changes
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: ./packages/icons/public/post-icons/**
- name: Exit if no changes
if: steps.changed-files.outputs.any_modified == 'false'
run: |
git checkout main
git push origin --delete ${{ steps.current-branch.outputs.branch }}
- name: Get Changed Icons
id: changed-icons
if: steps.changed-files.outputs.any_modified != 'false'
run: |
get_icons() {
# takes the list of icon file paths
# replaces paths to keep the icon numbers only
# separates with commas and replace the last one with "and"
echo $@ | sed 's/[^ ]*\/\([[:digit:]]*\)\.svg/\1/g' | sed 's/ /, /g' | sed 's/\(.*\),/\1 and/g'
}
echo "updated_icons=$(get_icons $MODIFIED_FILES $RENAMED_FILES $COPIED_FILES)" >> $GITHUB_OUTPUT
echo "added_icons=$(get_icons $ADDED_FILES)" >> $GITHUB_OUTPUT
echo "deleted_icons=$(get_icons $DELETED_FILES)" >> $GITHUB_OUTPUT
env:
ADDED_FILES: ${{ steps.changed-files.outputs.added_files }}
MODIFIED_FILES: ${{ steps.changed-files.outputs.modified_files }}
RENAMED_FILES: ${{ steps.changed-files.outputs.renamed_files }}
COPIED_FILES: ${{ steps.changed-files.outputs.copied_files }}
DELETED_FILES: ${{ steps.changed-files.outputs.deleted_files }}
- name: Create Changeset
if: steps.changed-files.outputs.any_modified != 'false'
run: |
pluralize_if_needed() {
# adds an "s" only if there are multiple arguments
echo $([ $# = 1 ] && echo "" || echo "s")
}
declare -a bump
declare -a description
if [[ -n $UPDATED_ICONS ]]; then
bump="patch"
description+="Updated icon$(pluralize_if_needed $UPDATED_ICONS) number ${UPDATED_ICONS}. "
fi
if [[ -n $ADDED_ICONS ]]; then
bump="minor"
description+="Added icon$(pluralize_if_needed $ADDED_ICONS) number ${ADDED_ICONS}. "
fi
if [[ -n $DELETED_ICONS ]]; then
bump="major"
description+="Deleted icon$(pluralize_if_needed $DELETED_ICONS) number ${DELETED_ICONS}. "
fi
echo --- > $CHANGESET
echo "'@swisspost/design-system-icons': ${bump}" >> $CHANGESET
echo --- >> $CHANGESET
echo >> $CHANGESET
echo "${description[@]}" | xargs >> $CHANGESET
echo >> $CHANGESET
env:
CHANGESET: ./.changeset/${{ steps.current-branch.outputs.branch }}.md
UPDATED_ICONS: ${{ steps.changed-icons.outputs.updated_icons }}
ADDED_ICONS: ${{ steps.changed-icons.outputs.added_icons }}
DELETED_ICONS: ${{ steps.changed-icons.outputs.deleted_icons }}
- name: Commit Changeset
if: steps.changed-files.outputs.any_modified != 'false'
run: |
git add .
git commit -am "chore(icons): add changeset"
git push -u origin ${{ steps.current-branch.outputs.branch }}
- name: Write PR Body
id: pr-body
if: steps.changed-files.outputs.any_modified != 'false'
run: |
echo "file=$PR_BODY_FILE" >> $GITHUB_OUTPUT
echo "# Design system icons are now up to date!" > $PR_BODY_FILE
if [[ -n $UPDATED_ICONS ]]; then
echo "## Updated icons" >> $PR_BODY_FILE
echo $UPDATED_ICONS >> $PR_BODY_FILE
fi
if [[ -n $ADDED_ICONS ]]; then
echo "## Added icons" >> $PR_BODY_FILE
echo $ADDED_ICONS >> $PR_BODY_FILE
fi
if [[ -n $DELETED_ICONS ]]; then
echo "## Deleted icons" >> $PR_BODY_FILE
echo $DELETED_ICONS >> $PR_BODY_FILE
fi
env:
PR_BODY_FILE: pr-body.md
UPDATED_ICONS: ${{ steps.changed-icons.outputs.updated_icons }}
ADDED_ICONS: ${{ steps.changed-icons.outputs.added_icons }}
DELETED_ICONS: ${{ steps.changed-icons.outputs.deleted_icons }}
- name: Create PR
if: steps.changed-files.outputs.any_modified != 'false'
run: |
gh pr create --title "chore(icons): :point_up: update icons" --body-file ${{ steps.pr-body.outputs.file }} --base origin/release/v8
env:
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}