declapract-typescript-ehmpathy 0.47.27 → 0.47.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,36 @@
1
- #!/usr/bin/env bash
1
+ #!/bin/sh
2
2
  ######################################################################
3
3
  # .what = export api keys for integration tests
4
- # .why = enables running integration tests that require api keys
4
+ # .why = enables tests that require api keys to run
5
5
  #
6
6
  # usage:
7
- # source .agent/repo=.this/role=any/skills/use.apikeys.sh
7
+ # . .agent/repo=.this/role=any/skills/use.apikeys.sh
8
8
  #
9
9
  # note:
10
- # - must be called with `source` to export vars to current shell
10
+ # - must be called with `.` or `source` to export vars to current shell
11
11
  # - loads from ~/.config/rhachet/apikeys.env if available
12
12
  # - falls back to .env.local (gitignored) in repo root
13
13
  ######################################################################
14
14
 
15
- # fail if not sourced
16
- if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
17
- echo "error: this script must be sourced, not executed"
18
- echo "usage: source ${BASH_SOURCE[0]}"
19
- exit 1
20
- fi
15
+ # fail if not sourced (check if $0 matches this file)
16
+ case "$0" in
17
+ *use.apikeys.sh)
18
+ echo "error: this file must be sourced, not executed"
19
+ echo "usage: source $0"
20
+ exit 1
21
+ ;;
22
+ esac
23
+
24
+ # alias source to `.` for posix compat
25
+ source() { . "$@"; }
21
26
 
22
- # try loading from user config first
23
- if [[ -f ~/.config/rhachet/apikeys.env ]]; then
27
+ # try to load from user config first
28
+ if [ -f ~/.config/rhachet/apikeys.env ]; then
24
29
  source ~/.config/rhachet/apikeys.env
25
30
  echo "✓ loaded api keys from ~/.config/rhachet/apikeys.env"
26
31
 
27
32
  # fallback to local gitignored file
28
- elif [[ -f .env.local ]]; then
33
+ elif [ -f .env.local ]; then
29
34
  source .env.local
30
35
  echo "✓ loaded api keys from .env.local"
31
36
 
@@ -39,20 +44,21 @@ else
39
44
  echo "with contents like:"
40
45
  echo " export OPENAI_API_KEY=sk-..."
41
46
  echo " export ANTHROPIC_API_KEY=sk-..."
42
- return 1
47
+ return 1 2>/dev/null || exit 1
43
48
  fi
44
49
 
45
50
  # read required keys from json config if present
46
51
  APIKEYS_CONFIG=".agent/repo=.this/role=any/skills/use.apikeys.json"
47
- if [[ -f "$APIKEYS_CONFIG" ]]; then
48
- # extract required keys using jq
52
+ if [ -f "$APIKEYS_CONFIG" ]; then
53
+ # extract required keys via jq
49
54
  REQUIRED_KEYS=$(jq -r '.apikeys.required[]?' "$APIKEYS_CONFIG" 2>/dev/null)
50
55
 
51
56
  # verify each required key is set
52
57
  for KEY in $REQUIRED_KEYS; do
53
- if [[ -z "${!KEY}" ]]; then
58
+ VALUE=$(eval "echo \"\$$KEY\"")
59
+ if [ -z "$VALUE" ]; then
54
60
  echo "⚠ $KEY not set (required by $APIKEYS_CONFIG)"
55
- return 1
61
+ return 1 2>/dev/null || exit 1
56
62
  fi
57
63
  echo "✓ $KEY set"
58
64
  done
@@ -362,37 +362,80 @@ runs:
362
362
  MAIN_SHA=$(gh api "repos/${REPO}/git/ref/heads/main" --jq '.object.sha')
363
363
 
364
364
  if [ -n "$FOUND_PR" ] && [ "$FOUND_PR" != "null" ]; then
365
- PR_NUMBER=$(echo "$FOUND_PR" | jq -r '.number')
366
- BRANCH=$(echo "$FOUND_PR" | jq -r '.headRefName')
367
- echo " ├── found-pr: #$PR_NUMBER ($BRANCH)"
368
-
369
- # upsert rebased commit
370
- echo " ├── upserting rebased commit..."
371
- COMMIT_SHA=$(upsert_rebased_commit "$BRANCH" "$MAIN_SHA" "chore(release): ${NEXT_VERSION} 🎉")
372
- echo " ├── commit: ${COMMIT_SHA:0:7}"
373
-
374
- # update pr metadata
375
- echo " ├── updating pr metadata..."
376
- gh pr edit "$PR_NUMBER" \
377
- --title "chore(release): ${NEXT_VERSION} 🎉" \
378
- --body "$PR_BODY"
379
-
380
- echo " ├── pr updated: #$PR_NUMBER"
381
- echo " └── 🌊 action: updated"
382
- echo "action=updated" >> $GITHUB_OUTPUT
383
- echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
365
+ FOUND_PR_NUMBER=$(echo "$FOUND_PR" | jq -r '.number')
366
+ FOUND_PR_BRANCH=$(echo "$FOUND_PR" | jq -r '.headRefName')
367
+ IDEAL_PR_BRANCH="release/${NEXT_VERSION}"
368
+ echo " ├── found-pr: #$FOUND_PR_NUMBER ($FOUND_PR_BRANCH)"
369
+
370
+ # check if branch name matches expected version
371
+ if [ "$FOUND_PR_BRANCH" != "$IDEAL_PR_BRANCH" ]; then
372
+ echo " ├── branch mismatch: $FOUND_PR_BRANCH != $IDEAL_PR_BRANCH"
373
+ echo " ├── recreate pr with correct branch..."
374
+
375
+ # close found pr (with comment explaining why)
376
+ gh pr comment "$FOUND_PR_NUMBER" --body "🫧 closed: version bumped to ${NEXT_VERSION}, recreated pr with branch \`${IDEAL_PR_BRANCH}\`"
377
+ gh pr close "$FOUND_PR_NUMBER"
378
+ echo " ├── closed: #$FOUND_PR_NUMBER"
379
+
380
+ # delete found branch (fail fast unless already gone)
381
+ DELETE_OUTPUT=$(gh api "repos/${REPO}/git/refs/heads/${FOUND_PR_BRANCH}" -X DELETE 2>&1) || {
382
+ if echo "$DELETE_OUTPUT" | grep -q "Reference does not exist"; then
383
+ echo " ├── branch already deleted: $FOUND_PR_BRANCH"
384
+ else
385
+ echo " ├── ⛈️ failed to delete branch: $FOUND_PR_BRANCH"
386
+ echo "$DELETE_OUTPUT"
387
+ exit 1
388
+ fi
389
+ }
390
+ echo " ├── deleted branch: $FOUND_PR_BRANCH"
391
+
392
+ # create new branch with correct name
393
+ echo " ├── create branch: $IDEAL_PR_BRANCH"
394
+ COMMIT_SHA=$(upsert_rebased_commit "$IDEAL_PR_BRANCH" "$MAIN_SHA" "chore(release): ${NEXT_VERSION} 🎉")
395
+ echo " ├── commit: ${COMMIT_SHA:0:7}"
396
+
397
+ # create new pr
398
+ echo " ├── create pr..."
399
+ PR_URL=$(gh pr create \
400
+ --title "chore(release): ${NEXT_VERSION} 🎉" \
401
+ --body "$PR_BODY" \
402
+ --base main \
403
+ --head "$IDEAL_PR_BRANCH")
404
+
405
+ PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
406
+ echo " ├── ✨ pr recreated: #$PR_NUMBER (was #$FOUND_PR_NUMBER)"
407
+ echo " └── 🌊 action: recreated"
408
+ echo "action=recreated" >> $GITHUB_OUTPUT
409
+ echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
410
+ else
411
+ # branch name matches, update in place
412
+ echo " ├── upsert rebased commit..."
413
+ COMMIT_SHA=$(upsert_rebased_commit "$FOUND_PR_BRANCH" "$MAIN_SHA" "chore(release): ${NEXT_VERSION} 🎉")
414
+ echo " ├── commit: ${COMMIT_SHA:0:7}"
415
+
416
+ # update pr metadata
417
+ echo " ├── update pr metadata..."
418
+ gh pr edit "$FOUND_PR_NUMBER" \
419
+ --title "chore(release): ${NEXT_VERSION} 🎉" \
420
+ --body "$PR_BODY"
421
+
422
+ echo " ├── ✨ pr updated: #$FOUND_PR_NUMBER"
423
+ echo " └── 🌊 action: updated"
424
+ echo "action=updated" >> $GITHUB_OUTPUT
425
+ echo "pr-number=$FOUND_PR_NUMBER" >> $GITHUB_OUTPUT
426
+ fi
384
427
  else
385
428
  BRANCH="release/${NEXT_VERSION}"
386
429
  echo " ├── found-pr: (none)"
387
430
  echo " ├── branch: $BRANCH"
388
431
 
389
432
  # upsert rebased commit (creates branch if missing)
390
- echo " ├── upserting rebased commit..."
433
+ echo " ├── upsert rebased commit..."
391
434
  COMMIT_SHA=$(upsert_rebased_commit "$BRANCH" "$MAIN_SHA" "chore(release): ${NEXT_VERSION} 🎉")
392
435
  echo " ├── commit: ${COMMIT_SHA:0:7}"
393
436
 
394
437
  # create pr
395
- echo " ├── creating pr..."
438
+ echo " ├── create pr..."
396
439
  PR_URL=$(gh pr create \
397
440
  --title "chore(release): ${NEXT_VERSION} 🎉" \
398
441
  --body "$PR_BODY" \
@@ -9,7 +9,7 @@
9
9
  "@swc/jest": "@declapract{check.minVersion('0.2.39')}"
10
10
  },
11
11
  "scripts": {
12
- "test:auth": "[ \"$ECHO\" = 'true' ] && echo 'source .agent/repo=.this/role=any/skills/use.apikeys.sh' || bash -c 'source .agent/repo=.this/role=any/skills/use.apikeys.sh'",
12
+ "test:auth": "[ \"$ECHO\" = 'true' ] && echo '. .agent/repo=.this/role=any/skills/use.apikeys.sh' || . .agent/repo=.this/role=any/skills/use.apikeys.sh",
13
13
  "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
14
14
  "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
15
15
  "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "declapract-typescript-ehmpathy",
3
3
  "author": "ehmpathy",
4
4
  "description": "declapract best practices declarations for typescript",
5
- "version": "0.47.27",
5
+ "version": "0.47.29",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
8
  "repository": "ehmpathy/declapract-typescript-ehmpathy",