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:
Luke Hagar
2025-09-26 14:46:52 +00:00
parent 723640e9d0
commit 16b154098f
3 changed files with 181 additions and 261 deletions

View File

@@ -1,50 +1,53 @@
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: steps:
- name: Checkout code - uses: actions/checkout@v4
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }} - name: Use Node 20
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: ${{ matrix.node-version }} node-version: 20
cache: npm
- name: Setup Bun ${{ matrix.bun-version }} - name: Setup Bun
uses: oven-sh/setup-bun@v1 uses: oven-sh/setup-bun@v1
with: with:
bun-version: ${{ matrix.bun-version }} bun-version: latest
- name: Install dependencies - name: Install
run: bun install --frozen-lockfile run: bun install --frozen-lockfile
- name: Run linting - name: Lint
run: bun run lint run: bun run lint
continue-on-error: false
- name: Run type checking - name: Typecheck
run: bun run type-check run: bun run type-check
- name: Run tests - name: Test
run: bun run test run: bun run test
- name: Run test coverage - name: Build
run: bun run test:coverage run: bun run build
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: codecov/codecov-action@v3 uses: codecov/codecov-action@v3
@@ -53,83 +56,3 @@ jobs:
flags: unittests flags: unittests
name: codecov-umbrella name: codecov-umbrella
fail_ci_if_error: false 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'
- 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

View File

@@ -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
- name: Checkout the successful commit
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 ref: ${{ github.event.workflow_run.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- 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
registry-url: https://registry.npmjs.org/
- name: Setup Bun - name: Setup Bun
uses: oven-sh/setup-bun@v1 uses: oven-sh/setup-bun@v1
with: with:
bun-version: latest bun-version: latest
- name: Install dependencies - name: Install
run: bun install --frozen-lockfile run: bun install --frozen-lockfile
- name: Run tests # Optional: Re-run build to ensure publish artifacts exist
run: bun run test - name: Build
- name: Run linting
run: bun run lint
- name: Build package
run: bun run build run: bun run build
- name: Get current version # Read current version from package.json
- name: Read current version
id: current-version id: current-version
shell: bash
run: | run: |
CURRENT_VERSION=$(node -p "require('./package.json').version") ver=$(node -p "require('./package.json').version")
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT echo "version=$ver" >> "$GITHUB_OUTPUT"
echo "tag=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Check if version exists on NPM # Check if version was already bumped in this commit
- name: Check if version was bumped
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"
echo "Previous version: $PREV_VERSION"
echo "Current version: $CURRENT_VERSION"
if [ "$PREV_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version was already bumped from $PREV_VERSION to $CURRENT_VERSION"
echo "bumped=false" >> "$GITHUB_OUTPUT"
echo "final_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
else else
echo "exists=false" >> $GITHUB_OUTPUT echo "No version bump detected, will auto-patch bump"
echo "Version $VERSION does not exist on NPM" echo "bumped=true" >> "$GITHUB_OUTPUT"
fi fi
- name: Bump patch version if needed # Auto-patch bump version if no version change was made
- name: Auto-patch bump version
if: steps.version-check.outputs.bumped == 'true'
id: bump-version id: bump-version
if: steps.version-check.outputs.exists == 'true' shell: bash
run: | run: |
npm version patch --no-git-tag-version npm version patch --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version") NEW_VERSION=$(node -p "require('./package.json').version")
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT echo "Auto-bumped version to $NEW_VERSION"
echo "bumped=true" >> $GITHUB_OUTPUT
# Set final version
- name: Set final version - name: Set final version
id: final-version id: final-version
shell: bash
run: | run: |
if [ "${{ steps.bump-version.outputs.bumped }}" = "true" ]; then if [ "${{ steps.version-check.outputs.bumped }}" = "true" ]; then
echo "version=${{ steps.bump-version.outputs.version }}" >> $GITHUB_OUTPUT echo "version=${{ steps.bump-version.outputs.version }}" >> "$GITHUB_OUTPUT"
echo "tag=${{ steps.bump-version.outputs.tag }}" >> $GITHUB_OUTPUT
else else
echo "version=${{ steps.current-version.outputs.version }}" >> $GITHUB_OUTPUT echo "version=${{ steps.current-version.outputs.version }}" >> "$GITHUB_OUTPUT"
echo "tag=${{ steps.current-version.outputs.tag }}" >> $GITHUB_OUTPUT
fi fi
- name: Generate release message # Commit version bump if auto-bumped
id: release-message - name: Commit auto-bumped version
run: | if: steps.version-check.outputs.bumped == 'true'
if [ "${{ steps.bump-version.outputs.bumped }}" = "true" ]; then shell: bash
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: | run: |
git config --local user.email "action@github.com" git config --local user.email "action@github.com"
git config --local user.name "GitHub Action" git config --local user.name "GitHub Action"
git add package.json git add package.json
git commit -m "chore: bump version to ${{ steps.bump-version.outputs.version }}" git commit -m "chore: auto-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 main
git push origin ${{ steps.final-version.outputs.tag }}
- name: Publish to NPM # Create a git tag like v1.2.3 if it doesn't already exist
run: npm publish - 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: env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public
- name: Create Release # Create a GitHub Release for the tag
uses: elgohr/Github-Release-Action@v5 - name: Create GitHub Release
env: uses: softprops/action-gh-release@v2
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{ steps.final-version.outputs.tag }} tag_name: v${{ steps.final-version.outputs.version }}
name: Release ${{ steps.final-version.outputs.tag }} name: v${{ steps.final-version.outputs.version }}
body: | generate_release_notes: true
## 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

View File

@@ -29,7 +29,7 @@
"useConst": "error" "useConst": "error"
}, },
"suspicious": { "suspicious": {
"noConsole": "warn", "noConsole": "off",
"noVar": "error" "noVar": "error"
} }
} }