Skip to content

Commit 324eae6

Browse files
committed
feat: Initial commit
0 parents  commit 324eae6

File tree

18 files changed

+1218
-0
lines changed

18 files changed

+1218
-0
lines changed

.github/workflows/push.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: actions/setup-go@v3
11+
- uses: actions/setup-node@v3
12+
- run: yarn install
13+
- run: make build
14+
- run: yarn test
15+
- name: release
16+
if: github.ref == 'refs/heads/main'
17+
run: npx --yes semantic-release --branches main
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
main.wasm
2+
wasm_exec.js
3+
node_modules/
4+
types/

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"gopls": {
3+
"build.env": {
4+
"GOOS": "js",
5+
"GOARCH": "wasm"
6+
}
7+
}
8+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 XING Developers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
build: wasm_exec.js main.wasm types/node.d.mts
2+
3+
wasm_exec.js:
4+
cp $$(go env GOROOT)/misc/wasm/wasm_exec.js wasm_exec.tmp.js
5+
echo "// @ts-nocheck" > wasm_exec.js
6+
cat wasm_exec.tmp.js >> wasm_exec.js
7+
rm wasm_exec.tmp.js
8+
9+
main.wasm: main.go go.mod
10+
GOOS=js GOARCH=wasm go build -o main.wasm
11+
12+
types/node.d.mts: *.cjs *.mjs *.d.ts *.json yarn.lock
13+
$$(yarn bin)/tsc -p .
14+
15+
clean:
16+
rm main.wasm
17+
rm wasm_exec.js
18+
rm -rf types
19+
20+
.PHONY: build clean

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# actionlint
2+
Actionlint as wasm

actionlint.cjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require("./wasm_exec.js");
2+
3+
/**
4+
* @typedef {(go: Go) => Promise<WebAssembly.WebAssemblyInstantiatedSource>} WasmLoader
5+
* @typedef {(source: string, path: string) => Promise<LintResult[]>} RunActionlint
6+
*
7+
* @typedef {Object} LintResult
8+
* @property {string} Message
9+
* @property {string} Filepath
10+
* @property {number} Line
11+
* @property {number} Column
12+
* @property {string} Kind
13+
*/
14+
15+
/**
16+
* @param {WasmLoader} loader
17+
* @returns {RunActionlint}
18+
*/
19+
module.exports.createActionlint = function createActionlint(loader) {
20+
const go = new Go();
21+
22+
/** @type {(() => void)[] | undefined} */
23+
let queued = undefined;
24+
25+
// This function gets called from go once the wasm module is ready and it
26+
// executes the linter for all queued calls.
27+
globalThis.actionlintInitialized = () => {
28+
queued?.forEach((f) => f());
29+
queued = globalThis.actionlintInitialized = undefined;
30+
};
31+
32+
loader(go).then((wasm) => {
33+
// Do not await this promise, because it only resolves once the go main()
34+
// function has exited. But we need the main function to stay alive to be
35+
// able to call the `runActionlint` function.
36+
go.run(wasm.instance);
37+
});
38+
39+
/**
40+
* @param {string} src
41+
* @param {string} path
42+
* @returns {Promise<LintResult[]>}
43+
*/
44+
return async function runLint(src, path) {
45+
// Return a promise, because we need to queue calls to `runLint()` while the
46+
// wasm module is still loading and execute them once the wasm module is
47+
//ready.
48+
return new Promise((resolve, reject) => {
49+
if (typeof runActionlint === "function") {
50+
const [result, err] = runActionlint(src, path);
51+
return err ? reject(err) : resolve(result);
52+
}
53+
54+
if (!queued) {
55+
queued = [];
56+
}
57+
58+
queued.push(() => {
59+
const [result, err] = runActionlint?.(src, path) ?? [
60+
[],
61+
new Error('"runActionlint" is not defined'),
62+
];
63+
return err ? reject(err) : resolve(result);
64+
});
65+
});
66+
};
67+
};

browser.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createActionlint } from "./actionlint.cjs";
2+
3+
/**
4+
* @typedef {import("./actionlint.cjs").LintResult} LintResult
5+
* @typedef {import("./actionlint.cjs").WasmLoader} WasmLoader
6+
* @typedef {import("./actionlint.cjs").RunActionlint} RunActionlint
7+
*/
8+
9+
/** @type {RunActionlint | undefined} */
10+
let runLint = undefined;
11+
12+
/**
13+
* @param {URL} url
14+
* @returns {RunActionlint}
15+
*/
16+
export function createLinter(url = new URL("./main.wasm", import.meta.url)) {
17+
if (runLint) {
18+
return runLint;
19+
}
20+
21+
return (runLint = createActionlint(
22+
/** @type {WasmLoader} */ async (go) => {
23+
return WebAssembly.instantiateStreaming(
24+
fetch(url.toString()),
25+
go.importObject
26+
);
27+
}
28+
));
29+
}

globals.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export declare global {
2+
var runActionlint:
3+
| ((src: string, path: string) => [LintResult[], Error | null])
4+
| undefined;
5+
var actionlintInitialized: (() => void) | undefined;
6+
}

go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module source.xing.com/fea/act-app
2+
3+
go 1.17
4+
5+
require (
6+
github.com/fatih/color v1.13.0 // indirect
7+
github.com/mattn/go-colorable v0.1.11 // indirect
8+
github.com/mattn/go-isatty v0.0.14 // indirect
9+
github.com/mattn/go-runewidth v0.0.13 // indirect
10+
github.com/rhysd/actionlint v1.6.9 // indirect
11+
github.com/rivo/uniseg v0.2.0 // indirect
12+
github.com/robfig/cron v1.2.0 // indirect
13+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
14+
golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02 // indirect
15+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
16+
)

0 commit comments

Comments
 (0)