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
41 changes: 41 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PR Validation

on:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build-validation:
name: Build Validation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Build NPM package
run: deno run -A scripts/build_npm.ts

- name: Verify NPM package structure
run: |
test -f npm/package.json
test -d npm/esm
test -d npm/script

- name: Test NPM package can be imported
working-directory: npm
run: |
npm install
node -e "const contrastrast = require('./script/mod.js'); console.log('NPM package import successful')"

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: npm-package
path: npm/
retention-days: 7
84 changes: 84 additions & 0 deletions .github/workflows/publish-jsr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Publish to JSR

on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Tag to publish (e.g., v1.0.0)"
required: true
type: string

jobs:
validate:
name: Pre-publish Validation
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.tag }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Publishing version: ${VERSION}"

- name: Verify version in deno.json matches tag
run: |
DENO_VERSION=$(jq -r '.version' deno.json)
TAG_VERSION="${{ steps.version.outputs.version }}"
TAG_VERSION_CLEAN="${TAG_VERSION#v}"

if [ "$DENO_VERSION" != "$TAG_VERSION_CLEAN" ]; then
echo "Error: Version mismatch!"
echo "deno.json version: $DENO_VERSION"
echo "Tag version: $TAG_VERSION_CLEAN"
exit 1
fi

- name: Run quality checks
run: |
deno fmt --check
deno lint
deno test

publish:
name: Publish to JSR
runs-on: ubuntu-latest
needs: validate
environment: publishing
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Publish to JSR
env:
JSR_TOKEN: ${{ secrets.JSR_TOKEN }}
run: deno publish

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.validate.outputs.version }}
name: Release ${{ needs.validate.outputs.version }}
generate_release_notes: true
draft: false
prerelease: ${{ contains(needs.validate.outputs.version, '-') }}
122 changes: 122 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Publish to NPM

on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Tag to publish (e.g., v1.0.0)"
required: true
type: string

jobs:
validate:
name: Pre-publish Validation
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.tag }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Publishing version: ${VERSION}"

- name: Verify version in deno.json matches tag
run: |
DENO_VERSION=$(jq -r '.version' deno.json)
TAG_VERSION="${{ steps.version.outputs.version }}"
TAG_VERSION_CLEAN="${TAG_VERSION#v}"

if [ "$DENO_VERSION" != "$TAG_VERSION_CLEAN" ]; then
echo "Error: Version mismatch!"
echo "deno.json version: $DENO_VERSION"
echo "Tag version: $TAG_VERSION_CLEAN"
exit 1
fi

- name: Run quality checks
run: |
deno fmt --check
deno lint
deno test

build-and-publish:
name: Build and Publish to NPM
runs-on: ubuntu-latest
needs: validate
environment: publishing
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
registry-url: "https://registry.npmjs.org"

- name: Build NPM package with dnt
run: deno run -A scripts/build_npm.ts

- name: Verify NPM package version matches tag
run: |
NPM_VERSION=$(jq -r '.version' npm/package.json)
TAG_VERSION="${{ needs.validate.outputs.version }}"
TAG_VERSION_CLEAN="${TAG_VERSION#v}"

if [ "$NPM_VERSION" != "$TAG_VERSION_CLEAN" ]; then
echo "Error: NPM package version mismatch!"
echo "npm/package.json version: $NPM_VERSION"
echo "Tag version: $TAG_VERSION_CLEAN"
exit 1
fi

- name: Verify package structure
run: |
test -f npm/package.json
test -d npm/esm
test -d npm/script
test -f npm/LICENSE
test -f npm/README.md

- name: Test NPM package imports
working-directory: npm
run: |
# Test CommonJS import
node -e "const contrastrast = require('./script/mod.js'); console.log('CommonJS import successful:', typeof contrastrast);"

# Test ESM import
node -e "import('./esm/mod.js').then(m => console.log('ESM import successful:', typeof m.default || typeof m));"

- name: Publish to NPM
working-directory: npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [[ "${{ needs.validate.outputs.version }}" == *"-"* ]]; then
echo "Publishing non-stable release with beta tag"
npm publish --tag beta
else
echo "Publishing stable release"
npm publish
fi
52 changes: 52 additions & 0 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Quality Checks

on:
pull_request:
workflow_dispatch:

jobs:
format:
name: Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Check formatting
run: deno fmt --check

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Run linter
run: deno lint

test:
name: Test w/ Deno
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Run tests
run: deno test
Loading