-
Notifications
You must be signed in to change notification settings - Fork 31
228 lines (197 loc) · 6.38 KB
/
Copy pathrelease.yml
File metadata and controls
228 lines (197 loc) · 6.38 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: Release
on:
push:
tags: ["v*"]
# Least privilege by default; jobs opt into the extra scopes they need.
permissions:
contents: read
jobs:
# ---- Build & Verify ----
build:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
- run: npm ci
- run: cd web && npm ci
- run: npm run build -w packages/sdk
- run: npm run typecheck
- run: npm run build
- run: node dist/cli/index.js --help
- name: Run tests
run: npx vitest run
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# ---- Publish to npm ----
publish-npm:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write # npm provenance
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
- name: Check if version already published
id: check
run: |
LOCAL=$(node -p "require('./package.json').version")
REMOTE=$(npm view teleton version 2>/dev/null || echo "0.0.0")
echo "local=$LOCAL remote=$REMOTE"
if [ "$LOCAL" != "$REMOTE" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- run: npm ci
if: steps.check.outputs.publish == 'true'
- run: cd web && npm ci
if: steps.check.outputs.publish == 'true'
- uses: actions/download-artifact@v4
if: steps.check.outputs.publish == 'true'
with:
name: dist
path: dist/
- run: npm publish --provenance --access public
if: steps.check.outputs.publish == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ---- Publish SDK to npm (if version changed) ----
publish-sdk:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write # npm provenance
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
cache: npm
- name: Check if SDK version needs publishing
id: check
run: |
LOCAL=$(node -p "require('./packages/sdk/package.json').version")
REMOTE=$(npm view @teleton-agent/sdk version 2>/dev/null || echo "0.0.0")
echo "local=$LOCAL" >> "$GITHUB_OUTPUT"
echo "remote=$REMOTE" >> "$GITHUB_OUTPUT"
if [ "$LOCAL" != "$REMOTE" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- name: Install root deps (for @types/node hoisting)
if: steps.check.outputs.publish == 'true'
run: npm ci
- name: Build and publish SDK
if: steps.check.outputs.publish == 'true'
run: npm run build -w packages/sdk && cd packages/sdk && npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ---- Publish Docker image ----
publish-docker:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
packages: write # push to ghcr.io
steps:
- uses: actions/checkout@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version and repo
id: meta
run: |
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
echo "repo=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ steps.meta.outputs.repo }}:${{ steps.meta.outputs.version }}
ghcr.io/${{ steps.meta.outputs.repo }}:latest
# ---- GitHub Release ----
create-release:
needs: [publish-npm]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # create the GitHub release
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if release already exists
id: check
run: |
if gh release view "$GITHUB_REF_NAME" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate changelog
if: steps.check.outputs.exists == 'false'
id: changelog
run: |
PREV_TAG=$(git tag --sort=-version:refname | head -2 | tail -1)
if [ -z "$PREV_TAG" ]; then
LOG=$(git log --oneline)
else
LOG=$(git log --oneline "$PREV_TAG"..HEAD)
fi
echo "log<<EOF" >> "$GITHUB_OUTPUT"
echo "$LOG" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Lowercase image path for the install snippet
id: meta
run: echo "repo=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
if: steps.check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
body: |
## Install
**npm:**
```bash
npm install -g teleton
```
**Docker:**
```bash
docker run -it -v ~/.teleton:/data ghcr.io/${{ steps.meta.outputs.repo }}:latest setup
```
## Changes
${{ steps.changelog.outputs.log }}