diff --git a/.github/workflows/check-deno-version-change.yml b/.github/workflows/check-deno-version-change.yml new file mode 100644 index 0000000..665ea4a --- /dev/null +++ b/.github/workflows/check-deno-version-change.yml @@ -0,0 +1,38 @@ +name: Check Deno Version Change + +on: + pull_request: + branches: + - main + types: + - opened + - synchronize + - reopened + +jobs: + check-version: + runs-on: ubuntu-latest + + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + + - name: Compare version in deno.json + run: | + PR_VERSION=$(jq -r '.version' deno.json) + + MAIN_DENO_JSON=$(curl -s -H "Authorization: token ${{ github.token }}" \ + "https://api.github.com/repos/${{ github.repository }}/contents/deno.json?ref=main" | \ + jq -r '.content' | base64 -d) + + MAIN_VERSION=$(echo "$MAIN_DENO_JSON" | jq -r '.version') + + echo "PR version: $PR_VERSION" + echo "Main version: $MAIN_VERSION" + + if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then + echo "❌ Version in deno.json has not changed compared to main" + exit 1 + else + echo "✅ Version has changed from $MAIN_VERSION to $PR_VERSION" + fi diff --git a/.github/workflows/publishToJsr.yml b/.github/workflows/publishToJsr.yml index 4563b1d..64f1916 100644 --- a/.github/workflows/publishToJsr.yml +++ b/.github/workflows/publishToJsr.yml @@ -2,14 +2,14 @@ name: Publish to JSR on: push: - tags: - - 'v*' # Triggers on version tags like v0.1.0 + branches: + - main jobs: publish: runs-on: ubuntu-latest permissions: - contents: read + contents: write # Needed to push tags id-token: write # For Deno to authenticate with JSR steps: @@ -21,5 +21,22 @@ jobs: with: deno-version: v2.x + - name: Extract version from deno.json + id: get_version + run: | + VERSION=$(jq -r '.version' deno.json) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "Version is $VERSION" + + - name: Configure Git identity + run: | + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor }}@users.noreply.github.com" + + - name: Create Git tag + run: | + git tag "v$VERSION" + git push origin "v$VERSION" + - name: Publish to JSR run: deno publish diff --git a/deno.json b/deno.json index 871e2fd..3fe3be9 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@johanfive/xmas", - "version": "0.0.1", + "version": "0.0.2", "exports": "./src/index.ts", "license": "MIT", "imports": { diff --git a/src/core/test-utils.ts b/src/core/test-utils.ts index 5da9a2e..c24138e 100644 --- a/src/core/test-utils.ts +++ b/src/core/test-utils.ts @@ -2,6 +2,7 @@ import { expect } from 'std/expect/mod.ts'; import { FakeTime } from 'std/testing/time.ts'; import type { HttpClient, HttpRequest, HttpResponse } from 'types/http.ts'; import type { Logger } from 'types/config.ts'; +import denoJson from '../../deno.json' with { type: 'json' }; /** * Request-response pair for testing - HTTP response case @@ -196,6 +197,8 @@ export async function withFakeTime(testFn: (fakeTime: FakeTime) => Promise } } +const expectedUserAgent = `xmas/${denoJson.version} (Deno)`; + /** * Reusable test constants for endpoint testing */ @@ -212,7 +215,7 @@ export const TestConstants = { 'Authorization': 'Basic dGVzdHVzZXI6dGVzdHBhc3M=', // base64 of testuser:testpass 'Content-Type': 'application/json', 'Accept': 'application/json', - 'User-Agent': 'xmas/0.0.1 (Deno)', // Should match version in deno.json + 'User-Agent': expectedUserAgent, } as const, /** Standard OAuth test configuration for creating RequestHandler instances */ @@ -228,12 +231,12 @@ export const TestConstants = { 'Authorization': 'Bearer test-access-token', 'Content-Type': 'application/json', 'Accept': 'application/json', - 'User-Agent': 'xmas/0.0.1 (Deno)', // Should match version in deno.json + 'User-Agent': expectedUserAgent, } as const, TOKEN_REQUEST_HEADERS: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json', - 'User-Agent': 'xmas/0.0.1 (Deno)', // Should match version in deno.json + 'User-Agent': expectedUserAgent, } as const, } as const;