22#
33# SPDX-License-Identifier: MIT
44
5- HEAD := $(shell git rev-parse --verify HEAD)
5+ HEAD = $(shell git rev-parse --verify HEAD)
6+ ENGINE ?= junie
67SKILL_FILE := .ai/skills/commit-or-pr-message/SKILL.md
78
9+ # kimi uses --skills-dir for auto-discovery; other engines need --skill-file
10+ ifeq ($(ENGINE ) ,kimi)
11+ SKILL_ARG :=
12+ else
13+ SKILL_ARG := --skill-file "$(SKILL_FILE ) "
14+ endif
15+
816define gh_head_run_id
9- gh run list --workflow $(1 ) --commit $(HEAD ) --json databaseId --jq '.[0].[" databaseId"] '
17+ gh run list --workflow $(1 ) --commit $(HEAD ) --json databaseId --jq '.[0].databaseId // "" '
1018endef
1119
1220.PHONY : build
1624.PHONY : merge
1725merge : merge-head push
1826 @if gh pr view --json number > /dev/null 2>&1 ; then \
19- $(MAKE ) watch-full create-pr; \
27+ $(MAKE ) watch-build create-pr; \
2028 else \
21- $(MAKE ) create-pr watch-full ; \
29+ $(MAKE ) create-pr watch-build ; \
2230 fi
2331 @$(MAKE ) merge-squash
2432
@@ -27,23 +35,23 @@ create-pr: build
2735 head_before=$$(git rev-parse HEAD ) ; \
2836 if gh pr view --json number > /dev/null 2>&1 ; then \
2937 printf ' %s\n' " Updating PR message..." ; \
30- ./scripts/ pr-message.sh --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
31- --skill-file " $( SKILL_FILE ) " || exit 0; \
38+ ./.share/bin/ pr-message.sh --engine " $( ENGINE ) " --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
39+ $( SKILL_ARG ) || exit 0; \
3240 head_after=$$(git rev-parse HEAD ) ; \
3341 if [ " $$ head_before" != " $$ head_after" ]; then \
34- ./scripts/ pr-message.sh --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
35- --skill-file " $( SKILL_FILE ) " || exit 0; \
42+ ./.share/bin/ pr-message.sh --engine " $( ENGINE ) " --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
43+ $( SKILL_ARG ) || exit 0; \
3644 fi ; \
3745 title=$$(cat "$$tmp_dir/title.txt" ) ; \
3846 gh pr edit --title " $$ title" --body-file " $$ tmp_dir/body.txt" || exit 0; \
3947 GH_PAGER=cat gh pr view; \
4048 else \
41- ./scripts/ pr-message.sh --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
42- --skill-file " $( SKILL_FILE ) " || exit 0; \
49+ ./.share/bin/ pr-message.sh --engine " $( ENGINE ) " --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
50+ $( SKILL_ARG ) || exit 0; \
4351 head_after=$$(git rev-parse HEAD ) ; \
4452 if [ " $$ head_before" != " $$ head_after" ]; then \
45- ./scripts/ pr-message.sh --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
46- --skill-file " $( SKILL_FILE ) " || exit 0; \
53+ ./.share/bin/ pr-message.sh --engine " $( ENGINE ) " --title-file " $$ tmp_dir/title.txt" --body-file " $$ tmp_dir/body.txt" \
54+ $( SKILL_ARG ) || exit 0; \
4755 fi ; \
4856 title=$$(cat "$$tmp_dir/title.txt" ) ; \
4957 gh pr create --title " $$ title" --body-file " $$ tmp_dir/body.txt" || exit 0; \
@@ -64,12 +72,25 @@ merge-squash:
6472 printf ' %s\n' " WARNING: Uncommitted changes detected. Review before merge." 1>&2 ; \
6573 fi ; \
6674 printf ' %s' " Proceed with squash merge? [Y/n] " ; \
67- read -r reply; \
75+ read -r reply < /dev/tty ; \
6876 case " $$ reply" in \
69- " " | y | Y | yes | YES) ;; \
70- * ) printf ' %s\n ' " Merge cancelled. " ; exit 1 ;; \
77+ [Nn] | [Nn][Oo]) printf ' %s\n ' " Merge cancelled. " ; exit 1 ;; \
78+ * ) ;; \
7179 esac ; \
7280 gh pr merge --squash --delete-branch --auto
7381
74- watch-full :
75- @gh run watch $$($(call gh_head_run_id, "full") ) --exit-status
82+ .PHONY : watch-build
83+ watch-build :
84+ @printf " Waiting for workflow 'build' to start on commit $( HEAD) ...\n"
85+ @run_id=" " ; \
86+ for i in $$ (seq 1 12); do \
87+ run_id=$$($(call gh_head_run_id, "build") ) ; \
88+ if [ -n " $$ run_id" ]; then break ; fi ; \
89+ printf " Run not found yet, retrying in 5s... ($$ i/12)\n" ; \
90+ sleep 5; \
91+ done ; \
92+ if [ -z " $$ run_id" ]; then \
93+ printf " Error: Workflow 'build' did not start within 60 seconds.\n" >&2 ; \
94+ exit 1; \
95+ fi ; \
96+ gh run watch " $$ run_id" --exit-status
0 commit comments