mirror of
https://github.com/LukeHagar/prettier-plugin-openapi.git
synced 2025-12-06 04:21:03 +00:00
143 lines
4.3 KiB
YAML
143 lines
4.3 KiB
YAML
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'
|
|
|
|
- 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 |