Skip to content

Commit

Permalink
Merge pull request #188 from FormidableLabs/v2-gh-actions-changesets
Browse files Browse the repository at this point in the history
Add GitHub Actions + Changesets
  • Loading branch information
carloskelly13 committed Apr 18, 2023
2 parents 5ad6e2d + 7f69fe3 commit 0b6746a
Show file tree
Hide file tree
Showing 7 changed files with 2,256 additions and 1,166 deletions.
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": [
"@svitejs/changesets-changelog-github-compact",
{
"repo": "FormidableLabs/prism-react-renderer"
}
],
"access": "public",
"baseBranch": "master"
}
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: groqd Release Workflow

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build packages
run: pnpm run build

- name: PR or Publish
id: changesets
uses: changesets/action@v1
with:
version: pnpm run version
publish: pnpm run changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Static Analysis

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
static-analysis:
name: 'Lint and Type-check'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build library
run: pnpm run build
- name: Type Check
run: pnpm run typecheck
- name: Lint
run: pnpm run lint
44 changes: 44 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Unit Test

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
matrix:
name: 'Node ${{ matrix.node }}'
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Generate language definitions
run: pnpm run build:languages

- name: Unit Test
run: pnpm run test

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
"typecheck": "pnpm run -r typecheck",
"check:ci": "pnpm run typecheck && pnpm run lint && pnpm run test",
"start:demo": "pnpm --filter demo dev",
"build": "pnpm --sequential --filter generate-prism-languages --filter prism-react-renderer --filter demo build",
"build:watch": "pnpm --filter generate-prism-languages build && pnpm --filter prism-react-renderer build:watch"
"build": "pnpm --sequential --filter generate-prism-languages --filter prism-react-renderer build",
"build:languages": "pnpm --filter generate-prism-languages build",
"build:watch": "pnpm --filter generate-prism-languages build && pnpm --filter prism-react-renderer build:watch",
"changeset": "changeset",
"version": "pnpm changeset version && pnpm install"
},
"devDependencies": {
"@changesets/cli": "^2.26.0",
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
"@babel/cli": "^7.10.4",
"@babel/core": "^7.21.4",
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/prism-react-renderer/src/utils/normalizeTokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Token } from "../types"
import type { Token as PrismToken } from "prismjs"
import type { Token as PrismToken, TokenStream } from "prismjs"

const newlineRe = /\r\n|\r|\n/

Expand Down Expand Up @@ -33,7 +33,7 @@ const appendTypes = (types: string[], add: string[] | string): string[] => {
// are always of type "plain".
// This is not recursive to avoid exceeding the call-stack limit, since it's unclear
// how nested Prism's tokens can become
const normalizeTokens = (tokens: Array<PrismToken | string>): Token[][] => {
const normalizeTokens = (tokens: (PrismToken | string)[]): Token[][] => {
const typeArrStack: string[][] = [[]]
const tokenArrStack = [tokens]
const tokenArrIndexStack = [0]
Expand All @@ -47,7 +47,7 @@ const normalizeTokens = (tokens: Array<PrismToken | string>): Token[][] => {
while (
(i = tokenArrIndexStack[stackIndex]++) < tokenArrSizeStack[stackIndex]
) {
let content: any
let content: TokenStream
let types = typeArrStack[stackIndex]
const tokenArr = tokenArrStack[stackIndex]
const token = tokenArr[i]
Expand All @@ -70,7 +70,7 @@ const normalizeTokens = (tokens: Array<PrismToken | string>): Token[][] => {
if (typeof content !== "string") {
stackIndex++
typeArrStack.push(types)
tokenArrStack.push(content)
tokenArrStack.push(content as PrismToken[])
tokenArrIndexStack.push(0)
tokenArrSizeStack.push(content.length)
continue
Expand Down
Loading

0 comments on commit 0b6746a

Please sign in to comment.