Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI

on:
push:
pull_request:

jobs:
quality:
name: Quality checks (Node ${{ matrix.node }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ["20.x", "24.x"]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm run lint

- name: Typecheck
run: pnpm run typecheck

- name: Unit tests
run: pnpm run test:unit

- name: Integration tests
run: pnpm run test:integration

- name: Build package
run: pnpm run build

- name: Ensure bundled LAME binary
env:
LAME_FORCE_DOWNLOAD: "1"
run: node ./scripts/install-lame.mjs

- name: Diagnose bundled LAME binary
run: node ./scripts/diagnose-lame.mjs

- name: Run examples
run: |
pnpm run example:wav-to-mp3
pnpm run example:mp3-to-wav
pnpm run example:stream

postinstall:
name: LAME install on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: quality
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

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

- name: Install dependencies (runs postinstall)
env:
LAME_FORCE_DOWNLOAD: "1"
run: pnpm install --frozen-lockfile
91 changes: 91 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Prepare Release

on:
workflow_run:
workflows: ["CI"]
types:
- completed

jobs:
version:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'master' &&
!startsWith(github.event.workflow_run.head_commit.message, 'chore(release)')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_commit.id }}
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v4

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

- name: Install dependencies
env:
LAME_SKIP_DOWNLOAD: "1"
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm run lint

- name: Typecheck
run: pnpm run typecheck

- name: Unit tests
run: pnpm run test:unit

- name: Integration tests
run: pnpm run test:integration

- name: Determine changelog mode
id: changelog
run: |
git fetch --tags --force >/dev/null 2>&1 || true
if git rev-parse "v2.0.0" >/dev/null 2>&1; then
echo "skip=0" >> "$GITHUB_OUTPUT"
else
echo "skip=1" >> "$GITHUB_OUTPUT"
fi

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Bump version and changelog
id: version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SKIP_CHANGELOG: ${{ steps.changelog.outputs.skip }}
run: |
set -eo pipefail
pnpm run release:version > version.log 2>&1 || STATUS=$?
cat version.log
if [ -n "$STATUS" ]; then
if grep -q "No changed packages" version.log; then
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
exit "$STATUS"
fi
NEW_VERSION=$(node -p "require('./package.json').version")
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"

- name: Push release commit and tags
if: steps.version.outputs.skip != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push --follow-tags
143 changes: 143 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Release

on:
workflow_run:
workflows: ["CI"]
types:
- completed

jobs:
build-binaries:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'master' &&
startsWith(github.event.workflow_run.head_commit.message, 'chore(release)')
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- platform: linux
arch: x64
binary: vendor/lame/linux-x64/lame
- platform: darwin
arch: arm64
binary: vendor/lame/darwin-arm64/lame
- platform: win32
arch: x64
binary: vendor/lame/win32-x64/lame.exe
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_commit.id }}
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v4

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

- name: Install dependencies
env:
LAME_SKIP_DOWNLOAD: "1"
run: pnpm install --frozen-lockfile

- name: Download LAME binary for ${{ matrix.platform }}-${{ matrix.arch }}
env:
NODE_LAME_PLATFORM: ${{ matrix.platform }}
NODE_LAME_ARCH: ${{ matrix.arch }}
LAME_FORCE_DOWNLOAD: "1"
run: node scripts/install-lame.mjs

- name: Package binary
run: node scripts/package-lame.mjs --binary "${{ matrix.binary }}" --platform "${{ matrix.platform }}" --arch "${{ matrix.arch }}" --out-dir artifacts

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: lame-${{ matrix.platform }}-${{ matrix.arch }}
path: artifacts

publish:
needs: build-binaries
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'master' &&
startsWith(github.event.workflow_run.head_commit.message, 'chore(release)')
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_commit.id }}
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: pnpm
registry-url: https://registry.npmjs.org

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Unpack binaries into vendor directory
run: node scripts/unpack-lame-artifacts.mjs artifacts vendor/lame

- name: Build package
run: pnpm run build

- name: Prepare release assets
run: |
set -eo pipefail
VERSION=$(node -p "require('./package.json').version")
ASSET_DIR="$PWD/release-assets"
mkdir -p "$ASSET_DIR"
while IFS= read -r manifest; do
base=$(basename "$manifest" .json)
src_dir="vendor/lame/$base"
if [ ! -d "$src_dir" ]; then
echo "Skipping $base - no vendor directory"
continue
fi
tmp_dir=$(mktemp -d)
cp "$src_dir"/* "$tmp_dir/"
cp "$manifest" "$tmp_dir/manifest.json"
(cd "$tmp_dir" && zip -qr "$ASSET_DIR/node-lame-v${VERSION}-${base}.zip" .)
rm -rf "$tmp_dir"
done < <(find artifacts -maxdepth 3 -name '*.json')
zip -qr "$ASSET_DIR/node-lame-v${VERSION}-dist.zip" dist

- name: Publish release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pnpm run release:publish

- name: Upload assets to GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(node -p "require('./package.json').version")
TAG="v${VERSION}"
gh release upload "$TAG" release-assets/*.zip --clobber
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pids
.lock-wscript

# Dependency directories
node_modules
node_modules/
vendor/

# Lib dependencies
bin/*
Expand All @@ -28,9 +29,16 @@ ehthumbs.db
Icon?
Thumbs.db

# Builds
dist/

# IDE
.vscode/*
.idea/*

# Test
test/encoded.mp3
coverage/
coverage-unit.json

# Examples
examples/audios/example.*.*
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm commitlint --edit "$1"
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pnpm run lint
pnpm run test:unit
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
dist/
coverage/
vendor/
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"tabWidth": 4
"tabWidth": 4
}
Loading