Skip to content

Commit ca6bd05

Browse files
rucchoclaude
andcommitted
ci: skip pull request creation when only the analysis cache changes
The Update Builtin Tasks workflow opened a pull request whenever a new Unity version was found, even when the regenerated built-in tasks were identical to the ones already committed. Such a pull request carries no reviewable change. The generated code and the analysis cache are now compared separately against the default branch. A pull request is created only when the generated code differs. When only the analysis cache differs, the cache is committed directly to the working branch instead, so that the analyzed versions are not analyzed again on the next run. To make the cache reusable before the working branch is merged, the workflow now restores the analysis cache from that branch at the beginning of the run. Only the cache directory is restored, so the pull request is still opened against the default branch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 8dfa715 commit ca6bd05

1 file changed

Lines changed: 89 additions & 2 deletions

File tree

‎.github/workflows/update-builtin-tasks.yml‎

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Update Builtin Tasks
33
# Regenerate the built-in build tasks (Tasks.*.g.cs) for newly released Unity versions
44
# and open/update a Pull Request together with the persisted analysis cache (AnalysisCache/*.json).
55
#
6+
# When a new Unity version turns out to produce no change in the generated code, no Pull Request
7+
# is created. The analysis cache is still committed to the working branch so that the next run can
8+
# reuse it instead of analyzing the same version again.
9+
#
610
# - schedule: periodic run (new tags are detected via the ls-remote pre-check)
711
# - workflow_dispatch: manual run
812
on:
@@ -20,14 +24,40 @@ permissions:
2024
pull-requests: write
2125

2226
env:
27+
BRANCH: auto/update-builtin-tasks
2328
CACHE_DIR: BuildMagic.Externals/BuildMagic.BuiltinTaskGenerator/AnalysisCache
29+
GENERATED_DIR: Packages/jp.co.cyberagent.buildmagic/BuildMagic/Editor/BuiltIn/Generated
2430
OUTPUT_DIR: ../../Packages/jp.co.cyberagent.buildmagic/BuildMagic/Editor/BuiltIn/Generated
2531

2632
jobs:
2733
update:
2834
runs-on: ubuntu-latest
2935
steps:
36+
# The working branch has to be committed to and pushed from this checkout, so the full
37+
# history is fetched instead of the default shallow clone.
3038
- uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
# Restore the analysis cache accumulated on the working branch, so that versions already
43+
# analyzed by a previous run are not analyzed again. Only the cache directory is restored:
44+
# the checked out branch stays the default branch so that a Pull Request is still opened
45+
# against it.
46+
- name: Restore analysis cache from the working branch
47+
run: |
48+
set -euo pipefail
49+
if ! git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
50+
echo "Branch $BRANCH does not exist yet; using the cache on the default branch."
51+
exit 0
52+
fi
53+
54+
git fetch origin "$BRANCH"
55+
if git checkout "origin/$BRANCH" -- "$CACHE_DIR"; then
56+
git reset --quiet -- "$CACHE_DIR"
57+
echo "Restored the analysis cache from $BRANCH."
58+
else
59+
echo "Branch $BRANCH has no analysis cache; using the cache on the default branch."
60+
fi
3161
3262
# Pre-check whether UnityCsReference has any new "f" release tags that are not yet cached.
3363
# A manual run with force_analyze=true always proceeds.
@@ -85,11 +115,35 @@ jobs:
85115
dotnet run --configuration Release -- generate -o "$OUTPUT_DIR" \
86116
${{ github.event.inputs.force_analyze == 'true' && '-f' || '' }}
87117
88-
- name: Create or update Pull Request
118+
# Distinguish "the generated code changed" from "only the analysis cache changed".
119+
# Both are measured against the checked out default branch.
120+
- name: Detect changes
121+
id: diff
89122
if: steps.check.outputs.has_new == 'true'
123+
run: |
124+
set -euo pipefail
125+
git add --all -- "$GENERATED_DIR" "$CACHE_DIR"
126+
127+
if git diff --cached --quiet HEAD -- "$GENERATED_DIR"; then
128+
code_changed=false
129+
else
130+
code_changed=true
131+
fi
132+
if git diff --cached --quiet HEAD -- "$CACHE_DIR"; then
133+
cache_changed=false
134+
else
135+
cache_changed=true
136+
fi
137+
138+
echo "code_changed=$code_changed" >> "$GITHUB_OUTPUT"
139+
echo "cache_changed=$cache_changed" >> "$GITHUB_OUTPUT"
140+
echo "Generated code changed: $code_changed / analysis cache changed: $cache_changed"
141+
142+
- name: Create or update Pull Request
143+
if: steps.diff.outputs.code_changed == 'true'
90144
uses: peter-evans/create-pull-request@v6
91145
with:
92-
branch: auto/update-builtin-tasks
146+
branch: ${{ env.BRANCH }}
93147
title: 'chore: update builtin tasks for new Unity versions'
94148
commit-message: 'chore: regenerate builtin tasks for new Unity versions'
95149
body: |
@@ -103,3 +157,36 @@ jobs:
103157
add-paths: |
104158
Packages/jp.co.cyberagent.buildmagic/BuildMagic/Editor/BuiltIn/Generated/**
105159
BuildMagic.Externals/BuildMagic.BuiltinTaskGenerator/AnalysisCache/**
160+
161+
# No Pull Request is worth opening, but the analysis results are still worth keeping:
162+
# commit them to the working branch so that the next run can reuse them.
163+
- name: Commit analysis cache only
164+
if: steps.diff.outputs.code_changed == 'false' && steps.diff.outputs.cache_changed == 'true'
165+
run: |
166+
set -euo pipefail
167+
git config user.name 'github-actions[bot]'
168+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
169+
170+
# Keep the freshly generated cache aside, because switching branches discards it.
171+
staging=$(mktemp -d)
172+
cp -R "$CACHE_DIR/." "$staging/"
173+
174+
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
175+
git fetch origin "$BRANCH"
176+
git checkout --force -B "$BRANCH" "origin/$BRANCH"
177+
else
178+
git checkout --force -B "$BRANCH"
179+
fi
180+
181+
mkdir -p "$CACHE_DIR"
182+
cp -R "$staging/." "$CACHE_DIR/"
183+
git add --all -- "$CACHE_DIR"
184+
185+
if git diff --cached --quiet HEAD -- "$CACHE_DIR"; then
186+
echo "The working branch already contains this analysis cache; nothing to commit."
187+
exit 0
188+
fi
189+
190+
git commit -m 'chore: update analysis cache for new Unity versions'
191+
git push origin "$BRANCH"
192+
echo "Committed the analysis cache to $BRANCH without opening a Pull Request."

0 commit comments

Comments
 (0)