mirror of
https://github.com/LukeHagar/prettier-plugin-openapi.git
synced 2025-12-06 12:47:47 +00:00
Update CI/CD workflows to streamline processes, adjust permissions, and enhance build and release steps. Modify biome.json to turn off console warnings.
This commit is contained in:
175
.github/workflows/ci.yml
vendored
175
.github/workflows/ci.yml
vendored
@@ -1,135 +1,58 @@
|
|||||||
name: CI/CD Pipeline
|
name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
branches: [ main, develop ]
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main, develop ]
|
branches: [ main ]
|
||||||
release:
|
push:
|
||||||
types: [ published ]
|
branches: [ main ]
|
||||||
|
|
||||||
|
# Cancel superseded PR runs when the PR is updated
|
||||||
|
concurrency:
|
||||||
|
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build-test:
|
||||||
name: Test Suite
|
name: Build & Test
|
||||||
runs-on: ubuntu-latest
|
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 }}
|
|
||||||
|
|
||||||
- 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:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
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: 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: Use Node 20
|
||||||
name: Publish to NPM
|
uses: actions/setup-node@v4
|
||||||
runs-on: ubuntu-latest
|
with:
|
||||||
needs: [test, build]
|
node-version: 20
|
||||||
if: github.event_name == 'release' && github.event.action == 'published'
|
cache: npm
|
||||||
|
|
||||||
steps:
|
- name: Setup Bun
|
||||||
- name: Checkout code
|
uses: oven-sh/setup-bun@v1
|
||||||
uses: actions/checkout@v4
|
with:
|
||||||
|
bun-version: latest
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
- name: Install
|
||||||
with:
|
run: bun install --frozen-lockfile
|
||||||
node-version: '20'
|
|
||||||
registry-url: 'https://registry.npmjs.org'
|
- name: Lint
|
||||||
|
run: bun run lint
|
||||||
- name: Setup Bun
|
continue-on-error: false
|
||||||
uses: oven-sh/setup-bun@v1
|
|
||||||
with:
|
- name: Typecheck
|
||||||
bun-version: latest
|
run: bun run type-check
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Test
|
||||||
run: bun install --frozen-lockfile
|
run: bun run test
|
||||||
|
|
||||||
- name: Build package
|
- name: Build
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|
||||||
- name: Publish to NPM
|
- name: Upload coverage to Codecov
|
||||||
run: bun run publish:package
|
uses: codecov/codecov-action@v3
|
||||||
env:
|
with:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
file: ./coverage/lcov.info
|
||||||
|
flags: unittests
|
||||||
- name: Create GitHub Release
|
name: codecov-umbrella
|
||||||
uses: actions/create-release@v1
|
fail_ci_if_error: false
|
||||||
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
|
|
||||||
|
|||||||
265
.github/workflows/release.yml
vendored
265
.github/workflows/release.yml
vendored
@@ -1,143 +1,140 @@
|
|||||||
name: Release
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_run:
|
||||||
branches:
|
workflows: ["CI"] # Must match the CI workflow name exactly
|
||||||
- main
|
types: [completed]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write # Needed to create tags/releases
|
||||||
|
packages: write # If you also publish GitHub Packages
|
||||||
|
id-token: write # Optional (for OIDC to cloud registries)
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
publish-and-release:
|
||||||
name: Publish Release
|
# Only proceed if:
|
||||||
|
# 1) CI concluded successfully
|
||||||
|
# 2) The run was triggered by a push (not a PR)
|
||||||
|
# 3) The branch is main
|
||||||
|
# 4) The run belongs to this repository (not a fork)
|
||||||
|
if: >
|
||||||
|
github.event.workflow_run.conclusion == 'success' &&
|
||||||
|
github.event.workflow_run.event == 'push' &&
|
||||||
|
github.event.workflow_run.head_branch == 'main' &&
|
||||||
|
github.event.workflow_run.head_repository.full_name == github.repository
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
# Check out the exact commit that passed CI
|
||||||
uses: actions/checkout@v4
|
- name: Checkout the successful commit
|
||||||
with:
|
uses: actions/checkout@v4
|
||||||
fetch-depth: 0
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
ref: ${{ github.event.workflow_run.head_sha }}
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Use Node 20
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: 20
|
||||||
|
cache: npm
|
||||||
- name: Setup Bun
|
registry-url: https://registry.npmjs.org/
|
||||||
uses: oven-sh/setup-bun@v1
|
|
||||||
with:
|
- name: Setup Bun
|
||||||
bun-version: latest
|
uses: oven-sh/setup-bun@v1
|
||||||
|
with:
|
||||||
- name: Install dependencies
|
bun-version: latest
|
||||||
run: bun install --frozen-lockfile
|
|
||||||
|
- name: Install
|
||||||
- name: Run tests
|
run: bun install --frozen-lockfile
|
||||||
run: bun run test
|
|
||||||
|
# Optional: Re-run build to ensure publish artifacts exist
|
||||||
- name: Run linting
|
- name: Build
|
||||||
run: bun run lint
|
run: bun run build
|
||||||
|
|
||||||
- name: Build package
|
# Read current version from package.json
|
||||||
run: bun run build
|
- name: Read current version
|
||||||
|
id: current-version
|
||||||
- name: Get current version
|
shell: bash
|
||||||
id: current-version
|
run: |
|
||||||
run: |
|
ver=$(node -p "require('./package.json').version")
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
echo "version=$ver" >> "$GITHUB_OUTPUT"
|
||||||
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "tag=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
# Check if version was already bumped in this commit
|
||||||
|
- name: Check if version was bumped
|
||||||
- name: Check if version exists on NPM
|
id: version-check
|
||||||
id: version-check
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ steps.current-version.outputs.version }}
|
# Get the previous commit's version
|
||||||
if npm view prettier-plugin-openapi@$VERSION version >/dev/null 2>&1; then
|
PREV_VERSION=$(git show HEAD~1:package.json 2>/dev/null | node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0")
|
||||||
echo "exists=true" >> $GITHUB_OUTPUT
|
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
|
||||||
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 }}
|
echo "Previous version: $PREV_VERSION"
|
||||||
|
echo "Current version: $CURRENT_VERSION"
|
||||||
|
|
||||||
## Installation
|
if [ "$PREV_VERSION" != "$CURRENT_VERSION" ]; then
|
||||||
|
echo "Version was already bumped from $PREV_VERSION to $CURRENT_VERSION"
|
||||||
```bash
|
echo "bumped=false" >> "$GITHUB_OUTPUT"
|
||||||
npm install prettier-plugin-openapi@${{ steps.final-version.outputs.version }}
|
echo "final_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
```
|
else
|
||||||
|
echo "No version bump detected, will auto-patch bump"
|
||||||
## Usage
|
echo "bumped=true" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
Add to your `.prettierrc`:
|
|
||||||
|
# Auto-patch bump version if no version change was made
|
||||||
```json
|
- name: Auto-patch bump version
|
||||||
{
|
if: steps.version-check.outputs.bumped == 'true'
|
||||||
"plugins": ["prettier-plugin-openapi"]
|
id: bump-version
|
||||||
}
|
shell: bash
|
||||||
```
|
run: |
|
||||||
draft: false
|
npm version patch --no-git-tag-version
|
||||||
prerelease: false
|
NEW_VERSION=$(node -p "require('./package.json').version")
|
||||||
|
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Auto-bumped version to $NEW_VERSION"
|
||||||
|
|
||||||
|
# Set final version
|
||||||
|
- name: Set final version
|
||||||
|
id: final-version
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ "${{ steps.version-check.outputs.bumped }}" = "true" ]; then
|
||||||
|
echo "version=${{ steps.bump-version.outputs.version }}" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "version=${{ steps.current-version.outputs.version }}" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Commit version bump if auto-bumped
|
||||||
|
- name: Commit auto-bumped version
|
||||||
|
if: steps.version-check.outputs.bumped == 'true'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git config --local user.email "action@github.com"
|
||||||
|
git config --local user.name "GitHub Action"
|
||||||
|
git add package.json
|
||||||
|
git commit -m "chore: auto-bump version to ${{ steps.bump-version.outputs.version }}"
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
# Create a git tag like v1.2.3 if it doesn't already exist
|
||||||
|
- name: Create tag if missing
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
TAG="v${{ steps.final-version.outputs.version }}"
|
||||||
|
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||||
|
echo "Tag $TAG already exists."
|
||||||
|
else
|
||||||
|
git tag "$TAG" ${{ github.event.workflow_run.head_sha }}
|
||||||
|
git push origin "$TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Publish to npm (requires NPM_TOKEN in repo secrets)
|
||||||
|
- name: Publish to npm
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
run: npm publish --access public
|
||||||
|
|
||||||
|
# Create a GitHub Release for the tag
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: v${{ steps.final-version.outputs.version }}
|
||||||
|
name: v${{ steps.final-version.outputs.version }}
|
||||||
|
generate_release_notes: true
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
"useConst": "error"
|
"useConst": "error"
|
||||||
},
|
},
|
||||||
"suspicious": {
|
"suspicious": {
|
||||||
"noConsole": "warn",
|
"noConsole": "off",
|
||||||
"noVar": "error"
|
"noVar": "error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user