Skip to content

feat: update workflow (#9) #7

feat: update workflow (#9)

feat: update workflow (#9) #7

Workflow file for this run

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
steps:
- name: Checkout code
uses: actions/checkout@v4
- 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@v4
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@v4
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@v4
- 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"