Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
feat: added vscode extension with highlighting and snippets (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Mar 6, 2019
1 parent 92b78d2 commit 8112d1d
Show file tree
Hide file tree
Showing 15 changed files with 781 additions and 124 deletions.
12 changes: 10 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"outFiles": ["${workspaceFolder}/out/**"],
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
},
"outFiles": ["${workspaceFolder}/out/**"]
}
},
{
"type": "extensionHost",
"request": "launch",
"name": "Launch Extension",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}/out/extension"],
"preLaunchTask": "create-extension-package"
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"files.exclude": {
"**/node_modules": true
"**/node_modules": true,
"**/out": true
},
"cSpell.words": ["bfnrt", "gmail", "noreply"]
}
14 changes: 14 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "create-extension-package",
"type": "shell",
"command": "yarn",
"group": "build",
"args": ["gulp", "create-extension-package"]
}
]
}
60 changes: 5 additions & 55 deletions docs/grammar.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# Workflow Grammar
# Workflow File Grammar

This grammar is based on the published by
[actions/workflow-parser](https://github.com/actions/workflow-parser/blob/master/language.md). Compiling a `.workflow`
file is divided into three phases:
This grammar is based on the one published by:

1. **Scanning**: where text is divided into individual tokens, marked by a range and a type.
2. **Parsing**: an initial syntax tree is constructed from the token stream. Parsing is error-tolerant and prefers to
construct partially valid trees in order to report diagnostics in the next phase.
3. **Binding**: where a complete list of symbols is compiled, and any advanced analysis/error reporting is done.
> https://github.com/actions/workflow-parser/blob/master/language.md
A compilation holds the results of these operations. The rest of this document describes them in detail.

## Scanning

The scanner produces a list of the tokens below from a document text.
## Scanner

```g4
VERSION_KEYWORD : 'version' ;
Expand Down Expand Up @@ -46,11 +37,7 @@ STRING_LITERAL : '"' (('\\' ["\\/bfnrt]) | ~["\\\u0000-\u001F\u007F])* '"' ;
WS : [\n \t\r] -> skip;
```

## Parsing

The parser will create a high-level list of blocks, without actually making decisions about which properties are legal
under which parents. It tries to leave as much work as possible to the binding phase. Each syntax node holds comment
tokens appearing before it. The main document node holds comment tokens appearing after it.
## Parser

```g4
workflow_file : (version | block)* ;
Expand Down Expand Up @@ -84,40 +71,3 @@ env_variables : LEFT_CURLY_BRACKET (env_variable)* RIGHT_CURLY_BRACKET ;
env_variable : IDENTIFIER EQUAL STRING_LITERAL ;
```

## Binding

It takes the high-level parse tree, holding to their original syntax nodes and comments, and produces the following
structure. It also validates that:

1. Version number is supported, and is declared (if any) at the correct location.
2. All properties are correct, and under the right type of block.
3. Complex values like Docker and GitHub URLs are valid.
4. Environment values and secrets are unique, and have correct keys.
5. No circular dependencies in the action graph.

```typescript
type Document {
version? number;
workflows: Workflow[];
actions: Action[];
}

type Workflow {
name: string;
on: string;
resolves: string[];
}

type Action {
name: string;
uses: string;
needs: string[];
runs: string[];
args: string[];
env: {
[key: string] : string;
};
secrets: string[];
}
```
14 changes: 7 additions & 7 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as gulp from "gulp";
import { BuildTasks } from "./scripts/gulp-build";
import { PackageTasks } from "./scripts/gulp-package";
import { ExtensionTasks } from "./scripts/gulp-extension";

gulp.task(
"ci",
Expand All @@ -13,13 +14,12 @@ gulp.task(

gulp.task(
"create-linter-package",
gulp.series([
BuildTasks.clean,
BuildTasks.compile,
PackageTasks.copyFiles,
PackageTasks.copyReadMe,
PackageTasks.generateCliPackage,
]),
gulp.series([BuildTasks.clean, BuildTasks.compile, PackageTasks.copyFiles, PackageTasks.generatePackageJson]),
);

gulp.task(
"create-extension-package",
gulp.series([BuildTasks.clean, BuildTasks.compile, ExtensionTasks.copyFiles, ExtensionTasks.generatePackageJson]),
);

gulp.task("default", gulp.parallel([BuildTasks.compile, BuildTasks.jest]));
62 changes: 58 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,60 @@
"name": "github-actions-js",
"version": "0.0.6",
"description": "A VSCode extension and a parser/linter for GitHub workflow/action files.",
"repository": "https://github.com/OmarTawfik/github-actions-js",
"publisher": "OmarTawfik",
"repository": {
"type": "git",
"url": "https://github.com/OmarTawfik/github-actions-js"
},
"author": "Omar Tawfik <[email protected]>",
"bugs": {
"url": "https://github.com/OmarTawfik/github-actions-js/issues",
"email": "[email protected]"
},
"license": "MIT",
"icon": "./resources/logo.png",
"categories": [
"Programming Languages",
"Snippets",
"Linters",
"Formatters"
],
"activationEvents": [
"onLanguage:github-actions"
],
"contributes": {
"languages": [
{
"id": "github-actions",
"extensions": [
".workflow"
],
"aliases": [
"GitHub Actions",
"GitHub Workflows"
]
}
],
"grammars": [
{
"language": "github-actions",
"scopeName": "source.workflow",
"path": "./resources/grammar.json"
}
],
"snippets": [
{
"language": "github-actions",
"path": "./resources/snippets.json"
}
]
},
"scripts": {
"gulp": "./node_modules/.bin/gulp"
"gulp": "./node_modules/.bin/gulp",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"engines": {
"vscode": "^1.23.0"
},
"jest": {
"preset": "ts-jest",
Expand All @@ -16,7 +65,11 @@
"keywords": [
"github",
"actions",
"parser"
"workflows",
"parser",
"linter",
"vscode",
"extension"
],
"devDependencies": {
"@types/del": "3.0.1",
Expand All @@ -40,7 +93,8 @@
"tslint": "5.12.1",
"tslint-config-airbnb": "5.11.1",
"tslint-config-prettier": "1.18.0",
"typescript": "3.3.3"
"typescript": "3.3.3",
"vscode": "1.1.23"
},
"dependencies": {
"chalk": "2.4.2"
Expand Down
36 changes: 36 additions & 0 deletions scripts/gulp-extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository.
*/

import * as path from "path";
import * as gulp from "gulp";
import * as merge from "gulp-merge-json";
import { outPath, rootPath } from "./gulp-utils";

const extensionPath = path.join(outPath, "extension");

export module ExtensionTasks {
export const copyFiles = "extension:copy-files";
export const generatePackageJson = "extension:generate-package-json";
}

gulp.task(ExtensionTasks.copyFiles, () => {
return gulp
.src([
path.join(outPath, "src", "**"),
path.join(rootPath, "src", "resources*", "**"),
path.join(rootPath, "README.md"),
])
.pipe(gulp.dest(extensionPath));
});

gulp.task(ExtensionTasks.generatePackageJson, () => {
return gulp
.src([path.join(rootPath, "package.json"), path.join(rootPath, "scripts", "package-extension.json")])
.pipe(
merge({
fileName: "package.json",
}),
)
.pipe(gulp.dest(extensionPath));
});
13 changes: 4 additions & 9 deletions scripts/gulp-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ const packagePath = path.join(outPath, "package");

export module PackageTasks {
export const copyFiles = "package:copy-files";
export const copyReadMe = "package:copy-readme";
export const generateCliPackage = "package:generate-cli-package";
export const generatePackageJson = "package:generate-package-json";
}

gulp.task(PackageTasks.copyFiles, () => {
return gulp.src(path.join(outPath, "src", "**")).pipe(gulp.dest(packagePath));
return gulp.src([path.join(outPath, "src", "**"), path.join(rootPath, "README.md")]).pipe(gulp.dest(packagePath));
});

gulp.task(PackageTasks.copyReadMe, () => {
return gulp.src(path.join(rootPath, "README.md")).pipe(gulp.dest(packagePath));
});

gulp.task(PackageTasks.generateCliPackage, () => {
gulp.task(PackageTasks.generatePackageJson, () => {
return gulp
.src([path.join(rootPath, "package.json"), path.join(rootPath, "package-npm.json")])
.src([path.join(rootPath, "package.json"), path.join(rootPath, "scripts", "package-npm.json")])
.pipe(
merge({
fileName: "package.json",
Expand Down
5 changes: 5 additions & 0 deletions scripts/package-extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "github-actions-vscode",
"description": "A VSCode extension for editing/linting GitHub actions/workflow files.",
"main": "extension.js"
}
File renamed without changes.
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*!
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository.
*/

import * as vscode from "vscode";

export function activate(_: vscode.ExtensionContext): void {}

export function deactivate(): void {}
60 changes: 60 additions & 0 deletions src/resources/grammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "github-actions",
"scopeName": "source.workflow",
"patterns": [
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#strings"
},
{
"include": "#integers"
}
],
"repository": {
"comments": {
"patterns": [
{
"name": "comment",
"match": "(#|//).*"
}
]
},
"keywords": {
"patterns": [
{
"name": "support.class",
"match": "\\b(version|workflow|action)\\b"
},
{
"name": "support.variable",
"match": "\\b(on|resolves|needs|uses|runs|args|env|secrets)\\b"
}
]
},
"strings": {
"name": "string",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "contents",
"match": "\\\\."
}
]
},
"integers": {
"patterns": [
{
"name": "constant.numeric",
"match": "[0-9]+"
}
]
}
}
}
Binary file added src/resources/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8112d1d

Please sign in to comment.