Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/check-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check for Code Changes

# A push to a PR that changes only Markdown files since a head that already passed CI skips the build and test jobs.
on:
workflow_call:
outputs:
run:
description: "'true' when CI should run the build and test jobs"
value: ${{ jobs.check.outputs.run }}

jobs:
check:
name: Check for code changes
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
outputs:
run: ${{ steps.check.outputs.run }}
steps:
- id: check
shell: bash
env:
GH_TOKEN: ${{ github.token }}
BEFORE: ${{ github.event.action == 'synchronize' && github.event.before || '' }}
HEAD: ${{ github.event.pull_request.head.sha }}
run: |
run=true
if [[ -n "$BEFORE" ]]; then
passed=$(gh api "repos/$GITHUB_REPOSITORY/actions/workflows/ci.yml/runs?head_sha=$BEFORE&event=pull_request&status=success" --jq '.total_count') || passed=0
if [[ "$passed" -gt 0 ]]; then
# The compare API lists at most 300 files; "ahead" rules out force-pushes that dropped commits.
# Markdown under package*/ ships in the UPM package, so it counts as code.
run=$(gh api "repos/$GITHUB_REPOSITORY/compare/$BEFORE...$HEAD" --jq '
if .status == "ahead" and (.files | length) > 0 and (.files | length) < 300
and all(.files[]; [.filename, .previous_filename // empty] | all(endswith(".md") and (startswith("package") | not)))
then "false" else "true" end') || run=true
fi
fi
echo "run=$run" >> "$GITHUB_OUTPUT"
if [[ "$run" == "false" ]]; then
echo "Only Markdown files changed since $BEFORE, which passed CI. Skipping the build and test jobs." >> "$GITHUB_STEP_SUMMARY"
fi
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ jobs:
with:
access_token: ${{ github.token }}

changes:
uses: ./.github/workflows/check-changes.yml
permissions:
actions: read
contents: read

create-unity-matrix:
uses: ./.github/workflows/create-unity-matrix.yml
with:
event-name: ${{ github.event_name }}
head-ref: ${{ github.head_ref }}

sdk:
needs: [changes]
if: ${{ needs.changes.outputs.run == 'true' }}
strategy:
matrix:
include:
Expand Down Expand Up @@ -66,6 +74,8 @@ jobs:

build-unity-sdk:
name: Build Unity SDK
needs: [changes]
if: ${{ needs.changes.outputs.run == 'true' }}
secrets:
UNITY_LICENSE_SERVER_CONFIG: ${{ secrets.UNITY_LICENSE_SERVER_CONFIG }}
permissions:
Expand All @@ -83,6 +93,8 @@ jobs:

package-validation:
name: UPM Package validation
needs: [changes]
if: ${{ needs.changes.outputs.run == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -127,8 +139,8 @@ jobs:
# This produces the `samples/IntegrationTest` as `test-${{ matrix.unity-version }}`.
test-create:
name: Create ${{ matrix.unity-version }} Test Project
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
needs: [create-unity-matrix]
if: ${{ needs.changes.outputs.run == 'true' && !startsWith(github.ref, 'refs/heads/release/') }}
needs: [changes, create-unity-matrix]
secrets:
UNITY_LICENSE_SERVER_CONFIG: ${{ secrets.UNITY_LICENSE_SERVER_CONFIG }}
strategy:
Expand Down
Loading