Skip to content

Commit

Permalink
feat: add ci tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Jan 26, 2024
1 parent 2080833 commit 972affa
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 28 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
workflow_run:
workflows: [ "Test" ]
branches: [ "main", "next" ]
types:
- completed

jobs:
main:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: '${{ secrets.TOLGEE_MACHINE_PAT }}'

- uses: pnpm/[email protected]
name: Install pnpm
id: pnpm-install
with:
version: 8.6.12
run_install: false

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '20'
cache: pnpm

- name: Install
run: pnpm install --frozen-lockfile

- name: Run get new version
run: npm run release-dry
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set version property
id: version
run: echo ::set-output name=VERSION::$(test -e .VERSION && echo v$(cat .VERSION))

- name: Build
if: ${{ steps.version.outputs.VERSION != '' }}
run: pnpm run build

- name: Login to docker
run: echo '${{ secrets.TOLGEE_MACHINE_PAT }}' | docker login ghcr.io -u USERNAME --password-stdin


- name: Create docker image
if: ${{ steps.version.outputs.VERSION != '' }}
run: |
docker buildx create --use
docker buildx build . -t ghcr.io/tolgee/translator:${{ steps.version.outputs.VERSION }} --platform linux/arm64,linux/amd64 --push
docker buildx build . -t ghcr.io/tolgee/translator:latest --platform linux/arm64,linux/amd64 --push
- name: Run npm release
if: ${{ steps.version.outputs.VERSION != '' }}
run: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.VERSION }}


48 changes: 48 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test

on:
pull_request:
push:
branches: [main]

jobs:
test:
name: 'Test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '20'
cache: npm

- name: Install
run: npm ci

- name: Test
run: npm run test


code-checks:
name: Eslint 🪲
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '20'
cache: npm

- name: Install
run: npm ci

- name: Eslint
run: npm run eslint

- name: Typescript
run: npm run tsc

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"dev": "vite",
"build": "tsc -p tsconfig.lib.json && vite build",
"build:watch": "concurrently \"tsc -p tsconfig.lib.json -w\" \"vite build -w\"",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"eslint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"tsc": "tsc --noEmit",
"grammar": "lezer-generator ./src/parser/tolgee.grammar -o ./src/parser/tolgeeParser.ts",
"preview": "vite preview",
"test": "jest"
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const Editor: React.FC<Props> = ({

editor.current = instance;
return () => instance.destroy();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
Expand All @@ -91,6 +92,7 @@ export const Editor: React.FC<Props> = ({
editor.current?.dispatch({
effects: compartment.current?.reconfigure(plugins),
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [placeholders]);

return <StyledEditor ref={ref} />;
Expand Down
19 changes: 11 additions & 8 deletions src/parser/PlaceholderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function buildPlaceholders(
modifiedRange: [from: number, to: number] | undefined
) {
const placeholders = getPlaceholders(text);

if (placeholders === null) {
return null;
}

return placeholders.filter((value) => {
if (modifiedRange) {
const [from, to] = modifiedRange;
Expand Down Expand Up @@ -138,7 +143,7 @@ export const PlaceholderPlugin = (options?: Options) => {
return StateField.define<Placeholder[]>({
create(state) {
try {
return buildPlaceholders(state.doc.toString(), undefined);
return buildPlaceholders(state.doc.toString(), undefined) || [];
} catch (e) {
return [];
}
Expand All @@ -159,13 +164,11 @@ export const PlaceholderPlugin = (options?: Options) => {
modifiedRange = [fromB, toB];
}
});
let newPlaceholders: Placeholder[] | undefined = undefined;
try {
newPlaceholders = buildPlaceholders(
change.state.doc.toString(),
modifiedRange
);
} catch (e) {
const newPlaceholders = buildPlaceholders(
change.state.doc.toString(),
modifiedRange
);
if (newPlaceholders === null) {
return shiftByChanges(value, change.changes);
}

Expand Down
35 changes: 16 additions & 19 deletions src/playground/TooltipPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ import { hoverTooltip } from "@codemirror/view";
import { getPlaceholders } from "../parser/getPlaceholders";

export const tooltipPlugin = hoverTooltip((view, pos) => {
try {
const placeholder = getPlaceholders(view.state.doc.toString()).find(
(item) =>
item.error && item.position.start <= pos && item.position.end >= pos
);
const placeholder = getPlaceholders(view.state.doc.toString())?.find(
(item) =>
item.error && item.position.start <= pos && item.position.end >= pos
);

if (placeholder) {
return {
pos: placeholder.position.start,
end: placeholder.position.end,
create: () => {
const dom = document.createElement("div");
dom.className = "cm-tooltip-cursor";
dom.textContent = placeholder.error!;
return { dom };
},
};
}
} catch (e) {
// pass
if (placeholder) {
return {
pos: placeholder.position.start,
end: placeholder.position.end,
create: () => {
const dom = document.createElement("div");
dom.className = "cm-tooltip-cursor";
dom.textContent = placeholder.error!;
return { dom };
},
};
}

return null;
});

0 comments on commit 972affa

Please sign in to comment.