|
8 | 8 |
|
9 | 9 | concurrency: ${{ github.workflow }}-${{ github.ref }} |
10 | 10 |
|
11 | | -permissions: |
12 | | - contents: write |
13 | | - pull-requests: write |
14 | | - |
15 | 11 | jobs: |
16 | | - release: |
17 | | - name: Release |
| 12 | + check-release: |
| 13 | + name: Check for new version |
18 | 14 | runs-on: ubuntu-latest |
| 15 | + timeout-minutes: 5 |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + outputs: |
| 19 | + should_release: ${{ steps.check.outputs.should_release }} |
| 20 | + needs_github_release: ${{ steps.check.outputs.needs_github_release }} |
| 21 | + version: ${{ steps.check.outputs.version }} |
19 | 22 | steps: |
20 | 23 | - name: Checkout repository |
21 | 24 | uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Compare package.json version to npm and check GitHub release |
| 27 | + id: check |
| 28 | + run: | |
| 29 | + LOCAL_VERSION=$(node -p "require('./packages/core/package.json').version") |
| 30 | + echo "Local version: $LOCAL_VERSION" |
| 31 | +
|
| 32 | + NPM_VERSION=$(npm view @json-render/core version 2>/dev/null || echo "0.0.0") |
| 33 | + echo "npm version: $NPM_VERSION" |
| 34 | +
|
| 35 | + if [ "$LOCAL_VERSION" != "$NPM_VERSION" ]; then |
| 36 | + echo "Version changed: $NPM_VERSION -> $LOCAL_VERSION" |
| 37 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 38 | + echo "needs_github_release=true" >> "$GITHUB_OUTPUT" |
| 39 | + else |
| 40 | + echo "Version unchanged on npm, skipping build and publish" |
| 41 | + echo "should_release=false" >> "$GITHUB_OUTPUT" |
| 42 | +
|
| 43 | + TAG="v$LOCAL_VERSION" |
| 44 | + if gh release view "$TAG" &>/dev/null; then |
| 45 | + echo "GitHub release $TAG exists" |
| 46 | + echo "needs_github_release=false" >> "$GITHUB_OUTPUT" |
| 47 | + else |
| 48 | + echo "GitHub release $TAG is missing, will create it" |
| 49 | + echo "needs_github_release=true" >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | + fi |
| 52 | + echo "version=$LOCAL_VERSION" >> "$GITHUB_OUTPUT" |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + build: |
| 57 | + name: Build |
| 58 | + needs: check-release |
| 59 | + if: needs.check-release.outputs.should_release == 'true' |
| 60 | + runs-on: ubuntu-latest |
| 61 | + timeout-minutes: 15 |
| 62 | + permissions: |
| 63 | + contents: read |
| 64 | + steps: |
| 65 | + - name: Checkout repository |
| 66 | + uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Install pnpm |
| 69 | + uses: pnpm/action-setup@v4 |
| 70 | + |
| 71 | + - name: Setup Node.js |
| 72 | + uses: actions/setup-node@v4 |
22 | 73 | with: |
23 | | - fetch-depth: 0 |
| 74 | + node-version: 22 |
| 75 | + cache: pnpm |
| 76 | + |
| 77 | + - name: Install dependencies |
| 78 | + run: pnpm install --frozen-lockfile |
| 79 | + |
| 80 | + - name: Build packages |
| 81 | + run: pnpm run build |
| 82 | + |
| 83 | + publish: |
| 84 | + name: Publish to npm |
| 85 | + needs: [check-release, build] |
| 86 | + if: needs.check-release.outputs.should_release == 'true' |
| 87 | + runs-on: ubuntu-latest |
| 88 | + timeout-minutes: 15 |
| 89 | + permissions: |
| 90 | + contents: read |
| 91 | + steps: |
| 92 | + - name: Checkout repository |
| 93 | + uses: actions/checkout@v4 |
24 | 94 |
|
25 | 95 | - name: Install pnpm |
26 | 96 | uses: pnpm/action-setup@v4 |
27 | 97 |
|
28 | 98 | - name: Setup Node.js |
29 | 99 | uses: actions/setup-node@v4 |
30 | 100 | with: |
31 | | - node-version: 20 |
| 101 | + node-version: 22 |
32 | 102 | cache: pnpm |
33 | 103 | registry-url: "https://registry.npmjs.org" |
34 | 104 |
|
35 | 105 | - name: Install dependencies |
36 | 106 | run: pnpm install --frozen-lockfile |
37 | 107 |
|
38 | | - - name: Create Release Pull Request or Publish |
39 | | - uses: changesets/action@v1 |
40 | | - with: |
41 | | - version: pnpm ci:version |
42 | | - publish: pnpm ci:publish |
43 | | - title: "chore: version packages" |
44 | | - commit: "chore: version packages" |
| 108 | + - name: Build packages |
| 109 | + run: pnpm run build |
| 110 | + |
| 111 | + - name: Publish all public packages |
| 112 | + run: pnpm -r publish --no-git-checks --filter '@json-render/*' |
45 | 113 | env: |
46 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
47 | 114 | NODE_AUTH_TOKEN: ${{ secrets.NPM_VERCEL_TOKEN_ELEVATED }} |
| 115 | + |
| 116 | + github-release: |
| 117 | + name: Create GitHub Release |
| 118 | + needs: [check-release, publish] |
| 119 | + if: >- |
| 120 | + always() |
| 121 | + && needs.check-release.outputs.needs_github_release == 'true' |
| 122 | + && (needs.publish.result == 'success' || needs.publish.result == 'skipped') |
| 123 | + runs-on: ubuntu-latest |
| 124 | + timeout-minutes: 10 |
| 125 | + permissions: |
| 126 | + contents: write |
| 127 | + steps: |
| 128 | + - name: Checkout repository |
| 129 | + uses: actions/checkout@v4 |
| 130 | + |
| 131 | + - name: Extract changelog entry |
| 132 | + run: | |
| 133 | + VERSION="${{ needs.check-release.outputs.version }}" |
| 134 | + awk '/<!-- release:start -->/{found=1; next} /<!-- release:end -->/{found=0} found{print}' CHANGELOG.md > /tmp/release-notes.md |
| 135 | +
|
| 136 | + LINES=$(wc -l < /tmp/release-notes.md | tr -d ' ') |
| 137 | + if [ "$LINES" -lt 2 ]; then |
| 138 | + echo "Error: No release notes found between <!-- release:start --> and <!-- release:end --> markers in CHANGELOG.md" |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + echo "Extracted release notes for $VERSION ($LINES lines)" |
| 142 | +
|
| 143 | + - name: Create GitHub Release |
| 144 | + run: | |
| 145 | + VERSION="${{ needs.check-release.outputs.version }}" |
| 146 | + TAG="v$VERSION" |
| 147 | +
|
| 148 | + if gh release view "$TAG" &>/dev/null; then |
| 149 | + echo "Release $TAG already exists" |
| 150 | + else |
| 151 | + echo "Creating release $TAG..." |
| 152 | + gh release create "$TAG" \ |
| 153 | + --title "$TAG" \ |
| 154 | + --notes-file /tmp/release-notes.md |
| 155 | + fi |
| 156 | + env: |
| 157 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments