Skip to content

chore: setup release pipeline and formatting #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 27, 2025
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
31 changes: 31 additions & 0 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Conventional Commits

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
conventional-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}

- name: Setup Git
run: |
git config --global user.name "Conventional Changelog Action"
git config --global user.email "[email protected]"
git checkout ${{ github.head_ref }}

- name: Conventional Commits
uses: TriPSs/conventional-changelog-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version-file: './package/package.json'
skip-version-file: false
skip-commit: false
skip-tag: false
release-count: 0
output-file: 'CHANGELOG.md'
74 changes: 74 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: PR Checks

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main
- 'feature/**'
- 'fix/**'
- 'chore/**'
- 'docs/**'

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'package/package-lock.json'

- name: Install dependencies
working-directory: ./package
run: npm ci

- name: Run tests
working-directory: ./package
run: npm test

validate:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'package/package-lock.json'

- name: Install dependencies
working-directory: ./package
run: npm ci

- name: Format code
id: format
working-directory: ./package
run: npm run format

- name: Commit formatting changes
if: success()
working-directory: ./package
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git diff --quiet && git diff --staged --quiet || (git commit -m "style: format code" && git push)

- name: Type check
id: type-check
working-directory: ./package
run: npm run type-check || (echo "TypeScript errors found" && exit 1)
35 changes: 18 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
name: Publish to npm
name: Publish Package

on:
push:
tags:
- "v*" # Trigger only on tags that start with 'v', e.g., v1.0.0
release:
types: [created]

jobs:
publish:
build:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Install dependencies
working-directory: ./package
run: npm install
run: npm ci

- name: Publish to npm
working-directory: ./package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Run tests
run: npm test

- name: Build
run: npm run build

- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.SHNIPPET_NPM_TOKEN }}
19 changes: 19 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Build output
dist/
build/

# Dependencies
node_modules/

# Snippets
snippet/

# Coverage
coverage/

# Logs
*.log

# Cache
.cache/
.npm/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
81 changes: 81 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Contributing to Shnippet

Thank you for your interest in contributing to Shnippet! This document provides guidelines and instructions for contributing.

## Development Setup

1. Fork the repository
2. Clone your fork:
```bash
git clone https://github.com/YOUR_USERNAME/shnippet.git
cd shnippet
```
3. Install dependencies:
```bash
npm install
```

## Branch Strategy

We use the following branch naming conventions:

- `main` - Production-ready code
- `feature/*` - New features (e.g., `feature/add-new-language`)
- `fix/*` - Bug fixes (e.g., `fix/parser-error`)
- `chore/*` - Maintenance tasks (e.g., `chore/update-deps`)
- `docs/*` - Documentation updates (e.g., `docs/update-readme`)

## Commit Convention

We follow the [Conventional Commits](https://www.conventionalcommits.org/) specification:

- `feat:` - New features
- `fix:` - Bug fixes
- `docs:` - Documentation changes
- `style:` - Code style changes (formatting, etc.)
- `refactor:` - Code refactoring
- `test:` - Adding or modifying tests
- `chore:` - Maintenance tasks

Example:
```
feat: add support for Python language
fix: handle empty file edge case
docs: update installation instructions
```

## Pull Request Process

1. Create a new branch from `main` using the appropriate prefix
2. Make your changes
3. Run tests locally:
```bash
npm test
```
4. Push your branch and create a Pull Request
5. Ensure all status checks pass:
- Tests
- Type checking

## Code Style

- We use TypeScript for type safety
- All tests must pass
- All TypeScript errors must be resolved

## Release Process

Releases are automated through GitHub Actions. When a PR is merged to `main`:

1. The conventional commits workflow will:
- Update the changelog
- Update the version number
- Create a git tag
2. The publish workflow will:
- Run all tests
- Build the package
- Publish to npm

## Questions?

Feel free to open an issue if you have any questions about contributing!
46 changes: 23 additions & 23 deletions package/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ await rimraf('dist');

// Build Node.js bundle
await build({
entryPoints: ['src/index.ts', 'src/bin/cli.ts'],
bundle: true,
platform: 'node',
target: 'node18',
format: 'esm',
outdir: 'dist',
outExtension: { '.js': '.js' },
external: ['rimraf'],
banner: {
js: '#!/usr/bin/env node\n'
},
sourcemap: true,
minify: false
entryPoints: ['src/index.ts', 'src/bin/cli.ts'],
bundle: true,
platform: 'node',
target: 'node18',
format: 'esm',
outdir: 'dist',
outExtension: { '.js': '.js' },
external: ['rimraf'],
banner: {
js: '#!/usr/bin/env node\n',
},
sourcemap: true,
minify: false,
});

// Build client-side bundle
await build({
entryPoints: ['src/client.ts'],
bundle: true,
platform: 'browser',
target: ['es2020'],
format: 'esm',
outdir: 'dist',
outExtension: { '.js': '.browser.js' },
sourcemap: true,
minify: true,
globalName: 'Shnippet'
entryPoints: ['src/client.ts'],
bundle: true,
platform: 'browser',
target: ['es2020'],
format: 'esm',
outdir: 'dist',
outExtension: { '.js': '.browser.js' },
sourcemap: true,
minify: true,
globalName: 'Shnippet',
});
Loading