Skip to content

Commit 64ce962

Browse files
committed
Copier Template: Github Workflows: claude: Factor into project-specific portion and cross-repo workflow.
Closes #8. (Coauthor: Anthropic Claude Sonnet 4.0.)
1 parent 473d8f4 commit 64ce962

3 files changed

Lines changed: 89 additions & 52 deletions

File tree

.github/workflows/claude.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ jobs:
6969
Bash(hatch:*)
7070
Bash(pip:*)
7171
Bash(python:*)
72-
Edit(**)
73-
Write(**)
72+
Edit
73+
Write
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Reusable Claude Agent
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
allowed-tools:
7+
description: 'Space-separated list of allowed tools for Claude.'
8+
required: true
9+
type: string
10+
python-version:
11+
required: true
12+
type: string
13+
timeout-minutes:
14+
description: 'Timeout for Claude execution.'
15+
default: 20
16+
required: false
17+
type: number
18+
secrets:
19+
anthropic-api-key:
20+
description: 'Anthropic API key for Claude access.'
21+
required: true
22+
23+
jobs:
24+
25+
claude:
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
pull-requests: read
30+
issues: read
31+
id-token: write
32+
steps:
33+
34+
- name: Prepare Python and Hatch
35+
uses: emcd/python-project-common/.github/actions/python-hatch@master
36+
with:
37+
python-version: '${{ inputs.python-version }}'
38+
39+
- name: Create CLAUDE.md Symlink
40+
run: |
41+
set -eu
42+
if [ -f ".auxiliary/configuration/conventions.md" ]; then
43+
ln -sf .auxiliary/configuration/conventions.md CLAUDE.md
44+
echo "::notice::Created symlink: CLAUDE.md -> .auxiliary/configuration/conventions.md"
45+
else
46+
echo "::error file=.auxiliary/configuration/conventions.md::Required conventions file not found"
47+
exit 1
48+
fi
49+
shell: bash
50+
51+
- name: Execute Claude Code
52+
id: claude
53+
uses: anthropics/claude-code-action@beta
54+
with:
55+
allowed_tools: ${{ inputs.allowed-tools }}
56+
anthropic_api_key: ${{ secrets.anthropic-api-key }}
57+
timeout_minutes: ${{ inputs.timeout-minutes }}
58+
trigger_phrase: "/claude"

template/.github/workflows/claude.yaml.jinja

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,36 @@ on:
1212

1313
jobs:
1414

15+
initialize:
16+
uses: ./.github/workflows/core--initializer.yaml
17+
1518
claude:
1619
if: |
17-
{% raw %}(github.event_name == 'issue_comment' && contains(github.event.comment.body, '/claude')) ||
20+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '/claude')) ||
1821
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '/claude')) ||
1922
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '/claude')) ||
20-
(github.event_name == 'issues' && (contains(github.event.issue.body, '/claude') || contains(github.event.issue.title, '/claude'))){% endraw %}
21-
runs-on: ubuntu-latest
22-
permissions:
23-
contents: read
24-
pull-requests: read
25-
issues: read
26-
id-token: write
27-
steps:
28-
29-
- name: Clone Repository
30-
uses: actions/checkout@v4
31-
32-
- name: Prepare Python and Hatch
33-
uses: ./.github/actions/python-hatch
34-
with:
35-
needs-clone: false
36-
python-version: '3.10'
37-
38-
- name: Create CLAUDE.md symlink
39-
run: |
40-
if [ -f ".auxiliary/configuration/conventions.md" ]; then
41-
ln -sf .auxiliary/configuration/conventions.md CLAUDE.md
42-
echo "::notice::Created symlink: CLAUDE.md -> .auxiliary/configuration/conventions.md"
43-
else
44-
echo "::error file=.auxiliary/configuration/conventions.md::Required conventions file not found"
45-
exit 1
46-
fi
47-
shell: bash
48-
49-
- name: Run Claude Code
50-
id: claude
51-
uses: anthropics/claude-code-action@beta
52-
with:
53-
anthropic_api_key: {% raw %}'${{ secrets.ANTHROPIC_API_KEY }}'{% endraw %}
54-
trigger_phrase: "/claude"
55-
timeout_minutes: 20
56-
allowed_tools: |
57-
Bash(hatch --env develop run linters)
58-
Bash(hatch --env develop run testers)
59-
Bash(hatch --env develop run docsgen)
60-
Bash(hatch --env develop run packagers)
61-
Bash(hatch run python:*)
62-
Bash(git status)
63-
Bash(git add:*)
64-
Bash(git commit:*)
65-
Bash(python:*)
66-
Bash(pip:*)
67-
Edit(**)
68-
Write(**)
23+
(github.event_name == 'issues' && (contains(github.event.issue.body, '/claude') || contains(github.event.issue.title, '/claude')))
24+
needs: [initialize]
25+
uses: emcd/python-project-common/.github/workflows/xrepo--claude.yaml@{{ _commit }}
26+
with:
27+
allowed-tools: >-
28+
Bash(git add:*)
29+
Bash(git branch:*)
30+
Bash(git checkout:*)
31+
Bash(git diff:*)
32+
Bash(git log:*)
33+
Bash(git ls-files:*)
34+
Bash(git remote:*)
35+
Bash(git reset:*)
36+
Bash(git rev-parse:*)
37+
Bash(git rm:*)
38+
Bash(git status)
39+
Bash(hatch:*)
40+
Bash(pip:*)
41+
Bash(python:*)
42+
Edit
43+
Write
44+
python-version: {% raw %}'${{ fromJSON(needs.initialize.outputs.python-versions)[0] }}'{% endraw %}
45+
timeout-minutes: 20
46+
secrets:
47+
anthropic-api-key: {% raw %}'${{ secrets.ANTHROPIC_API_KEY }}'{% endraw %}

0 commit comments

Comments
 (0)