Skip to content

Commit

Permalink
feat(binary): use deno for build binary (#802)
Browse files Browse the repository at this point in the history
* feat(binary): use deno for build binary

* rm

* Update yarn.lock

* CI: add deno test

* chore: remove CI env

* CI: simple and merge

* fix

* CI: remove macOS x Node.js 18

* CI: cancel

* CI: add yarn ci -vvv

* CI: remove env CI

* CI: -v
  • Loading branch information
azu committed Apr 7, 2024
1 parent b632fc3 commit cebbe6d
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 177 deletions.
38 changes: 11 additions & 27 deletions .github/workflows/publish-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,31 @@ on:
repository_dispatch:
types: [publish-artifact]
env:
CI: true
DOCKER_BASE_NAME: ghcr.io/${{ github.repository }}
DOCKER_HUB_BASE_NAME: secretlint/secretlint

permissions:
contents: write
packages: write
jobs:
# TODO: deno depend on npm registry
# so, we need to wait for npm publish
# Single Executable binary
publish-binary:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
node-version: [20]
runs-on: ubuntu-latest
needs: test-binary
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Use Bun
uses: oven-sh/setup-bun@v1
- name: Use Deno
uses: denoland/setup-deno@v1
with:
bun-version: 1.1.0
- name: Install
run: yarn install
- name: Build
run: yarn run build
deno-version: v1.x
- name: Test binary
run: deno task dev
working-directory: ./publish/binary-compiler
- name: Build binary
run: npm run dist
run: bash build.sh
working-directory: ./publish/binary-compiler
- name: Rename binary
run: |
# secretlint-{verion}-{os}-{arch}
# e.g.
# secretlint_0.0.1_linux_amd64
# secretlint_0.0.1_darwin_amd64
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | tr '[:upper:]' '[:lower:]' | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
mv ./publish/binary-compiler/dist/secretlint ./publish/binary-compiler/dist/secretlint_${{ github.event.client_payload.version }}_${OS}_${ARCH}
- name: Release
uses: softprops/action-gh-release@v2
with:
Expand Down
25 changes: 9 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
branches-ignore:
- gh-pages
pull_request:
env:
CI: true
permissions:
contents: read
jobs:
Expand All @@ -26,6 +24,10 @@ jobs:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
node-version: [ 18, 20 ]
# but exclude macOs x node 18
exclude:
- os: macos-latest
node-version: 18
steps:
- name: checkout
uses: actions/checkout@v4
Expand All @@ -36,17 +38,8 @@ jobs:
- name: Install
run: yarn install
- name: Test
run: yarn ci
# binary tet
- name: Use Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.0
- name: Build binary
run: npm run dist
working-directory: ./publish/binary-compiler
- name: Test binary
# exclude windows
if: matrix.os != 'windows-latest'
run: npm run test-run
working-directory: ./publish/binary-compiler
run: yarn ci -v

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"workspaces": [
"packages/*",
"packages/@secretlint/*",
"publish/binary-compiler",
"examples/*"
],
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/@secretlint/profiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
".": {
"import": {
"types": "./module/node.d.ts",
"browser": "./module/browser.js",
"default": "./module/node.js"
},
"default": "./module/node.js"
Expand Down
8 changes: 7 additions & 1 deletion packages/@secretlint/profiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ export type SecretLintProfilerMarker =
export type Constructor<I> = {
new (...args: any[]): I;
};
export type LimitedPerformanceObserver = Constructor<{
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceObserver/disconnect) */
disconnect(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceObserver/observe) */
observe(options?: any): void;
}>;
export type SecretLintProfilerOptions = {
perf: Performance;
PerformanceObserver: any;
PerformanceObserver: LimitedPerformanceObserver;
};

export class SecretLintProfiler {
Expand Down
7 changes: 6 additions & 1 deletion packages/@secretlint/profiler/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { SecretLintProfiler } from "./index.js";
import perf_hooks from "node:perf_hooks";

export { SecretLintProfiler };
class NullPerformanceObserver {
disconnect(): void {}
observe(_options?: PerformanceObserverInit | undefined): void {}
}

export const secretLintProfiler = new SecretLintProfiler({
perf: perf_hooks.performance,
PerformanceObserver: perf_hooks.PerformanceObserver,
PerformanceObserver: perf_hooks.PerformanceObserver ? perf_hooks.PerformanceObserver : NullPerformanceObserver,
});
2 changes: 0 additions & 2 deletions publish/binary-compiler/.npmrc

This file was deleted.

11 changes: 7 additions & 4 deletions publish/binary-compiler/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# @secretlint/binary-compiler

Single executable binary compiler for secretlint using [Bun](https://bun.sh/).

- [Single-file executable – Runtime | Bun Docs](https://bun.sh/docs/bundler/executables)
Single executable binary compiler for secretlint using [Deno](https://deno.land/).

## CURRENT PROBLEM

Expand All @@ -11,10 +9,15 @@ Single executable binary compiler for secretlint using [Bun](https://bun.sh/).
## Usage

```
npm run build
npm run dist
./dist/secretlint --help
```

## Built-in

- Recommended Rules
- @secretlint/secretlint-formatter-sarif

## Changelog

See [Releases page](https://github.com/secretlint/secretlint/releases).
Expand Down
20 changes: 20 additions & 0 deletions publish/binary-compiler/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
# cross compile using deno
# --target <target>
# Target OS architecture
#
# [possible values: x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc, x86_64-apple-darwin, aarch64-apple-darwin]

distDir="dist"
binaryName="secretlint"
secretlintVersion=$(jq -r .version ../../lerna.json)
platforms=("x86_64-unknown-linux-gnu" "x86_64-pc-windows-msvc" "x86_64-apple-darwin" "aarch64-apple-darwin")
# read lerna.json's version
for ((i=0; i<${#platforms[@]}; ++i));
do
echo "Building for ${platforms[$i]}"
# secretlint-{version}-{platform}
outputFilePath="${distDir}/${binaryName}-${secretlintVersion}-${platforms[$i]}"
deno compile --no-lock --allow-read --allow-sys --allow-env --allow-write --target "${platforms[$i]}" --output "$outputFilePath" src/entry.ts
done
5 changes: 5 additions & 0 deletions publish/binary-compiler/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"dev": "deno run --no-lock --allow-read --allow-sys --allow-env src/entry.ts \"**/*\""
}
}
55 changes: 0 additions & 55 deletions publish/binary-compiler/package.json

This file was deleted.

12 changes: 8 additions & 4 deletions publish/binary-compiler/src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// preload for embeded binary
import { cli, run } from "secretlint/cli";
// preload for embedded binary
// TODO: use local file path instead of npm registry
// https://github.com/denoland/deno/issues/18474
import "npm:@secretlint/secretlint-rule-preset-recommend";
import "npm:@secretlint/secretlint-formatter-sarif";
import { cli, run } from "npm:secretlint/cli";
run(cli.input, cli.flags).then(
({ exitStatus, stderr, stdout }) => {
if (stdout) {
Expand All @@ -8,10 +12,10 @@ run(cli.input, cli.flags).then(
if (stderr) {
console.error(stderr);
}
process.exit(exitStatus);
Deno.exit(exitStatus);
},
(error) => {
console.error(error);
process.exit(1);
Deno.exit(1);
}
);
11 changes: 0 additions & 11 deletions publish/binary-compiler/test/tsconfig.json

This file was deleted.

0 comments on commit cebbe6d

Please sign in to comment.