feat: added github action workflow and examples (#2) #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: [main] | |
| tags: | |
| - "v*" | |
| jobs: | |
| test: | |
| name: Test Deno ${{ matrix.deno-version }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| deno-version: ["2.x"] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Deno ${{ matrix.deno-version }} | |
| 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/ | |
| release: | |
| name: Release to JSR and Deno Land | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Deno | |
| uses: denoland/setup-deno@v1 | |
| with: | |
| deno-version: 2.x | |
| - name: Extract version from tag or generate | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "is_release=true" >> $GITHUB_OUTPUT | |
| else | |
| # Generate pre-release version for main branch | |
| COMMIT_SHA=${GITHUB_SHA:0:7} | |
| VERSION="0.0.0-dev.$COMMIT_SHA" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "is_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Version: $VERSION" | |
| - name: Update version in deno.json | |
| run: | | |
| # Update version in deno.json using jq | |
| jq --arg version "${{ steps.version.outputs.version }}" '.version = $version' deno.json > deno.json.tmp | |
| mv deno.json.tmp deno.json | |
| echo "Updated deno.json version to ${{ steps.version.outputs.version }}" | |
| cat deno.json | |
| - name: Validate JSR configuration | |
| run: | | |
| deno publish --dry-run --allow-dirty | |
| - name: Publish to JSR | |
| if: steps.version.outputs.is_release == 'true' | |
| run: | | |
| deno publish | |
| - name: Create GitHub Release | |
| if: steps.version.outputs.is_release == 'true' | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| release_name: Release v${{ steps.version.outputs.version }} | |
| body: | | |
| ## What's Changed | |
| This release includes updates to the Lingo.dev Deno SDK. | |
| ### Installation | |
| **JSR (Recommended):** | |
| ```bash | |
| deno add @lingodotdev/deno-sdk | |
| ``` | |
| **Deno Land:** | |
| ```typescript | |
| import { LingoDotDevEngine } from "https://deno.land/x/lingodotdev@v${{ steps.version.outputs.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. | |
| draft: false | |
| prerelease: false | |
| deno-land: | |
| name: Update Deno Land Registry | |
| runs-on: ubuntu-latest | |
| needs: release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Extract version | |
| id: version | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - 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 30 seconds for Deno Land to process the new version..." | |
| sleep 30 | |
| - name: Verify Deno Land publication | |
| run: | | |
| VERSION=${{ steps.version.outputs.version }} | |
| echo "Checking if version $VERSION is available on Deno Land..." | |
| # Check if the version exists on deno.land/x | |
| 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!" | |
| else | |
| echo "⚠️ Version v$VERSION not yet available on Deno Land (HTTP $HTTP_CODE)" | |
| echo "This may be normal - Deno Land can take a few minutes to process new releases" | |
| fi |