Skip to content

Commit

Permalink
Port to TypeScript and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Mar 20, 2024
1 parent ac701c2 commit f829110
Show file tree
Hide file tree
Showing 27 changed files with 98,217 additions and 208 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.github/
/.vscode/
/coverage/
/dist/
/node_modules/
/__tests__/
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"eqeqeq": 2,
"no-duplicate-imports": "error",
"indent": ["error", 2, { "SwitchCase": 1, "ignoredNodes": ["MemberExpression"] }],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "never"]
},
"env": {
"node": true
}
}
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text=auto eol=lf

# Exclude test files from language stats
/dist/** -diff linguist-generated=true
*.[dD] linguist-detectable=false
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Modified from: actions/typescript-action
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
checks: write
contents: read

jobs:
test-typescript:
name: TypeScript Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install Dependencies
run: npm ci

- name: Check Format
run: npm run format:check

- name: Lint
run: npm run lint

- name: Test
run: npm run test

- name: Build dist/ Directory
run: npm run bundle

- name: Compare Directories
id: diff
run: |
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff --ignore-space-at-eol --text dist/
exit 1
fi
# If `dist/` was different than expected, upload the expected version as artifact
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
name: Upload Artifact
id: upload
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test Local Action
uses: ./
with:
file: ./__tests__/data/pass.d
18 changes: 0 additions & 18 deletions .github/workflows/testing.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules/
/coverage/
/__tests__/TEMP/
/__tests__/CACHE/
/.parsiphae-action-bin/
/.parsiphae-action-source/
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.github/
/.vscode/
/coverage/
/dist/
/node_modules/
/__tests__/
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": false,
"singleQuote": true,
"singleAttributePerLine": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 140,
"endOfLine": "lf"
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files.eol": "\n",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "never",
"source.fixAll.format": "never"
},
"typescript.tsdk": "./node_modules/typescript/lib"
}
55 changes: 26 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Parsiphae Action

[![test](https://github.com/szapp/parsiphae-action/actions/workflows/testing.yml/badge.svg)](https://github.com/szapp/parsiphae-action/actions/workflows/testing.yml)
[![marketplace](https://img.shields.io/github/v/release/szapp/parsiphae-action?logo=githubactions&logoColor=white&label=marketplace)](https://github.com/marketplace/actions/daedalus-parsiphae)
[![CI](https://github.com/szapp/parsiphae-action/actions/workflows/ci.yml/badge.svg)](https://github.com/szapp/parsiphae-action/actions/workflows/ci.yml)
[![Coverage](badges/coverage.svg)](https://github.com/szapp/parsiphae-action/actions/workflows/ci.yml)
[![Marketplace](https://img.shields.io/github/v/release/szapp/parsiphae-action?logo=githubactions&logoColor=white&label=marketplace)](https://github.com/marketplace/actions/daedalus-parsiphae)

Github action for [Parsiphae](https://github.com/Lehona/Parsiphae), a WIP compiler for the Daedalus scripting language, written by and maintained by [@Lehona](https://github.com/Lehona).
GitHub action for [Parsiphae](https://github.com/Lehona/Parsiphae), a WIP compiler for the Daedalus scripting language, written by and maintained by [@Lehona](https://github.com/Lehona).

## Checks

Expand All @@ -23,11 +24,11 @@ Checks are added to commits and performed on pull requests.

## Usage

Create a new GitHub Actions workflow in your project, e.g. at `.github/workflows/syntax.yml`.
Create a new GitHub Actions workflow in your project, e.g. at `.github/workflows/scripts.yml`.
The content of the file should be in the following format:

```yaml
name: syntax
name: scripts

# Run workflow on push with changes of src or d files
on:
Expand All @@ -44,37 +45,33 @@ permissions:
# The checkout action needs to be run first
jobs:
parsiphae:
name: Run syntax check
name: Run Parsiphae on scripts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check syntax
- name: Check scripts
uses: szapp/parsiphae-action@v1
with:
file: _work/Data/Scripts/Content/Gothic.src
```
## Configuration
* `file`:
File path within the repository of the D file or the SRC file to parse, e.g. `_work\Data\Scripts\Content\Gothic.src`
*Required*

* `version`:
Parsiphae version to use (branch, tag, or commit-SHA).
Defaults to `master`, i.e. using the master branch of [Parsiphae](https://github.com/Lehona/Parsiphae) with the latest changes.

* `token`:
The `GITHUB_TOKEN` to [authenticate on behalf of GitHub Actions](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow).
Defaults to the GitHub token, i.e. checks are created by the GitHub Actions bot.

* `check_name`:
Specify a different name for the check run.
Useful to differentiate checks if there are multiple instances of this action in one workflow.
Defaults to 'Parsiphae'

* `cache`:
Cache the Parsiphae built in between workflow runs.
This greatly increases speed of the check as Parsiphae is not cloned and re-built every time.
The cached executable is specific to the workflow runner OS and the Parsiphae version (see `version`) specified.
Defaults to true
- `file`:
File path within the repository of the D file or the SRC file to parse, e.g. `_work\Data\Scripts\Content\Gothic.src`
_Required_

- `token`:
The `GITHUB_TOKEN` to [authenticate on behalf of GitHub Actions](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow).
Defaults to the GitHub token, i.e. checks are created by the GitHub Actions bot.

- `check_name`:
Specify a different name for the check run.
Useful to differentiate checks if there are multiple instances of this action in one workflow.
Defaults to 'Parsiphae'

- `cache`:
Cache the Parsiphae built in between workflow runs.
This greatly increases speed of the check as Parsiphae is not cloned and re-built every time.
The cached executable is specific to the workflow runner OS and the Parsiphae version (see `version`) specified.
Defaults to true
3 changes: 3 additions & 0 deletions __tests__/data/fail.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const int foo = 0;
const int bar = 1
const string baz = 2;
3 changes: 3 additions & 0 deletions __tests__/data/pass.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const int foo = 0;
const int bar = 1;
const string baz = 2;
12 changes: 12 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as main from '../src/main'

const runMock = jest.spyOn(main, 'run').mockImplementation()

describe('index', () => {
it('calls run when imported', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index')

expect(runMock).toHaveBeenCalled()
})
})
Loading

0 comments on commit f829110

Please sign in to comment.