mirror of
https://github.com/vercel-labs/json-render.git
synced 2026-09-14 13:41:32 +08:00
5f2ecc1118
* update release process * fix lock
158 lines
4.7 KiB
YAML
158 lines
4.7 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
jobs:
|
|
check-release:
|
|
name: Check for new version
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
permissions:
|
|
contents: read
|
|
outputs:
|
|
should_release: ${{ steps.check.outputs.should_release }}
|
|
needs_github_release: ${{ steps.check.outputs.needs_github_release }}
|
|
version: ${{ steps.check.outputs.version }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Compare package.json version to npm and check GitHub release
|
|
id: check
|
|
run: |
|
|
LOCAL_VERSION=$(node -p "require('./packages/core/package.json').version")
|
|
echo "Local version: $LOCAL_VERSION"
|
|
|
|
NPM_VERSION=$(npm view @json-render/core version 2>/dev/null || echo "0.0.0")
|
|
echo "npm version: $NPM_VERSION"
|
|
|
|
if [ "$LOCAL_VERSION" != "$NPM_VERSION" ]; then
|
|
echo "Version changed: $NPM_VERSION -> $LOCAL_VERSION"
|
|
echo "should_release=true" >> "$GITHUB_OUTPUT"
|
|
echo "needs_github_release=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "Version unchanged on npm, skipping build and publish"
|
|
echo "should_release=false" >> "$GITHUB_OUTPUT"
|
|
|
|
TAG="v$LOCAL_VERSION"
|
|
if gh release view "$TAG" &>/dev/null; then
|
|
echo "GitHub release $TAG exists"
|
|
echo "needs_github_release=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "GitHub release $TAG is missing, will create it"
|
|
echo "needs_github_release=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
fi
|
|
echo "version=$LOCAL_VERSION" >> "$GITHUB_OUTPUT"
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
build:
|
|
name: Build
|
|
needs: check-release
|
|
if: needs.check-release.outputs.should_release == 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install pnpm
|
|
uses: pnpm/action-setup@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: pnpm
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Build packages
|
|
run: pnpm run build
|
|
|
|
publish:
|
|
name: Publish to npm
|
|
needs: [check-release, build]
|
|
if: needs.check-release.outputs.should_release == 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install pnpm
|
|
uses: pnpm/action-setup@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: pnpm
|
|
registry-url: "https://registry.npmjs.org"
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Build packages
|
|
run: pnpm run build
|
|
|
|
- name: Publish all public packages
|
|
run: pnpm -r publish --no-git-checks --filter '@json-render/*'
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_VERCEL_TOKEN_ELEVATED }}
|
|
|
|
github-release:
|
|
name: Create GitHub Release
|
|
needs: [check-release, publish]
|
|
if: >-
|
|
always()
|
|
&& needs.check-release.outputs.needs_github_release == 'true'
|
|
&& (needs.publish.result == 'success' || needs.publish.result == 'skipped')
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Extract changelog entry
|
|
run: |
|
|
VERSION="${{ needs.check-release.outputs.version }}"
|
|
awk '/<!-- release:start -->/{found=1; next} /<!-- release:end -->/{found=0} found{print}' CHANGELOG.md > /tmp/release-notes.md
|
|
|
|
LINES=$(wc -l < /tmp/release-notes.md | tr -d ' ')
|
|
if [ "$LINES" -lt 2 ]; then
|
|
echo "Error: No release notes found between <!-- release:start --> and <!-- release:end --> markers in CHANGELOG.md"
|
|
exit 1
|
|
fi
|
|
echo "Extracted release notes for $VERSION ($LINES lines)"
|
|
|
|
- name: Create GitHub Release
|
|
run: |
|
|
VERSION="${{ needs.check-release.outputs.version }}"
|
|
TAG="v$VERSION"
|
|
|
|
if gh release view "$TAG" &>/dev/null; then
|
|
echo "Release $TAG already exists"
|
|
else
|
|
echo "Creating release $TAG..."
|
|
gh release create "$TAG" \
|
|
--title "$TAG" \
|
|
--notes-file /tmp/release-notes.md
|
|
fi
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|