-
Notifications
You must be signed in to change notification settings - Fork 37
105 lines (96 loc) · 4.05 KB
/
publish-release.yml
File metadata and controls
105 lines (96 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Release
on:
push:
branches: [main]
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
environment: npm
permissions:
contents: write
id-token: write
actions: write
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
registry-url: "https://registry.npmjs.org"
- run: pnpm install --frozen-lockfile
- name: Check if version is already published
id: check
run: |
PKG_NAME=$(node -p "require('./package.json').name")
PKG_VERSION=$(node -p "require('./package.json').version")
echo "version=${PKG_VERSION}" >> "$GITHUB_OUTPUT"
if npm view "${PKG_NAME}@${PKG_VERSION}" version 2>/dev/null; then
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Sync package.json description from README
if: steps.check.outputs.published == 'false'
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json','utf-8'));
const lines = fs.readFileSync('README.md','utf-8').split('\n');
for (const line of lines) {
const t = line.trim();
if (!t || t.startsWith('#') || t.startsWith('[') || t.startsWith('http') || t.startsWith('![')) continue;
pkg.description = t.replace(/[*_\`]/g,'').replace(/\s+/g,' ').trim();
break;
}
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
- name: Strip video URLs from README for npm
if: steps.check.outputs.published == 'false'
run: sed -i '/^https:\/\/github.com\/user-attachments\//d' README.md
- name: Build and publish
if: steps.check.outputs.published == 'false'
run: pnpm build && npm publish --access public
- name: Ensure git tag exists
if: steps.check.outputs.published == 'false'
run: |
TAG="v${{ steps.check.outputs.version }}"
if ! git rev-parse "${TAG}" >/dev/null 2>&1; then
git tag "${TAG}"
git push origin "${TAG}"
fi
- name: Update major version tag for GitHub Action
if: steps.check.outputs.published == 'false'
run: |
MAJOR="v$(echo "${{ steps.check.outputs.version }}" | cut -d. -f1)"
git tag -f "${MAJOR}"
git push origin "${MAJOR}" --force
- name: Create GitHub Release
if: steps.check.outputs.published == 'false'
run: |
TAG="v${{ steps.check.outputs.version }}"
gh release create "${TAG}" --generate-notes --title "${TAG}" --verify-tag --latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger Docker publish workflow
# GitHub's anti-recursion rule: tags pushed by GITHUB_TOKEN do NOT
# trigger downstream workflows. Explicitly dispatch publish-docker.yml
# so the GHCR image actually gets built on every release.
if: steps.check.outputs.published == 'false'
run: |
TAG="v${{ steps.check.outputs.version }}"
gh workflow run publish-docker.yml --ref "${TAG}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify Slack
if: steps.check.outputs.published == 'false'
run: |
if [ -z "$SLACK_WEBHOOK" ]; then echo "SLACK_WEBHOOK not set, skipping"; exit 0; fi
VERSION="v${{ steps.check.outputs.version }}"
curl -s -X POST "$SLACK_WEBHOOK" \
-H "Content-Type: application/json" \
-d "{\"text\":\"📦 *@copilotkit/aimock ${VERSION} published*\nnpm: https://www.npmjs.com/package/@copilotkit/aimock/v/${{ steps.check.outputs.version }}\nRelease: https://github.com/${{ github.repository }}/releases/tag/${VERSION}\"}"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}