-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e4072fd
Showing
9 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: test | ||
on: | ||
push: | ||
|
||
permissions: | ||
checks: write | ||
contents: read | ||
|
||
jobs: | ||
parsiphae: | ||
name: Run syntax check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run Parsiphae | ||
uses: ./ | ||
with: | ||
file: ./test.d |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Sören Zapp | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Parsiphae Action | ||
|
||
[](https://github.com/szapp/parsiphae-action/actions/workflows/testing.yml) | ||
|
||
Github action for [Parsiphae](https://github.com/Lehona/Parsiphae), a WIP compiler for the Daedalus scripting language. | ||
|
||
## Usage | ||
|
||
Create a new GitHub Actions workflow in your project, e.g. at `.github/workflows/syntax.yml`. | ||
The content of the file should be in the following format: | ||
|
||
```yaml | ||
name: syntax | ||
|
||
# Run workflow on push with changes of src or d files | ||
on: | ||
push: | ||
paths: | ||
- '**.src' | ||
- '**.d' | ||
|
||
# These permissions are necessary for creating the check runs | ||
permissions: | ||
checks: write | ||
contents: read | ||
|
||
# The checkout action needs to be run first | ||
jobs: | ||
parsiphae: | ||
name: Run syntax check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Check syntax | ||
uses: szapp/parsiphae-action@v1 | ||
with: | ||
file: _work/Data/Scripts/Content/Gothic.src | ||
``` | ||
## Checks | ||
Checks are added to commits and performed on pull requests. | ||
### Checks page | ||
 | ||
### Commit file and line annotations | ||
 | ||
### Pull request checks | ||
 | ||
## 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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: Parsiphae | ||
description: Parser checks for Daedalus scripts | ||
inputs: | ||
file: | ||
description: File path of D file or SRC file | ||
required: true | ||
version: | ||
description: Parsiphae version to use (branch, tag, or sha) | ||
default: master | ||
token: | ||
description: Github authentication token | ||
default: ${{ github.token }} | ||
check_name: | ||
description: Name of check run | ||
default: Parsiphae | ||
cache: | ||
description: Cache Parsiphae built | ||
default: true | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Prepare Parsiphae | ||
run: | | ||
mkdir -p .parsiphae-action-source | ||
echo "$WORKSPACE/.parsiphae-action-source/target/release" >> $GITHUB_PATH | ||
filepath=$(echo "$FILE_PATH" | sed -r 's/\\\+/\//g' | sed -r 's/^\.?\///') | ||
echo "PARSIPHAE_FILEPATH=${filepath}" >> $GITHUB_ENV | ||
echo "PARSIPHAE_VERSION=$VERSION" >> $GITHUB_ENV | ||
shell: bash | ||
env: | ||
WORKSPACE: ${{ github.workspace }} | ||
FILE_PATH: ${{ inputs.file }} | ||
VERSION: ${{ inputs.version }} | ||
|
||
- name: Check file input | ||
id: ext | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const fs = require('fs') | ||
const { PARSIPHAE_FILEPATH: path } = process.env | ||
const ext = path.replace(/^.*\.src$/i, 's').replace(/^.*\.d$/i, 'i') | ||
if (!fs.existsSync(path)) | ||
core.setFailed(`File not found: '${path}'`) | ||
else if (ext !== 's' && ext !== 'i') | ||
core.setFailed(`Invalid file extension: '${path}'`) | ||
else | ||
core.setOutput('arg', ext) | ||
- name: Cache Parsiphae | ||
if: inputs.cache == 'true' | ||
id: cache-parsiphae | ||
uses: actions/cache@v4 | ||
with: | ||
path: .parsiphae-action-source/target/release | ||
key: ${{ runner.os }}-${{ inputs.version }}-parsiphae | ||
|
||
- name: Clone Parsiphae | ||
if: steps.cache-parsiphae.outputs.cache-hit != 'true' | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: Lehona/Parsiphae | ||
ref: ${{ inputs.version }} | ||
path: .parsiphae-action-source | ||
|
||
- name: Build Parsiphae | ||
if: steps.cache-parsiphae.outputs.cache-hit != 'true' | ||
run: | | ||
cd .parsiphae-action-source | ||
cargo build --release | ||
shell: bash | ||
|
||
- name: Run Parsiphae | ||
run: | | ||
parsiphae -$ARG "${PARSIPHAE_FILEPATH}" 2> .parsiphae-action.err > .parsiphae-action.out || true | ||
exit 0 | ||
shell: bash | ||
env: | ||
ARG: ${{ steps.ext.outputs.arg }} | ||
|
||
- name: Create Checks | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ inputs.token }} | ||
script: | | ||
const annotate = require('./annotate.js') | ||
return await annotate(github, context, core, '${{ inputs.check_name }}') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module.exports = async (github, context, core, checkName) => { | ||
const fs = require('fs'); | ||
|
||
// Patterns | ||
const regexFile = new RegExp(/(?<=in file \").+(?=\")/); | ||
const regexLine = new RegExp(/(?<=in line )[0-9]+/); | ||
const regexMsg = new RegExp(/(?<=: ).+/); | ||
const regexPreSlash = new RegExp(/^[\\|\/]+/); | ||
|
||
// Extended inputs | ||
const { PARSIPHAE_FILEPATH: srcfile, PARSIPHAE_VERSION: parVersion, GITHUB_WORKSPACE: workspace } = process.env | ||
|
||
// Parsiphae report | ||
const stdout = fs.readFileSync('.parsiphae-action.out', 'ascii'); | ||
const stderr = fs.readFileSync('.parsiphae-action.err', 'ascii'); | ||
const lines = stderr.split(/\r?\n/); | ||
|
||
// Iterate over reported errors | ||
const annotations = []; | ||
lines.forEach((line) => { | ||
if (!line.length) | ||
return; | ||
const linenum = +(line.match(regexLine) || ['0'])[0]; | ||
const message = (line.match(regexMsg) || ['invalid'])[0]; | ||
const path = (line.match(regexFile) || ['invalid'])[0]; | ||
const filename = core.toPosixPath(path.replace(/\\+/g, '\\').replace(workspace, '').replace(regexPreSlash, '')); | ||
annotations.push({ | ||
path: filename, | ||
start_line: linenum, | ||
end_line: linenum, | ||
annotation_level: 'failure', | ||
message: message | ||
}); | ||
}); | ||
|
||
// Construct detailed information | ||
const pos = stdout.search(/Parsed |parsing took/); | ||
let tree = stdout.substring(0, pos-1).trim(); | ||
if (tree) { | ||
tree = `<details><summary>Summary</summary><pre>${tree}</pre></details>`; | ||
} | ||
const info = stdout.substring(pos); | ||
const link = `https://github.com/Lehona/Parsiphae/tree/${parVersion}`; | ||
const details = ` | ||
Parsiphae parsed \`${srcfile}\`. | ||
${tree} | ||
${info} | ||
For more details on Parsiphae, see [Lehona/Parsiphae@${parVersion}](${link}). | ||
`; | ||
|
||
// Create Gitub check run | ||
const numErr = annotations.length; | ||
const { data: { details_url } } = await github.rest.checks.create({ | ||
...context.repo, | ||
name: checkName, | ||
head_sha: context.sha, | ||
started_at: new Date().toISOString(), | ||
completed_at: new Date().toISOString(), | ||
conclusion: numErr ? 'failure' : 'success', | ||
output: { | ||
title: `${numErr || 'No'} error${numErr != 1 ? 's' : ''}`, | ||
summary: `Parsiphae found ${numErr || 'no'} syntax error${numErr != 1 ? 's' : ''}`, | ||
text: details, | ||
annotations: annotations | ||
} | ||
}); | ||
|
||
// Refer to check run results | ||
const extraName = (checkName != 'Parsiphae') ? ' (' + checkName + ')' : '' | ||
core.notice(`Find the detailed Parsiphae${extraName} results at ${details_url}`); | ||
|
||
// Mark as always successful | ||
return true; | ||
}; |
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
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; |