-
Notifications
You must be signed in to change notification settings - Fork 0
292 lines (262 loc) · 9.31 KB
/
Copy pathrelease.yml
File metadata and controls
292 lines (262 loc) · 9.31 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
name: Release Workflow
on:
push:
branches: [main]
pull_request:
types: [closed]
jobs:
create_release_pr:
name: Create Release PR
if: "github.event_name == 'push' && !contains(github.event.head_commit.message, 'chore: release')"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: 2.x
- name: Calculate new version
id: version
run: |
CURRENT_VERSION=$(jq -r '.version' deno.json)
# Default to patch bump
VERSION_TYPE="patch"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
case $VERSION_TYPE in
"major")
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
"minor")
MINOR=$((MINOR + 1))
PATCH=0
;;
"patch")
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Update deno.json version
run: |
NEW_VERSION=${{ steps.version.outputs.version }}
jq --arg version "$NEW_VERSION" '.version = $version' deno.json > deno.json.tmp
mv deno.json.tmp deno.json
echo "Updated deno.json to version $NEW_VERSION"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: release ${{ steps.version.outputs.tag }}"
title: "Release ${{ steps.version.outputs.tag }}"
body: |
This PR bumps the version to `${{ steps.version.outputs.tag }}` for the next release.
Merging this PR will trigger the release workflow.
branch: "release/${{ steps.version.outputs.tag }}"
labels: "release"
test:
name: Test Deno
if: "github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')"
runs-on: ubuntu-latest
strategy:
matrix:
deno-version: ["2.x"]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}
- name: Cache Deno dependencies
uses: actions/cache@v4
with:
path: ~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/deno.lock') }}
restore-keys: |
${{ runner.os }}-deno-
- name: Check formatting
run: deno fmt --check
- name: Lint code
run: deno lint
- name: Type check
run: |
deno check src/mod.ts
deno check examples/basic-usage.ts
deno check examples/supabase-edge-function.ts
- name: Run tests
env:
LINGO_API_KEY: ${{ secrets.LINGO_API_KEY }}
run: deno test --allow-net tests/
- name: Test examples compile
run: deno check examples/*.ts
- name: Validate JSR configuration
run: deno publish --dry-run --allow-dirty
release:
name: Create Release
if: "github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')"
runs-on: ubuntu-latest
needs: [test]
permissions:
contents: write
id-token: write
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: 2.x
- name: Get Version
id: version
run: |
VERSION=$(jq -r '.version' deno.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
run: |
TAG=${{ steps.version.outputs.tag }}
git tag "$TAG"
git push origin "$TAG"
echo "Created and pushed tag $TAG"
- name: Generate release notes
id: release_notes
run: |
NEW_VERSION=${{ steps.version.outputs.version }}
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
cat > release_notes.md << EOF
## What's Changed
EOF
if [ -n "$LAST_TAG" ]; then
echo "Changes since $LAST_TAG:" >> release_notes.md
echo "" >> release_notes.md
git log ${LAST_TAG}..HEAD --pretty=format:"* %s (%h)" --no-merges >> release_notes.md
else
echo "* Initial release of Lingo.dev Deno SDK" >> release_notes.md
fi
cat >> release_notes.md << EOF
## Installation
**JSR (Recommended):**
```bash
deno add @lingodotdev/deno-sdk
```
**Deno Land:**
```typescript
import { LingoDotDevEngine } from "https://deno.land/x/lingodotdev@v$NEW_VERSION/mod.ts";
```
## Usage
```typescript
import { LingoDotDevEngine } from "@lingodotdev/deno-sdk";
const engine = new LingoDotDevEngine({
apiKey: "your-api-key"
});
const result = await engine.localizeText("Hello world", {
sourceLocale: "en",
targetLocale: "es"
});
```
See the [README](https://github.com/lingodotdev/sdk-deno#readme) for full documentation.
EOF
sed -i "s/\$NEW_VERSION/$NEW_VERSION/g" release_notes.md
- name: Publish to JSR
run: |
echo "Publishing to JSR..."
deno publish --allow-dirty
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body_path: release_notes.md
draft: false
prerelease: false
deno-land:
name: Update Deno Land Registry
runs-on: ubuntu-latest
needs: release
if: "needs.release.result == 'success'"
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Trigger Deno Land webhook
run: |
curl -X POST "https://api.deno.land/webhook/gh/lingodotdev/sdk-deno" \
-H "Content-Type: application/json" \
-d '{
"ref": "${{ github.ref }}",
"repository": {
"full_name": "lingodotdev/sdk-deno"
}
}'
- name: Wait for Deno Land processing
run: |
echo "Waiting 60 seconds for Deno Land to process the new version..."
sleep 60
- name: Verify Deno Land publication
run: |
VERSION="${{ needs.release.outputs.version }}"
echo "Checking if version $VERSION is available on Deno Land..."
MAX_ATTEMPTS=5
ATTEMPT=1
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://deno.land/x/lingodotdev@v$VERSION/mod.ts")
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ Version v$VERSION successfully published to Deno Land!"
break
else
echo "⏳ Attempt $ATTEMPT/$MAX_ATTEMPTS: Version v$VERSION not yet available (HTTP $HTTP_CODE)"
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
echo "Waiting 30 seconds before retry..."
sleep 30
fi
fi
ATTEMPT=$((ATTEMPT + 1))
done
if [ $ATTEMPT -gt $MAX_ATTEMPTS ]; then
echo "⚠️ Version v$VERSION may not be available on Deno Land yet"
echo "This can be normal - Deno Land sometimes takes longer to process releases"
fi
notify:
name: Notify Release Success
runs-on: ubuntu-latest
needs: [release, deno-land]
if: "always() && needs.release.result == 'success'"
steps:
- name: Release Summary
run: |
VERSION="${{ needs.release.outputs.version }}"
TAG="${{ needs.release.outputs.tag }}"
echo "🎉 Successfully released $TAG!"
echo ""
echo "📦 Published to:"
echo " ✅ JSR Registry: @lingodotdev/deno-sdk@$VERSION"
echo " ✅ GitHub Releases: $TAG"
if [[ "${{ needs.deno-land.result }}" == "success" ]]; then
echo " ✅ Deno Land: https://deno.land/x/lingodotdev@v$VERSION"
else
echo " ⚠️ Deno Land: May still be processing"
fi
echo ""
echo "🚀 Installation:"
echo " deno add @lingodotdev/deno-sdk"