Skip to content

Commit 9023900

Browse files
committed
Inline subactions
1 parent 4d25b00 commit 9023900

5 files changed

Lines changed: 78 additions & 207 deletions

File tree

.github/workflows/tests.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,23 @@ jobs:
9797
git add -A
9898
git commit -q -m head
9999
100-
- name: "Run analyze sub-action against scenario"
101-
uses: ./analyze
100+
- uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
102101
with:
103-
base-ref: HEAD~1
104-
working-directory: scenario
105-
paths: 'src/**/*.php'
106-
source-roots: 'src'
107-
show-modified: 'false'
108-
show-removed: 'true'
102+
coverage: 'none'
103+
php-version: 8.5
104+
tools: composer:v2
105+
106+
- run: composer install --no-interaction --no-progress --classmap-authoritative
107+
108+
- name: "Run analysis against scenario"
109+
working-directory: scenario
110+
env:
111+
BASE_REF: HEAD~1
112+
PATHS_GLOB: 'src/**/*.php'
113+
SOURCE_ROOTS: 'src'
114+
SHOW_MODIFIED: 'false'
115+
SHOW_REMOVED: 'true'
116+
run: bash ${{ github.workspace }}/scripts/detect.sh
109117

110118
- name: "Assert expected output"
111119
run: |

README.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ A minimal job whose only purpose is to fire `workflow_run` so the main workflow
2929

3030
```yaml
3131
name: 'API Surface Check'
32+
33+
# Minimal pull_request workflow whose only job is to fire workflow_run for the
34+
# api-surface-comment workflow (which has pull-requests:write even on fork PRs
35+
# and runs the actual analysis from trusted action code).
36+
3237
on:
3338
pull_request:
3439
paths-ignore:
@@ -123,28 +128,6 @@ jobs:
123128

124129
The PR number and base ref are resolved automatically from the `workflow_run` event payload — you don't pass them.
125130

126-
## Sub-actions
127-
128-
The main action is a thin orchestrator. The work it can do — analysis and comment posting — is also exposed as standalone sub-actions for advanced setups (custom workflows, smoke testing, or scenarios that don't fit the two-workflow `pull_request`/`workflow_run` pattern).
129-
130-
### `composer/api-surface-check/analyze`
131-
132-
Runs the full analysis: setup PHP, install action deps, optionally install project deps, snapshot HEAD and BASE, diff, and write `comment-body.txt`. Assumes the consumer has already checked out a git tree with HEAD and `base-ref` reachable.
133-
134-
Inputs are the same as the main action's analysis-related inputs (`paths`, `source-roots`, `working-directory`, `install-dependencies`, etc.) plus a required `base-ref`. Outputs `has-changes` (`true`/`false`) and `output-dir`.
135-
136-
### `composer/api-surface-check/post-comment`
137-
138-
Posts, updates, or deletes a PR comment based on the `comment-body.txt` produced by `analyze`. Run it unconditionally once the PR is resolved — when given an empty/missing body it deletes any previously-posted bot comment, which fixes stale comments after a PR is updated to revert API additions.
139-
140-
| Input | Default | Description |
141-
| ---------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------- |
142-
| `pr-number` | _required_ | PR number to post / update / delete the comment on. |
143-
| `output-dir` | `api-surface-result` | Directory containing `comment-body.txt`. An empty/missing body deletes any existing marked comment. |
144-
| `comment-marker` | `<!-- api-surface-bot -->` | HTML marker that identifies previous bot comments. |
145-
146-
Requires `GH_TOKEN` env (passed in by the consumer) with `pull-requests: write`.
147-
148131
## Resolving vendor parents
149132

150133
By default the action only resolves classes that live under `source-roots`. If your code extends classes that come from Composer dependencies (e.g. `class Foo extends \Symfony\…`), better-reflection can't follow those parents and the introduction-point check is incomplete — methods defined on a vendor parent may be wrongly flagged as new on your subclass.

action.yml

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,34 +111,70 @@ runs:
111111
bash ${{ github.action_path }}/scripts/preflight.sh
112112
echo "should-run=$(cat api-surface-preflight.txt)" >> "$GITHUB_OUTPUT"
113113
114-
- name: Run analysis
114+
- name: Setup PHP
115115
if: steps.pr.outputs.number && steps.preflight.outputs.should-run == 'true'
116-
uses: ./analyze
116+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
117117
with:
118-
base-ref: origin/${{ steps.pr.outputs.base-ref }}
119-
paths: ${{ inputs.paths }}
120-
source-roots: ${{ inputs.source-roots }}
121-
output-dir: ${{ inputs.output-dir }}
122-
working-directory: ${{ inputs.working-directory }}
123-
install-dependencies: ${{ inputs.install-dependencies }}
124-
composer-working-directory: ${{ inputs.composer-working-directory }}
125-
include-internal: ${{ inputs.include-internal }}
126-
types: ${{ inputs.types }}
127-
visibility: ${{ inputs.visibility }}
128-
show-removed: ${{ inputs.show-removed }}
129-
show-modified: ${{ inputs.show-modified }}
130-
comment-marker: ${{ inputs.comment-marker }}
131-
heading: ${{ inputs.heading }}
118+
coverage: 'none'
119+
php-version: 8.5
120+
tools: composer:v2
121+
122+
- name: Install action dependencies
123+
if: steps.pr.outputs.number && steps.preflight.outputs.should-run == 'true'
124+
shell: bash
125+
working-directory: ${{ github.action_path }}
126+
run: composer install --no-interaction --no-progress --classmap-authoritative
127+
128+
- name: Install project dependencies
129+
id: project-deps
130+
if: steps.pr.outputs.number && steps.preflight.outputs.should-run == 'true' && inputs.install-dependencies == 'true'
131+
shell: bash
132+
working-directory: ${{ inputs.composer-working-directory || inputs.working-directory }}
133+
run: |
134+
if [[ ! -f composer.json ]]; then
135+
echo "::warning::install-dependencies=true but no composer.json at $(pwd); proceeding without vendor resolution."
136+
exit 0
137+
fi
138+
# Safety: --no-scripts blocks composer.json scripts; --no-plugins blocks
139+
# installed composer-plugin code. Together they reduce composer install
140+
# to "fetch tarballs and write autoload" — no PR-controlled code runs.
141+
if ! composer install --no-scripts --no-plugins --no-dev --prefer-dist --no-interaction --no-progress --ignore-platform-reqs; then
142+
echo "::warning::composer install failed; proceeding without vendor resolution."
143+
exit 0
144+
fi
145+
if [[ -d vendor ]]; then
146+
echo "vendor-path=$(cd vendor && pwd)" >> "$GITHUB_OUTPUT"
147+
fi
148+
149+
- name: Run analysis
150+
id: detect
151+
if: steps.pr.outputs.number && steps.preflight.outputs.should-run == 'true'
152+
shell: bash
153+
working-directory: ${{ inputs.working-directory }}
154+
env:
155+
BASE_REF: origin/${{ steps.pr.outputs.base-ref }}
156+
PATHS_GLOB: ${{ inputs.paths }}
157+
SOURCE_ROOTS: ${{ inputs.source-roots }}
158+
VENDOR_PATH: ${{ steps.project-deps.outputs.vendor-path }}
159+
OUTPUT_DIR: ${{ inputs.output-dir }}
160+
INCLUDE_INTERNAL: ${{ inputs.include-internal }}
161+
TYPES: ${{ inputs.types }}
162+
VISIBILITY: ${{ inputs.visibility }}
163+
SHOW_REMOVED: ${{ inputs.show-removed }}
164+
SHOW_MODIFIED: ${{ inputs.show-modified }}
165+
COMMENT_MARKER: ${{ inputs.comment-marker }}
166+
HEADING: ${{ inputs.heading }}
167+
run: bash ${{ github.action_path }}/scripts/detect.sh
132168

133169
# Always run post-comment when we have a PR. With analysis skipped,
134170
# comment-body.txt is missing/empty and post-comment deletes any
135171
# previously-posted bot comment.
136172
- name: Post or update comment
137173
if: steps.pr.outputs.number
138-
uses: ./post-comment
139-
with:
140-
pr-number: ${{ steps.pr.outputs.number }}
141-
output-dir: ${{ inputs.output-dir }}
142-
comment-marker: ${{ inputs.comment-marker }}
174+
shell: bash
143175
env:
144176
GH_TOKEN: ${{ github.token }}
177+
OUTPUT_DIR: ${{ inputs.output-dir }}
178+
COMMENT_MARKER: ${{ inputs.comment-marker }}
179+
PR_NUMBER: ${{ steps.pr.outputs.number }}
180+
run: bash ${{ github.action_path }}/scripts/post-comment.sh

analyze/action.yml

Lines changed: 0 additions & 126 deletions
This file was deleted.

post-comment/action.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)