-
Notifications
You must be signed in to change notification settings - Fork 137
142 lines (122 loc) · 5.06 KB
/
this-codebase-smells.yml
File metadata and controls
142 lines (122 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: This Codebase Smells
on:
workflow_dispatch: {}
schedule:
# Hourly on Sundays (UTC); we gate to run only at 16:00 Europe/Zurich
- cron: '0 * * * 0'
permissions:
contents: read
discussions: write
env:
TZ: Europe/Zurich
COPILOT_MODEL: 'gpt-5.4'
COPILOT_REASONING_EFFORT: 'xhigh'
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- name: Time gate (run only at 16:00 Europe/Zurich)
id: gate
if: ${{ github.event_name == 'schedule' }}
run: |
hour=$(TZ=Europe/Zurich date +%H)
if [ "$hour" = "16" ]; then
echo "run=true" >> "$GITHUB_OUTPUT"
echo "It's 16:00 Europe/Zurich; proceeding."
else
echo "run=false" >> "$GITHUB_OUTPUT"
echo "Not 16:00 Europe/Zurich; skipping subsequent steps."
fi
- uses: actions/checkout@v4
if: ${{ steps.gate.outputs.run != 'false' }}
- uses: actions/setup-node@v4
if: ${{ steps.gate.outputs.run != 'false' }}
with:
node-version: '22'
cache: 'npm'
- name: Install GitHub Copilot CLI
if: ${{ steps.gate.outputs.run != 'false' }}
run: |
npm install -g @github/copilot
copilot --version
- name: Run GitHub Copilot CLI analysis
if: ${{ steps.gate.outputs.run != 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
run: |
set -o pipefail
mkdir -p "$RUNNER_TEMP"
# Read the prompt and run Copilot CLI in programmatic mode
copilot_args=(
-p "$(cat .github/workflows/this-codebase-smells/prompt.md)"
--allow-tool 'shell(*)'
--allow-tool 'read_file(*)'
--allow-tool 'glob(*)'
)
if [ -n "${COPILOT_MODEL:-}" ]; then
echo "Using requested Copilot model: $COPILOT_MODEL"
copilot_args+=(--model "$COPILOT_MODEL")
else
echo "Using Copilot CLI default model"
fi
if [ -n "${COPILOT_REASONING_EFFORT:-}" ]; then
echo "Using requested reasoning effort: $COPILOT_REASONING_EFFORT"
copilot_args+=(--effort "$COPILOT_REASONING_EFFORT")
fi
copilot "${copilot_args[@]}" 2>&1 | tee "$RUNNER_TEMP/raw_report.md"
# Extract only the content between our markers for the Discussion body
awk '/^---BEGIN REPORT---$/ {flag=1; next} /^---END REPORT---$/ {flag=0} flag' "$RUNNER_TEMP/raw_report.md" > "$RUNNER_TEMP/report.md"
if [ ! -s "$RUNNER_TEMP/report.md" ]; then
echo "Report markers not found or empty report produced"
echo "First 200 lines of raw output for debugging:"
head -n 200 "$RUNNER_TEMP/raw_report.md" || true
echo "Full raw output:"
cat "$RUNNER_TEMP/raw_report.md" || true
exit 1
fi
- name: Resolve Discussion category ID
if: ${{ steps.gate.outputs.run != 'false' }}
id: cat
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
owner="intellectronica"
repo="ruler"
gh api graphql -f query='
query($owner:String!,$repo:String!){
repository(owner:$owner,name:$repo){
discussionCategories(first:100){
nodes{ id name }
}
}
}' -F owner="$owner" -F repo="$repo" > cat.json
cat_id=$(jq -r '.data.repository.discussionCategories.nodes[] | select(.name=="Workflow") | .id' cat.json)
if [ -z "$cat_id" ]; then echo "Workflow discussion category not found"; exit 1; fi
echo "id=$cat_id" >> "$GITHUB_OUTPUT"
- name: Create Discussion
if: ${{ steps.gate.outputs.run != 'false' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
owner="intellectronica"
repo="ruler"
repo_id=$(gh api "repos/$owner/$repo" --jq .node_id)
if [ -z "$repo_id" ]; then echo "Failed to get repository node_id"; exit 1; fi
title="This Codebase Smells! [$(TZ=Europe/Zurich date +%F)]"
# JSON-escape the report body safely
body_json=$(jq -Rs . < "$RUNNER_TEMP/report.md")
# Build GraphQL payload
jq -n --arg repoId "$repo_id" \
--arg catId "${{ steps.cat.outputs.id }}" \
--arg title "$title" \
--argjson body "$body_json" \
'{
query: "mutation($repoId:ID!,$categoryId:ID!,$title:String!,$body:String!){ createDiscussion(input:{repositoryId:$repoId, categoryId:$categoryId, title:$title, body:$body}){ discussion{ url } } }",
variables: { repoId: $repoId, categoryId: $catId, title: $title, body: $body }
}' > payload.json
gh api graphql --input payload.json -q '.data.createDiscussion.discussion.url' | tee discussion_url.txt
- name: Show Discussion URL
if: ${{ steps.gate.outputs.run != 'false' }}
run: |
echo "Discussion created:"
cat discussion_url.txt