Repository navigation
Update Builtin Tasks #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Builtin Tasks | |
| # Regenerate the built-in build tasks (Tasks.*.g.cs) for newly released Unity versions | |
| # and open/update a Pull Request together with the persisted analysis cache (AnalysisCache/*.json). | |
| # | |
| # When a new Unity version turns out to produce no change in the generated code, no Pull Request | |
| # is created. The analysis cache is still committed to the working branch so that the next run can | |
| # reuse it instead of analyzing the same version again. | |
| # | |
| # - schedule: periodic run (new tags are detected via the ls-remote pre-check) | |
| # - workflow_dispatch: manual run | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 1' # Every Monday 00:00 UTC (adjust the cadence as needed) | |
| workflow_dispatch: | |
| inputs: | |
| force_analyze: | |
| description: 'Ignore the cached analysis results and re-analyze all versions (-f)' | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| env: | |
| BRANCH: auto/update-builtin-tasks | |
| CACHE_DIR: BuildMagic.Externals/BuildMagic.BuiltinTaskGenerator/AnalysisCache | |
| GENERATED_DIR: Packages/jp.co.cyberagent.buildmagic/BuildMagic/Editor/BuiltIn/Generated | |
| OUTPUT_DIR: ../../Packages/jp.co.cyberagent.buildmagic/BuildMagic/Editor/BuiltIn/Generated | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # The working branch has to be committed to and pushed from this checkout, so the full | |
| # history is fetched instead of the default shallow clone. | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # Restore the analysis cache accumulated on the working branch, so that versions already | |
| # analyzed by a previous run are not analyzed again. Only the cache directory is restored: | |
| # the checked out branch stays the default branch so that a Pull Request is still opened | |
| # against it. | |
| - name: Restore analysis cache from the working branch | |
| run: | | |
| set -euo pipefail | |
| if ! git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then | |
| echo "Branch $BRANCH does not exist yet; using the cache on the default branch." | |
| exit 0 | |
| fi | |
| git fetch origin "$BRANCH" | |
| if git checkout "origin/$BRANCH" -- "$CACHE_DIR"; then | |
| git reset --quiet -- "$CACHE_DIR" | |
| echo "Restored the analysis cache from $BRANCH." | |
| else | |
| echo "Branch $BRANCH has no analysis cache; using the cache on the default branch." | |
| fi | |
| # Pre-check whether UnityCsReference has any new "f" release tags that are not yet cached. | |
| # A manual run with force_analyze=true always proceeds. | |
| - name: Check for new Unity versions | |
| id: check | |
| run: | | |
| set -euo pipefail | |
| if [ "${{ github.event.inputs.force_analyze }}" = "true" ]; then | |
| echo "force_analyze requested; running unconditionally." | |
| echo "has_new=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| remote_tags=$(git ls-remote --tags https://github.com/Unity-Technologies/UnityCsReference.git \ | |
| | sed 's#.*refs/tags/##; s/\^{}//' \ | |
| | grep -E '^[0-9]+\.[0-9]+\.[0-9]+f[0-9]+$' \ | |
| | sort -u) | |
| has_new=false | |
| new_list="" | |
| for tag in $remote_tags; do | |
| major=${tag%%.*} | |
| rest=${tag#*.} | |
| minor=${rest%%.*} | |
| # Ignore versions older than the default min version (2022.3.0f1). | |
| if [ "$major" -lt 2022 ]; then continue; fi | |
| if [ "$major" -eq 2022 ] && [ "$minor" -lt 3 ]; then continue; fi | |
| if [ ! -f "$CACHE_DIR/$tag.json" ]; then | |
| has_new=true | |
| new_list="$new_list $tag" | |
| fi | |
| done | |
| echo "has_new=$has_new" >> "$GITHUB_OUTPUT" | |
| if [ "$has_new" = "true" ]; then | |
| echo "New Unity versions detected:$new_list" | |
| else | |
| echo "No new Unity versions. Skipping generation." | |
| fi | |
| - uses: actions/setup-dotnet@v4 | |
| if: steps.check.outputs.has_new == 'true' | |
| with: | |
| dotnet-version: '10.0.x' | |
| # A fresh full clone of UnityCsReference is performed by the tool itself. | |
| # It is not cached: clones only happen on the rare runs that find a new version, | |
| # and for a repo this size caching brings little benefit while consuming the cache quota. | |
| - name: Run generator | |
| if: steps.check.outputs.has_new == 'true' | |
| env: | |
| BUILDMAGIC_LIBRARY_PATH: ${{ github.workspace }}/${{ env.CACHE_DIR }} | |
| working-directory: BuildMagic.Externals/BuildMagic.BuiltinTaskGenerator | |
| run: | | |
| dotnet run --configuration Release -- generate -o "$OUTPUT_DIR" \ | |
| ${{ github.event.inputs.force_analyze == 'true' && '-f' || '' }} | |
| # Distinguish "the generated code changed" from "only the analysis cache changed". | |
| # Both are measured against the checked out default branch. | |
| - name: Detect changes | |
| id: diff | |
| if: steps.check.outputs.has_new == 'true' | |
| run: | | |
| set -euo pipefail | |
| git add --all -- "$GENERATED_DIR" "$CACHE_DIR" | |
| if git diff --cached --quiet HEAD -- "$GENERATED_DIR"; then | |
| code_changed=false | |
| else | |
| code_changed=true | |
| fi | |
| if git diff --cached --quiet HEAD -- "$CACHE_DIR"; then | |
| cache_changed=false | |
| else | |
| cache_changed=true | |
| fi | |
| echo "code_changed=$code_changed" >> "$GITHUB_OUTPUT" | |
| echo "cache_changed=$cache_changed" >> "$GITHUB_OUTPUT" | |
| echo "Generated code changed: $code_changed / analysis cache changed: $cache_changed" | |
| - name: Create or update Pull Request | |
| if: steps.diff.outputs.code_changed == 'true' | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| branch: ${{ env.BRANCH }} | |
| title: 'chore: update builtin tasks for new Unity versions' | |
| commit-message: 'chore: regenerate builtin tasks for new Unity versions' | |
| body: | | |
| Automatically generated built-in build tasks for newly released Unity versions. | |
| - `Tasks.*.g.cs`: regenerated build tasks | |
| - `AnalysisCache/*.json`: persisted analysis cache (ensures deterministic output) | |
| This PR is created by the `Update Builtin Tasks` workflow. If it is left unmerged | |
| and the workflow runs again, this branch will be updated in place. | |
| add-paths: | | |
| Packages/jp.co.cyberagent.buildmagic/BuildMagic/Editor/BuiltIn/Generated/** | |
| BuildMagic.Externals/BuildMagic.BuiltinTaskGenerator/AnalysisCache/** | |
| # No Pull Request is worth opening, but the analysis results are still worth keeping: | |
| # commit them to the working branch so that the next run can reuse them. | |
| - name: Commit analysis cache only | |
| if: steps.diff.outputs.code_changed == 'false' && steps.diff.outputs.cache_changed == 'true' | |
| run: | | |
| set -euo pipefail | |
| git config user.name 'github-actions[bot]' | |
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| # Keep the freshly generated cache aside, because switching branches discards it. | |
| staging=$(mktemp -d) | |
| cp -R "$CACHE_DIR/." "$staging/" | |
| if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then | |
| git fetch origin "$BRANCH" | |
| git checkout --force -B "$BRANCH" "origin/$BRANCH" | |
| else | |
| git checkout --force -B "$BRANCH" | |
| fi | |
| mkdir -p "$CACHE_DIR" | |
| cp -R "$staging/." "$CACHE_DIR/" | |
| git add --all -- "$CACHE_DIR" | |
| if git diff --cached --quiet HEAD -- "$CACHE_DIR"; then | |
| echo "The working branch already contains this analysis cache; nothing to commit." | |
| exit 0 | |
| fi | |
| git commit -m 'chore: update analysis cache for new Unity versions' | |
| git push origin "$BRANCH" | |
| echo "Committed the analysis cache to $BRANCH without opening a Pull Request." |