mirror of
https://github.com/LukeHagar/prettier-plugin-openapi.git
synced 2025-12-06 04:21:03 +00:00
Add ESLint and Prettier configuration files, update .gitignore and .npmignore, and enhance CI/CD workflows with testing and release automation
This commit is contained in:
61
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
61
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a bug with the Prettier OpenAPI plugin
|
||||
title: '[BUG] '
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is with the Prettier OpenAPI plugin.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Create an OpenAPI file with the following content:
|
||||
```yaml
|
||||
# or JSON
|
||||
```
|
||||
2. Run Prettier with the plugin: `npx prettier --plugin=prettier-plugin-openapi your-file.yaml`
|
||||
3. See the formatting issue
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of how the OpenAPI file should be formatted.
|
||||
|
||||
**OpenAPI file example**
|
||||
Please provide a minimal OpenAPI file that demonstrates the issue:
|
||||
|
||||
```yaml
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Test API
|
||||
version: 1.0.0
|
||||
# ... rest of your OpenAPI content
|
||||
```
|
||||
|
||||
**Prettier configuration**
|
||||
Please share your `.prettierrc` or Prettier configuration:
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["prettier-plugin-openapi"],
|
||||
"tabWidth": 2,
|
||||
"printWidth": 80
|
||||
}
|
||||
```
|
||||
|
||||
**Environment (please complete the following information):**
|
||||
- OS: [e.g. macOS, Windows, Linux]
|
||||
- Node.js version: [e.g. 18.0.0]
|
||||
- Prettier version: [e.g. 3.0.0]
|
||||
- Plugin version: [e.g. 1.0.0]
|
||||
- OpenAPI version: [e.g. 3.0.0, 2.0]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here. Include:
|
||||
- Whether this affects JSON or YAML files (or both)
|
||||
- If it's related to key ordering, formatting, or parsing
|
||||
- Any error messages from the console
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots showing the before/after formatting to help explain the problem.
|
||||
46
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
46
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for the Prettier OpenAPI plugin
|
||||
title: '[FEATURE] '
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is with OpenAPI file formatting. Ex. I'm always frustrated when the plugin doesn't handle [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what formatting behavior you want the plugin to have.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative formatting approaches you've considered.
|
||||
|
||||
**Use case**
|
||||
Describe the specific OpenAPI formatting use case for this feature. How would it help you or other users format their OpenAPI files?
|
||||
|
||||
**OpenAPI specification**
|
||||
If this feature relates to a specific OpenAPI specification version or feature, please mention it:
|
||||
- OpenAPI 2.0 (Swagger)
|
||||
- OpenAPI 3.0.x
|
||||
- OpenAPI 3.1.x
|
||||
- Specific OpenAPI features (components, security schemes, etc.)
|
||||
|
||||
**Example OpenAPI content**
|
||||
If applicable, provide an example of the OpenAPI content that would benefit from this feature:
|
||||
|
||||
```yaml
|
||||
# Your OpenAPI example here
|
||||
```
|
||||
|
||||
**Current behavior**
|
||||
Describe how the plugin currently handles this content.
|
||||
|
||||
**Desired behavior**
|
||||
Describe how you would like the plugin to format this content.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here. Include:
|
||||
- Whether this affects JSON or YAML files (or both)
|
||||
- If it's related to key ordering, indentation, or other formatting aspects
|
||||
- Any specific OpenAPI tooling or workflow this would improve
|
||||
27
.github/pull_request_template.md
vendored
Normal file
27
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
## Description
|
||||
|
||||
Brief description of the changes in this PR.
|
||||
|
||||
## Type of Change
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] Documentation update
|
||||
- [ ] Performance improvement
|
||||
- [ ] Code refactoring
|
||||
|
||||
## Testing
|
||||
|
||||
- [ ] New tests added for new functionality
|
||||
- [ ] Existing tests updated if needed
|
||||
- [ ] Manual testing completed
|
||||
- [ ] Tests pass locally
|
||||
|
||||
## Related Issues
|
||||
|
||||
Fixes #(issue number)
|
||||
|
||||
## Additional Notes
|
||||
|
||||
Any additional information that reviewers should know.
|
||||
168
.github/workflows/ci.yml
vendored
Normal file
168
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
name: CI/CD Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
pull_request:
|
||||
branches: [ main, develop ]
|
||||
release:
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18, 20, 21]
|
||||
bun-version: [1.0.0, latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: Setup Bun ${{ matrix.bun-version }}
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: ${{ matrix.bun-version }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Run linting
|
||||
run: bun run lint
|
||||
|
||||
- name: Run type checking
|
||||
run: bun run type-check
|
||||
|
||||
- name: Run tests
|
||||
run: bun run test
|
||||
|
||||
- name: Run test coverage
|
||||
run: bun run test:coverage
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
file: ./coverage/lcov.info
|
||||
flags: unittests
|
||||
name: codecov-umbrella
|
||||
fail_ci_if_error: false
|
||||
|
||||
build:
|
||||
name: Build Package
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Build package
|
||||
run: bun run build
|
||||
|
||||
- name: Verify build output
|
||||
run: |
|
||||
ls -la dist/
|
||||
node -e "console.log('Build verification:', require('./dist/index.js'))"
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist-files
|
||||
path: dist/
|
||||
retention-days: 30
|
||||
|
||||
publish:
|
||||
name: Publish to NPM
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test, build]
|
||||
if: github.event_name == 'release' && github.event.action == 'published'
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Build package
|
||||
run: bun run build
|
||||
|
||||
- name: Publish to NPM
|
||||
run: bun run publish:package
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.event.release.tag_name }}
|
||||
release_name: ${{ github.event.release.name }}
|
||||
body: ${{ github.event.release.body }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
security:
|
||||
name: Security Audit
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Run security audit
|
||||
run: bun audit
|
||||
|
||||
- name: Run Snyk security scan
|
||||
uses: snyk/actions/node@master
|
||||
env:
|
||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
with:
|
||||
args: --severity-threshold=high
|
||||
144
.github/workflows/release.yml
vendored
Normal file
144
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Publish Release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Run tests
|
||||
run: bun run test
|
||||
|
||||
- name: Run linting
|
||||
run: bun run lint
|
||||
|
||||
- name: Build package
|
||||
run: bun run build
|
||||
|
||||
- name: Get current version
|
||||
id: current-version
|
||||
run: |
|
||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "tag=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check if version exists on NPM
|
||||
id: version-check
|
||||
run: |
|
||||
VERSION=${{ steps.current-version.outputs.version }}
|
||||
if npm view prettier-plugin-openapi@$VERSION version >/dev/null 2>&1; then
|
||||
echo "exists=true" >> $GITHUB_OUTPUT
|
||||
echo "Version $VERSION already exists on NPM"
|
||||
else
|
||||
echo "exists=false" >> $GITHUB_OUTPUT
|
||||
echo "Version $VERSION does not exist on NPM"
|
||||
fi
|
||||
|
||||
- name: Bump patch version if needed
|
||||
id: bump-version
|
||||
if: steps.version-check.outputs.exists == 'true'
|
||||
run: |
|
||||
npm version patch --no-git-tag-version
|
||||
NEW_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "bumped=true" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Set final version
|
||||
id: final-version
|
||||
run: |
|
||||
if [ "${{ steps.bump-version.outputs.bumped }}" = "true" ]; then
|
||||
echo "version=${{ steps.bump-version.outputs.version }}" >> $GITHUB_OUTPUT
|
||||
echo "tag=${{ steps.bump-version.outputs.tag }}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "version=${{ steps.current-version.outputs.version }}" >> $GITHUB_OUTPUT
|
||||
echo "tag=${{ steps.current-version.outputs.tag }}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Generate release message
|
||||
id: release-message
|
||||
run: |
|
||||
if [ "${{ steps.bump-version.outputs.bumped }}" = "true" ]; then
|
||||
COMMIT_MSG=$(git log -1 --pretty=format:"%s")
|
||||
echo "message=Automated patch release: $COMMIT_MSG" >> $GITHUB_OUTPUT
|
||||
else
|
||||
COMMIT_MSG=$(git log -1 --pretty=format:"%s")
|
||||
echo "message=Release: $COMMIT_MSG" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Commit version bump if needed
|
||||
if: steps.bump-version.outputs.bumped == 'true'
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git add package.json
|
||||
git commit -m "chore: bump version to ${{ steps.bump-version.outputs.version }}"
|
||||
|
||||
- name: Create tag
|
||||
run: |
|
||||
git tag ${{ steps.final-version.outputs.tag }}
|
||||
|
||||
- name: Push changes and tag
|
||||
run: |
|
||||
git push origin main
|
||||
git push origin ${{ steps.final-version.outputs.tag }}
|
||||
|
||||
- name: Publish to NPM
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Create Release
|
||||
uses: elgohr/Github-Release-Action@v5
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.final-version.outputs.tag }}
|
||||
name: Release ${{ steps.final-version.outputs.tag }}
|
||||
body: |
|
||||
## Release ${{ steps.final-version.outputs.version }}
|
||||
|
||||
${{ steps.release-message.outputs.message }}
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install prettier-plugin-openapi@${{ steps.final-version.outputs.version }}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Add to your `.prettierrc`:
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["prettier-plugin-openapi"]
|
||||
}
|
||||
```
|
||||
draft: false
|
||||
prerelease: false
|
||||
Reference in New Issue
Block a user