diff --git a/.github/workflows/check-changes.yml b/.github/workflows/check-changes.yml new file mode 100644 index 000000000..558a07c16 --- /dev/null +++ b/.github/workflows/check-changes.yml @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 504772d8c..15a033997 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,12 @@ 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: @@ -34,6 +40,8 @@ jobs: head-ref: ${{ github.head_ref }} sdk: + needs: [changes] + if: ${{ needs.changes.outputs.run == 'true' }} strategy: matrix: include: @@ -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: @@ -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 @@ -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: