Skip to content

Commit ce58fe6

Browse files
committed
ci(primitives): transition to new css primitives
GitHub no longer distributes primitives in JSON format. Also, the names of the values (CSS variables) have changed. Most of the new names correspond 1-to-1 with one of the old names. Some colors have also changed slightly (e.g. `fg-default`), but otherwise remain mostly the same. See https://primer.style/foundations/primitives/migrating
1 parent 4f44a5c commit ce58fe6

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

.github/workflows/csstolua.lua

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local res = {}
2+
3+
for ln in io.lines() do
4+
local k, v = ln:match('^%s*%-%-(%w.-)%s*:%s*(.-)%s*;%s*$')
5+
6+
if k then
7+
k = k:gsub('%-+', '_')
8+
9+
if res[k] then
10+
assert(res[k] == v)
11+
else
12+
res[k] = v
13+
end
14+
end
15+
end
16+
17+
io.write('local M = {\n')
18+
19+
for k, v in pairs(res) do
20+
io.write((' [%q] = %q,\n'):format(k, v))
21+
end
22+
23+
io.write('}\n')

.github/workflows/update-color-primitives.yml

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ name: Get/Update Primer Color Primitives
22

33
env:
44
_DEST_DIR: "${{ github.workspace }}/lua/github-theme/palette/primitives"
5-
_JSON_DIR: "${{ github.workspace }}/node_modules/@primer/primitives/dist/json/colors"
5+
_SRC_DIR: "${{ github.workspace }}/node_modules/@primer/primitives/dist/internalCss"
66
_LICENSE_GLOB: "${{ github.workspace }}/node_modules/@primer/primitives/[Ll][Ii][Cc][Ee][Nn][Ss][Ee]*"
77
_PRIMITIVES_PKGJSON: "${{ github.workspace }}/node_modules/@primer/primitives/package.json"
8+
_CSSTOLUA: "${{ github.workspace }}/.github/workflows/csstolua.lua"
89

910
on:
1011
workflow_dispatch:
1112
schedule:
12-
# 3x per week (every other day) at 12:40pm Pacific Time
13-
- cron: "40 19 * * 1,3,5"
13+
# once a week, every Monday at 12:40pm Pacific Time
14+
- cron: "40 19 * * 1"
1415

1516
jobs:
1617
get-colors:
@@ -34,21 +35,22 @@ jobs:
3435
- run: npm i @primer/primitives@latest
3536

3637
- run: |
37-
set -u +f
38+
set -eu +f
3839
shopt -s nocaseglob failglob
3940
license="$(<$_LICENSE_GLOB)"
4041
rm -r "$_DEST_DIR" || :
4142
mkdir -p "$_DEST_DIR"
42-
cd "$_JSON_DIR"
43+
cd "$_SRC_DIR"
4344
4445
if jq -e .version "$_PRIMITIVES_PKGJSON"; then
4546
version="M._VERSION = vim.json.decode([=[$(jq -e .version "$_PRIMITIVES_PKGJSON")]=], { luanil = { object = false, array = false } })"
4647
fi
4748
48-
for file in *.json; do
49-
cat >|"${_DEST_DIR}/${file%.json}.lua" <<EOF
49+
for file in *.css; do
50+
values="$(nvim -l "$_CSSTOLUA" < "$file")"
51+
cat >| "${_DEST_DIR}/${file%.css}.lua" <<EOF
5052
-- NOTE: THIS IS AN AUTO-GENERATED FILE. DO NOT EDIT BY-HAND.
51-
local M = vim.json.decode([=[$(<"$file")]=], { luanil = { object = false, array = false } })
53+
${values}
5254
${version-}
5355
M._LICENSE = [=[
5456
$license]=]

0 commit comments

Comments
 (0)