|
| 1 | +# Action — detect-changes |
| 2 | + |
| 3 | +Detects which subdirectories under `apps/` (or a custom directory) have changed since the |
| 4 | +last commit, and outputs a JSON matrix for use in downstream matrix jobs. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +```yaml |
| 9 | +jobs: |
| 10 | + detect: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + changed-apps: ${{ steps.changes.outputs.changed-apps }} |
| 14 | + has-changes: ${{ steps.changes.outputs.has-changes }} |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - uses: KevinDeBenedetti/github-workflows/.github/actions/detect-changes@main |
| 21 | + id: changes |
| 22 | + with: |
| 23 | + apps-directory: apps |
| 24 | + |
| 25 | + build: |
| 26 | + needs: detect |
| 27 | + if: needs.detect.outputs.has-changes == 'true' |
| 28 | + strategy: |
| 29 | + matrix: |
| 30 | + app: ${{ fromJson(needs.detect.outputs.changed-apps) }} |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - run: echo "Building ${{ matrix.app }}" |
| 34 | +``` |
| 35 | +
|
| 36 | +## Inputs |
| 37 | +
|
| 38 | +| Input | Type | Default | Description | |
| 39 | +|---|---|---|---| |
| 40 | +| `apps-directory` | string | `apps` | Root directory containing app subdirectories | |
| 41 | +| `base-ref` | string | `''` | Base git ref to compare against (auto-detected if empty) | |
| 42 | + |
| 43 | +## Outputs |
| 44 | + |
| 45 | +| Output | Description | |
| 46 | +|---|---| |
| 47 | +| `changed-apps` | JSON array of changed app names, e.g. `["api","web"]` | |
| 48 | +| `has-changes` | `"true"` or `"false"` — whether any app changed | |
| 49 | +| `changed-api` | `"true"` or `"false"` — whether `apps/api` changed | |
| 50 | +| `changed-web` | `"true"` or `"false"` — whether `apps/web` changed | |
| 51 | +| `changed-client` | `"true"` or `"false"` — whether `apps/client` changed | |
| 52 | + |
| 53 | +## Base ref resolution |
| 54 | + |
| 55 | +1. Uses `base-ref` input if provided |
| 56 | +2. Falls back to `github.event.pull_request.base.sha` on pull requests |
| 57 | +3. Falls back to `github.event.before` on push events |
| 58 | +4. Falls back to `HEAD~1` if the before SHA is empty or all zeros (e.g. first push to branch) |
| 59 | + |
| 60 | +## Notes |
| 61 | + |
| 62 | +- Requires `fetch-depth: 0` (or at least enough history to compare against the base ref) in your |
| 63 | + checkout step. |
| 64 | +- Per-app boolean outputs (`changed-api`, `changed-web`, `changed-client`) are useful for |
| 65 | + `if:` conditions when you don't need a matrix. |
| 66 | +- App names are sanitized (lowercased, non-alphanumeric characters replaced with `_`) in the |
| 67 | + output key names. |
0 commit comments