Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workflows): add a build-tokens workflow #3256

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/build-tokens.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build Tokens
on:
pull_request:
types: [opened, synchronize, edited, reopened]
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved
paths:
- 'packages/tokens/**'

jobs:
build:
name: Build Tokens
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup-pnpm

- name: Install dependencies
run: pnpm --filter design-system-tokens... install

- name: Build tokens & dependencies
run: pnpm --filter design-system-tokens... build

- name: Create Summary
id: summary
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const path = require('path')

const inputfileNames = fs.readdirSync('packages/tokens/tokensstudio-generated')
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved
const inputFiles = inputfileNames.map(fileName => ({
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved
type: path.extname(fileName),
name: fileName,
content: fs.readFileSync(`packages/tokens/tokensstudio-generated/${fileName}`, 'utf8')
}))

const outputOrder = [
'index.scss',
'core.scss',
'mode.scss',
'device.scss',
'channel.scss',
'theme.scss',
'components.scss',
]
const outputFileNames = fs.readdirSync('packages/tokens/dist')
const outputFiles = outputFileNames.map(fileName => ({
type: path.extname(fileName),
name: fileName,
content: fs.readFileSync(`packages/tokens/dist/${fileName}`, 'utf8')
})).sort((a, b) => (outputOrder.indexOf(a.name) === -1 ? 1000 : outputOrder.indexOf(a.name)) - (outputOrder.indexOf(b.name) === -1 ? 1000 : outputOrder.indexOf(b.name)))
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved

return `# Build Tokens
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved
## Input
${inputFiles.map(({ type, name, content }) => `<details>
<summary><code>${name}</code></summary>
<pre lang="${type}">${content}</pre>
</details>`).join('\n')}

## Output
${outputFiles.map(({ type, name, content }) => `<details>
<summary><code>${name}</code></summary>
<pre lang="${type}">${content}</pre>
</details>`).join('\n')}
`

- name: Output Summary
run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY