-
Notifications
You must be signed in to change notification settings - Fork 89
213 lines (179 loc) 路 7.63 KB
/
Copy pathrelease.yml
File metadata and controls
213 lines (179 loc) 路 7.63 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Release tag to publish, for example v0.2.12
required: true
type: string
permissions:
contents: read
id-token: write
jobs:
validate:
runs-on: ubuntu-latest
outputs:
package_name: ${{ steps.verify.outputs.package_name }}
package_version: ${{ steps.verify.outputs.package_version }}
tag_name: ${{ steps.verify.outputs.tag_name }}
npm_already_published: ${{ steps.npm_exists.outputs.already_published }}
clawhub_already_published: ${{ steps.clawhub_exists.outputs.already_published }}
tarball_name: ${{ steps.pack.outputs.tarball_name }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.tag || github.event.release.tag_name }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22.14.0"
registry-url: "https://registry.npmjs.org"
- name: Setup npm
run: npm install -g npm@11.6.2
- name: Validate release tag matches package version
id: verify
env:
TAG_NAME: ${{ inputs.tag || github.event.release.tag_name }}
run: |
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if [ -z "$TAG_NAME" ]; then
echo "tag input is required for workflow_dispatch, and release.tag_name is required for release runs."
exit 1
fi
EXPECTED_TAG="v${PACKAGE_VERSION}"
if [ "$TAG_NAME" != "$EXPECTED_TAG" ]; then
echo "Tag/version mismatch."
echo "Expected tag: $EXPECTED_TAG"
echo "Actual tag: $TAG_NAME"
echo "package.json version: $PACKAGE_VERSION"
exit 1
fi
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
- name: Check if this version is already published to npm
id: npm_exists
run: |
if npm view "${{ steps.verify.outputs.package_name }}@${{ steps.verify.outputs.package_version }}" version >/dev/null 2>&1; then
echo "already_published=true" >> "$GITHUB_OUTPUT"
else
echo "already_published=false" >> "$GITHUB_OUTPUT"
fi
- name: Check if this version is already published to ClawHub
id: clawhub_exists
env:
PACKAGE_NAME: ${{ steps.verify.outputs.package_name }}
PACKAGE_VERSION: ${{ steps.verify.outputs.package_version }}
run: |
python3 - <<'PY'
import json
import os
import urllib.error
import urllib.parse
import urllib.request
package_name = os.environ["PACKAGE_NAME"].strip()
package_version = os.environ["PACKAGE_VERSION"].strip()
url = f"https://clawhub.ai/api/v1/packages/{urllib.parse.quote(package_name, safe='')}"
already_published = False
try:
with urllib.request.urlopen(url) as response:
payload = json.load(response)
except urllib.error.HTTPError as error:
if error.code != 404:
raise
payload = {}
package = payload.get("package") or {}
latest_version = str(package.get("latestVersion") or "").strip()
tags = package.get("tags") or {}
latest_tag = str(tags.get("latest") or "").strip() if isinstance(tags, dict) else ""
already_published = latest_version == package_version or latest_tag == package_version
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
fh.write(f"already_published={'true' if already_published else 'false'}\n")
PY
- name: Install dependencies
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm ci
- name: Run build
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm run build
- name: Run lint
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm run lint
- name: Run typecheck
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm run typecheck
- name: Run tests
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm run test
- name: Run smoke tests
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm run smoke
- name: Verify package payload
if: steps.npm_exists.outputs.already_published != 'true' || steps.clawhub_exists.outputs.already_published != 'true'
run: npm run pack:check
- name: Pack npm release artifact
id: pack
if: steps.npm_exists.outputs.already_published != 'true'
run: |
TARBALL_NAME="$(npm pack --json | jq -r '.[0].filename')"
echo "tarball_name=$TARBALL_NAME" >> "$GITHUB_OUTPUT"
- name: Upload npm release artifact
if: steps.npm_exists.outputs.already_published != 'true'
uses: actions/upload-artifact@v7
with:
name: npm-release-tarball
path: ${{ steps.pack.outputs.tarball_name }}
if-no-files-found: error
- name: Report already-published release state
if: steps.npm_exists.outputs.already_published == 'true' && steps.clawhub_exists.outputs.already_published == 'true'
run: |
echo "Skipping publish: ${{ steps.verify.outputs.package_name }}@${{ steps.verify.outputs.package_version }} is already published to npm and ClawHub."
publish-npm:
needs: validate
if: needs.validate.outputs.npm_already_published != 'true'
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22.14.0"
registry-url: "https://registry.npmjs.org"
- name: Setup npm
run: npm install -g npm@11.6.2
- name: Download npm release artifact
uses: actions/download-artifact@v8
with:
name: npm-release-tarball
path: ./release-artifacts
- name: Prepare trusted publishing auth
run: |
npm config delete //registry.npmjs.org/:_authToken || true
- name: Publish to npm
run: |
if [ "${{ github.event.repository.private }}" = "true" ]; then
npm publish "./release-artifacts/${{ needs.validate.outputs.tarball_name }}" --access public
else
npm publish "./release-artifacts/${{ needs.validate.outputs.tarball_name }}" --provenance --access public
fi
env:
NODE_AUTH_TOKEN: ""
publish-clawhub:
needs: validate
if: needs.validate.outputs.clawhub_already_published != 'true'
permissions:
contents: read
id-token: write
uses: ./.github/workflows/clawhub-package-publish.yml
with:
dry_run: false
owner: opik
ref: ${{ needs.validate.outputs.tag_name }}
version: ${{ needs.validate.outputs.package_version }}
source_ref: refs/tags/${{ needs.validate.outputs.tag_name }}
secrets:
clawhub_token: ${{ secrets.CLAWHUB_TOKEN }}