ci(primitives): transition to new css primitives #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Get/Update Primer Primitives | |
env: | |
_DEST_DIR: '${{ github.workspace }}/lua/github-theme/palette/primitives' | |
_SRC_DIR: '${{ github.workspace }}/node_modules/@primer/primitives/dist/internalCss' | |
_LICENSE_GLOB: '${{ github.workspace }}/node_modules/@primer/primitives/[Ll][Ii][Cc][Ee][Nn][Ss][Ee]*' | |
_PRIMITIVES_PKGJSON: '${{ github.workspace }}/node_modules/@primer/primitives/package.json' | |
_CSSTOLUA: '${{ github.workspace }}/.github/workflows/csstolua.lua' | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '40 19 1,15 * *' # Roughly every 2 weeks (at 12:40pm Pacific Time) | |
push: | |
branches: | |
- '**' # Any branch, but ignore tag pushes | |
paths: | |
- .github/workflows/**/* | |
- scripts/**/* | |
pull_request: | |
paths: | |
- .github/workflows/**/* | |
- scripts/**/* | |
jobs: | |
install-primitives: | |
runs-on: ubuntu-latest | |
permissions: # NOTE: `write` is not applied for PR's from forks | |
checks: write | |
contents: write | |
issues: write | |
packages: read | |
pull-requests: write | |
statuses: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: rhysd/action-setup-vim@v1 | |
with: | |
neovim: true | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
check-latest: true | |
- run: npm i @primer/primitives@latest | |
- name: Generate Lua files | |
run: | | |
set -eu +f | |
shopt -s nocaseglob failglob | |
license="$(<$_LICENSE_GLOB)" | |
rm -r "$_DEST_DIR" || : | |
mkdir -p "$_DEST_DIR" | |
cd "$_SRC_DIR" | |
if jq -e .version "$_PRIMITIVES_PKGJSON"; then | |
version="M._VERSION = vim.json.decode([=[$(jq -e .version "$_PRIMITIVES_PKGJSON")]=], { luanil = { object = false, array = false } })" | |
fi | |
for file in *.css; do | |
values="$(nvim -l "$_CSSTOLUA" < "$file")" | |
cat >| "${_DEST_DIR}/$(tr '-' '_' <<< "${file%.css}.lua")" <<EOF | |
-- NOTE: THIS IS AN AUTO-GENERATED FILE. DO NOT EDIT BY-HAND. | |
${values} | |
${version-} | |
M._LICENSE = [=[ | |
$license]=] | |
return M | |
EOF | |
done | |
- name: Check formatting (stylua) | |
uses: JohnnyMorganz/stylua-action@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
version: latest | |
args: -f stylua.toml --verify -- ${{ env._DEST_DIR }} | |
- id: diff | |
run: git diff --quiet -- "$_DEST_DIR" || echo has_diff=true >> "$GITHUB_OUTPUT" | |
- if: ${{ steps.diff.outputs.has_diff }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: primitives | |
path: ${{ env._DEST_DIR }} | |
retention-days: ${{ (github.event_name != 'push' || github.ref_name != 'main') && 14 || null }} | |
if-no-files-found: error | |
overwrite: true | |
- if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
delete-branch: true | |
branch: generated/primitives/${{ github.ref_name }} | |
commit-message: 'deps(primer): update primitives' | |
title: 'deps(primer): update primitives' | |
body: | | |
| | | | |
| ----------------- | ------------------------ | | |
| **Trigger** | ${{ github.event_name }} | | |
| **Target Branch** | ${{ github.ref_name }} | | |
> [!NOTE] | |
> Checks are not automatically run for this PR. | |
> Close and reopen this PR to run tests and checks (against the newly generated primitives). |