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,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: 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
with: with:
file: ./coverage/lcov.info file: ./coverage/lcov.info
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
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
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
run: bun run build
- name: Run linting # Read current version from package.json
run: bun run lint - name: Read current version
id: current-version
shell: bash
run: |
ver=$(node -p "require('./package.json').version")
echo "version=$ver" >> "$GITHUB_OUTPUT"
- name: Build package # Check if version was already bumped in this commit
run: bun run build - name: Check if version was bumped
id: version-check
shell: bash
run: |
# Get the previous commit's version
PREV_VERSION=$(git show HEAD~1:package.json 2>/dev/null | node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0")
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
- name: Get current version echo "Previous version: $PREV_VERSION"
id: current-version echo "Current version: $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 if [ "$PREV_VERSION" != "$CURRENT_VERSION" ]; then
id: version-check echo "Version was already bumped from $PREV_VERSION to $CURRENT_VERSION"
run: | echo "bumped=false" >> "$GITHUB_OUTPUT"
VERSION=${{ steps.current-version.outputs.version }} echo "final_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
if npm view prettier-plugin-openapi@$VERSION version >/dev/null 2>&1; then else
echo "exists=true" >> $GITHUB_OUTPUT echo "No version bump detected, will auto-patch bump"
echo "Version $VERSION already exists on NPM" echo "bumped=true" >> "$GITHUB_OUTPUT"
else fi
echo "exists=false" >> $GITHUB_OUTPUT
echo "Version $VERSION does not exist on NPM"
fi
- name: Bump patch version if needed # Auto-patch bump version if no version change was made
id: bump-version - name: Auto-patch bump version
if: steps.version-check.outputs.exists == 'true' if: steps.version-check.outputs.bumped == 'true'
run: | id: bump-version
npm version patch --no-git-tag-version shell: bash
NEW_VERSION=$(node -p "require('./package.json').version") run: |
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT npm version patch --no-git-tag-version
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT NEW_VERSION=$(node -p "require('./package.json').version")
echo "bumped=true" >> $GITHUB_OUTPUT echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "Auto-bumped version to $NEW_VERSION"
- name: Set final version # Set final version
id: final-version - name: Set final version
run: | id: final-version
if [ "${{ steps.bump-version.outputs.bumped }}" = "true" ]; then shell: bash
echo "version=${{ steps.bump-version.outputs.version }}" >> $GITHUB_OUTPUT run: |
echo "tag=${{ steps.bump-version.outputs.tag }}" >> $GITHUB_OUTPUT if [ "${{ steps.version-check.outputs.bumped }}" = "true" ]; then
else echo "version=${{ steps.bump-version.outputs.version }}" >> "$GITHUB_OUTPUT"
echo "version=${{ steps.current-version.outputs.version }}" >> $GITHUB_OUTPUT else
echo "tag=${{ steps.current-version.outputs.tag }}" >> $GITHUB_OUTPUT echo "version=${{ steps.current-version.outputs.version }}" >> "$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") run: |
echo "message=Automated patch release: $COMMIT_MSG" >> $GITHUB_OUTPUT git config --local user.email "action@github.com"
else git config --local user.name "GitHub Action"
COMMIT_MSG=$(git log -1 --pretty=format:"%s") git add package.json
echo "message=Release: $COMMIT_MSG" >> $GITHUB_OUTPUT git commit -m "chore: auto-bump version to ${{ steps.bump-version.outputs.version }}"
fi git push origin main
- name: Commit version bump if needed # Create a git tag like v1.2.3 if it doesn't already exist
if: steps.bump-version.outputs.bumped == 'true' - name: Create tag if missing
run: | shell: bash
git config --local user.email "action@github.com" run: |
git config --local user.name "GitHub Action" TAG="v${{ steps.final-version.outputs.version }}"
git add package.json if git rev-parse "$TAG" >/dev/null 2>&1; then
git commit -m "chore: bump version to ${{ steps.bump-version.outputs.version }}" echo "Tag $TAG already exists."
else
git tag "$TAG" ${{ github.event.workflow_run.head_sha }}
git push origin "$TAG"
fi
- name: Create tag # Publish to npm (requires NPM_TOKEN in repo secrets)
run: | - name: Publish to npm
git tag ${{ steps.final-version.outputs.tag }} env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public
- name: Push changes and tag # Create a GitHub Release for the tag
run: | - name: Create GitHub Release
git push origin main uses: softprops/action-gh-release@v2
git push origin ${{ steps.final-version.outputs.tag }} with:
tag_name: v${{ steps.final-version.outputs.version }}
- name: Publish to NPM name: v${{ steps.final-version.outputs.version }}
run: npm publish generate_release_notes: true
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

View File

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