Skip to content

Commit f00eaab

Browse files
authored
Fix release automation workflows (#3110)
* Fix release draft update job * Fix release followup workflows * Ensure config types check reports status
1 parent 92bdc27 commit f00eaab

4 files changed

Lines changed: 96 additions & 23 deletions

File tree

.github/workflows/changelog.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
PATCH_PATH: ${{ runner.temp }}/changelog.patch
6969
run: |
7070
set -euo pipefail
71+
git add --intent-to-add -- CHANGELOG.md
7172
if git diff --quiet -- CHANGELOG.md; then
7273
echo "has_changes=false" >> "$GITHUB_OUTPUT"
7374
exit 0

.github/workflows/config-types.yaml

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,87 @@ name: Check config types
22

33
on:
44
push:
5-
paths:
6-
- 'src/datamodel_code_generator/config.py'
7-
- 'src/datamodel_code_generator/_types/**'
8-
- 'pyproject.toml'
9-
- '.github/workflows/config-types.yaml'
105
pull_request:
11-
paths:
12-
- 'src/datamodel_code_generator/config.py'
13-
- 'src/datamodel_code_generator/_types/**'
14-
- 'pyproject.toml'
15-
- '.github/workflows/config-types.yaml'
166

177
permissions:
188
contents: read
9+
pull-requests: read
1910

2011
jobs:
2112
config-types:
2213
runs-on: ubuntu-latest
2314
steps:
15+
- name: Check config type inputs
16+
id: changes
17+
env:
18+
GH_TOKEN: ${{ github.token }}
19+
run: |
20+
set -euo pipefail
21+
22+
if [ "${{ github.event_name }}" = "pull_request" ]; then
23+
FILES=$(gh api --paginate \
24+
"/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
25+
--jq '.[].filename')
26+
elif [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
27+
echo "needs_check=true" >> "$GITHUB_OUTPUT"
28+
exit 0
29+
else
30+
COMPARE_JSON=$(gh api \
31+
"/repos/${{ github.repository }}/compare/${{ github.event.before }}...${{ github.sha }}") || {
32+
echo "compare API failed; running config-types check defensively."
33+
echo "needs_check=true" >> "$GITHUB_OUTPUT"
34+
exit 0
35+
}
36+
37+
FILE_COUNT=$(jq '.files | length' <<< "$COMPARE_JSON")
38+
if [ "$FILE_COUNT" -ge 300 ]; then
39+
echo "compare API may be truncated ($FILE_COUNT files); running config-types check defensively."
40+
echo "needs_check=true" >> "$GITHUB_OUTPUT"
41+
exit 0
42+
fi
43+
44+
FILES=$(jq -r '.files[].filename' <<< "$COMPARE_JSON")
45+
fi
46+
47+
NEEDS_CHECK=false
48+
while IFS= read -r file; do
49+
case "$file" in
50+
src/datamodel_code_generator/config.py)
51+
NEEDS_CHECK=true
52+
;;
53+
src/datamodel_code_generator/_types/*)
54+
NEEDS_CHECK=true
55+
;;
56+
pyproject.toml)
57+
NEEDS_CHECK=true
58+
;;
59+
.github/workflows/config-types.yaml)
60+
NEEDS_CHECK=true
61+
;;
62+
esac
63+
done <<< "$FILES"
64+
65+
echo "needs_check=$NEEDS_CHECK" >> "$GITHUB_OUTPUT"
66+
67+
- name: Skip config type check
68+
if: steps.changes.outputs.needs_check != 'true'
69+
run: echo "No config type inputs changed."
70+
2471
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
72+
if: steps.changes.outputs.needs_check == 'true'
2573
with:
2674
persist-credentials: false
2775

2876
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5
77+
if: steps.changes.outputs.needs_check == 'true'
2978
with:
3079
enable-cache: true
3180

32-
- run: uv python install 3.14
81+
- if: steps.changes.outputs.needs_check == 'true'
82+
run: uv python install 3.14
3383

34-
- run: uv tool install --python 3.14 tox --with tox-uv
84+
- if: steps.changes.outputs.needs_check == 'true'
85+
run: uv tool install --python 3.14 tox --with tox-uv
3586

36-
- run: tox -e config-types -- --check
87+
- if: steps.changes.outputs.needs_check == 'true'
88+
run: tox -e config-types -- --check

.github/workflows/release-draft.yaml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
permissions:
111111
contents: write
112112
issues: write
113-
pull-requests: read
113+
pull-requests: write
114114
steps:
115115
- name: Download analysis artifact
116116
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
@@ -147,14 +147,24 @@ jobs:
147147
env:
148148
GH_TOKEN: ${{ github.token }}
149149
run: |
150-
gh pr edit ${{ github.event.pull_request.number }} --add-label "breaking-change-analyzed"
150+
gh api \
151+
--method POST \
152+
-H "Accept: application/vnd.github+json" \
153+
"/repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/labels" \
154+
-f labels[]="breaking-change-analyzed" \
155+
--silent
151156
152157
- name: Add breaking-change label if applicable
153158
if: steps.analysis.outputs.has_breaking_changes == 'true'
154159
env:
155160
GH_TOKEN: ${{ github.token }}
156161
run: |
157-
gh pr edit ${{ github.event.pull_request.number }} --add-label "breaking-change"
162+
gh api \
163+
--method POST \
164+
-H "Accept: application/vnd.github+json" \
165+
"/repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/labels" \
166+
-f labels[]="breaking-change" \
167+
--silent
158168
159169
- name: Post analysis result to PR
160170
env:
@@ -165,7 +175,8 @@ jobs:
165175
run: |
166176
# Use temp file to avoid shell escaping issues with special characters
167177
TMPFILE=$(mktemp)
168-
trap 'rm -f "$TMPFILE"' EXIT
178+
TMPJSON=$(mktemp)
179+
trap 'rm -f "$TMPFILE" "$TMPJSON"' EXIT
169180
170181
# Build comment using printf to avoid YAML parsing issues with markdown
171182
{
@@ -182,7 +193,14 @@ jobs:
182193
printf '*This analysis was performed by Claude Code Action*\n'
183194
} > "$TMPFILE"
184195
185-
gh pr comment ${{ github.event.pull_request.number }} --body-file "$TMPFILE"
196+
jq -n --rawfile body "$TMPFILE" '{body: $body}' > "$TMPJSON"
197+
198+
gh api \
199+
--method POST \
200+
-H "Accept: application/vnd.github+json" \
201+
"/repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/comments" \
202+
--input "$TMPJSON" \
203+
--silent
186204
187205
- name: Calculate version and update draft release
188206
env:
@@ -193,7 +211,7 @@ jobs:
193211
set -euo pipefail
194212
195213
# Get latest published release tag and strip "v" prefix if present
196-
LATEST_TAG_RAW=$(gh release list --limit 1 --exclude-drafts --json tagName --jq '.[0].tagName // "0.0.0"')
214+
LATEST_TAG_RAW=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 1 --exclude-drafts --json tagName --jq '.[0].tagName // "0.0.0"')
197215
LATEST_TAG="${LATEST_TAG_RAW#v}"
198216
LATEST_TAG="${LATEST_TAG#V}"
199217
echo "Latest published tag: $LATEST_TAG_RAW (parsed as: $LATEST_TAG)"
@@ -213,7 +231,7 @@ jobs:
213231
214232
# Check if draft release exists (use jq to extract first draft tag safely)
215233
# Keep raw tag name for gh commands, strip prefix only for version comparison
216-
DRAFT_TAG_RAW=$(gh release list --json tagName,isDraft --jq '[.[] | select(.isDraft == true)] | .[0].tagName // ""')
234+
DRAFT_TAG_RAW=$(gh release list --repo "$GITHUB_REPOSITORY" --json tagName,isDraft --jq '[.[] | select(.isDraft == true)] | .[0].tagName // ""')
217235
DRAFT_TAG="${DRAFT_TAG_RAW#v}"
218236
DRAFT_TAG="${DRAFT_TAG#V}"
219237
BC_SOURCE_TAG_RAW="$DRAFT_TAG_RAW"
@@ -274,7 +292,7 @@ jobs:
274292
# Get existing draft body if updating (only if DRAFT_TAG_RAW is set, meaning we're updating same version)
275293
EXISTING_BC=""
276294
if [ -n "$BC_SOURCE_TAG_RAW" ]; then
277-
EXISTING_BODY=$(gh release view "$BC_SOURCE_TAG_RAW" --json body --jq '.body // ""')
295+
EXISTING_BODY=$(gh release view "$BC_SOURCE_TAG_RAW" --repo "$GITHUB_REPOSITORY" --json body --jq '.body // ""')
278296
# Extract existing Breaking Changes section content
279297
# Use awk for precise extraction - stops at any ## header that's not "## Breaking Changes"
280298
if echo "$EXISTING_BODY" | grep -q '^## Breaking Changes$'; then
@@ -336,19 +354,21 @@ jobs:
336354
if [ -n "$DRAFT_TAG_RAW" ] && [ "$DRAFT_TAG" = "$NEXT_VERSION" ]; then
337355
echo "Updating existing draft release: $DRAFT_TAG_RAW"
338356
echo "$RELEASE_BODY" | gh release edit "$DRAFT_TAG_RAW" \
357+
--repo "$GITHUB_REPOSITORY" \
339358
--title "$NEXT_VERSION" \
340359
--notes-file -
341360
else
342361
echo "Creating new draft release: $NEXT_VERSION"
343362
# Create new draft first, then delete old one (to prevent data loss)
344363
if echo "$RELEASE_BODY" | gh release create "$NEXT_VERSION" \
364+
--repo "$GITHUB_REPOSITORY" \
345365
--title "$NEXT_VERSION" \
346366
--notes-file - \
347367
--draft; then
348368
# Only delete old draft after successful creation
349369
if [ -n "$OLD_DRAFT_TAG" ]; then
350370
echo "Deleting old draft: $OLD_DRAFT_TAG"
351-
gh release delete "$OLD_DRAFT_TAG" --yes 2>/dev/null || true
371+
gh release delete "$OLD_DRAFT_TAG" --repo "$GITHUB_REPOSITORY" --yes 2>/dev/null || true
352372
fi
353373
else
354374
echo "Failed to create new draft release"

.github/workflows/release-notify.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
permissions:
1313
contents: read
1414
issues: write
15-
pull-requests: read
15+
pull-requests: write
1616
env:
1717
TARGET_OWNER: koxudaxi
1818
TARGET_REPO: datamodel-code-generator

0 commit comments

Comments
 (0)