Skip to content

Commit b148080

Browse files
authored
CI/CD experiment (#3)
Auto-release on PRs merged into `main` + enforce PRs going into main do change the version
1 parent a725635 commit b148080

4 files changed

Lines changed: 65 additions & 7 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Check Deno Version Change
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
12+
jobs:
13+
check-version:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v4
19+
20+
- name: Compare version in deno.json
21+
run: |
22+
PR_VERSION=$(jq -r '.version' deno.json)
23+
24+
MAIN_DENO_JSON=$(curl -s -H "Authorization: token ${{ github.token }}" \
25+
"https://api.github.com/repos/${{ github.repository }}/contents/deno.json?ref=main" | \
26+
jq -r '.content' | base64 -d)
27+
28+
MAIN_VERSION=$(echo "$MAIN_DENO_JSON" | jq -r '.version')
29+
30+
echo "PR version: $PR_VERSION"
31+
echo "Main version: $MAIN_VERSION"
32+
33+
if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
34+
echo "❌ Version in deno.json has not changed compared to main"
35+
exit 1
36+
else
37+
echo "✅ Version has changed from $MAIN_VERSION to $PR_VERSION"
38+
fi

.github/workflows/publishToJsr.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: Publish to JSR
22

33
on:
44
push:
5-
tags:
6-
- 'v*' # Triggers on version tags like v0.1.0
5+
branches:
6+
- main
77

88
jobs:
99
publish:
1010
runs-on: ubuntu-latest
1111
permissions:
12-
contents: read
12+
contents: write # Needed to push tags
1313
id-token: write # For Deno to authenticate with JSR
1414

1515
steps:
@@ -21,5 +21,22 @@ jobs:
2121
with:
2222
deno-version: v2.x
2323

24+
- name: Extract version from deno.json
25+
id: get_version
26+
run: |
27+
VERSION=$(jq -r '.version' deno.json)
28+
echo "VERSION=$VERSION" >> $GITHUB_ENV
29+
echo "Version is $VERSION"
30+
31+
- name: Configure Git identity
32+
run: |
33+
git config user.name "${{ github.actor }}"
34+
git config user.email "${{ github.actor }}@users.noreply.github.com"
35+
36+
- name: Create Git tag
37+
run: |
38+
git tag "v$VERSION"
39+
git push origin "v$VERSION"
40+
2441
- name: Publish to JSR
2542
run: deno publish

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@johanfive/xmas",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"exports": "./src/index.ts",
55
"license": "MIT",
66
"imports": {

src/core/test-utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'std/expect/mod.ts';
22
import { FakeTime } from 'std/testing/time.ts';
33
import type { HttpClient, HttpRequest, HttpResponse } from 'types/http.ts';
44
import type { Logger } from 'types/config.ts';
5+
import denoJson from '../../deno.json' with { type: 'json' };
56

67
/**
78
* Request-response pair for testing - HTTP response case
@@ -196,6 +197,8 @@ export async function withFakeTime(testFn: (fakeTime: FakeTime) => Promise<void>
196197
}
197198
}
198199

200+
const expectedUserAgent = `xmas/${denoJson.version} (Deno)`;
201+
199202
/**
200203
* Reusable test constants for endpoint testing
201204
*/
@@ -212,7 +215,7 @@ export const TestConstants = {
212215
'Authorization': 'Basic dGVzdHVzZXI6dGVzdHBhc3M=', // base64 of testuser:testpass
213216
'Content-Type': 'application/json',
214217
'Accept': 'application/json',
215-
'User-Agent': 'xmas/0.0.1 (Deno)', // Should match version in deno.json
218+
'User-Agent': expectedUserAgent,
216219
} as const,
217220

218221
/** Standard OAuth test configuration for creating RequestHandler instances */
@@ -228,12 +231,12 @@ export const TestConstants = {
228231
'Authorization': 'Bearer test-access-token',
229232
'Content-Type': 'application/json',
230233
'Accept': 'application/json',
231-
'User-Agent': 'xmas/0.0.1 (Deno)', // Should match version in deno.json
234+
'User-Agent': expectedUserAgent,
232235
} as const,
233236

234237
TOKEN_REQUEST_HEADERS: {
235238
'Content-Type': 'application/x-www-form-urlencoded',
236239
'Accept': 'application/json',
237-
'User-Agent': 'xmas/0.0.1 (Deno)', // Should match version in deno.json
240+
'User-Agent': expectedUserAgent,
238241
} as const,
239242
} as const;

0 commit comments

Comments
 (0)