Skip to content

Commit fdd3e11

Browse files
committed
feat: add new comment-from-artifact mode
This new `mode` means you can use a two-workflow setup to avoid needing `pull_request_target`. Basically, workflow 1 analyzes and workflow 2 posts the comment.
1 parent e2dcb9f commit fdd3e11

9 files changed

Lines changed: 1619 additions & 3138 deletions

File tree

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ jobs:
5050
| `pack-size-threshold` | Threshold (in bytes) for warning about significant increase in total pack size | No | `50000` |
5151
| `detect-replacements` | Detect modules which have community suggested alternatives | No | `true` |
5252
| `working-directory` | Working directory to scan for package lock file | No | None |
53+
| `mode` | Run mode: `comment`, `artifact`, or `comment-from-artifact` | No | `comment` |
54+
| `artifact-path` | Path to the artifact JSON file (for `comment-from-artifact` mode) | No | None |
5355

5456
## Example with custom inputs
5557

@@ -66,7 +68,8 @@ jobs:
6668

6769
See the [`recipes/`](./recipes/) directory for complete workflow examples:
6870

69-
- [`basic.yml`](./recipes/basic.yml) - Basic dependency diff on pull requests
71+
- [`basic/`](./recipes/basic/) - Basic dependency diff on pull requests
72+
- [`artifact/`](./recipes/artifact/) - Two-workflow setup using artifacts (no `pull_request_target` needed)
7073
- [`bundle-diff.yml`](./recipes/bundle-diff.yml) - Advanced workflow with package bundle size analysis
7174

7275
## Always Report Install Size
@@ -126,6 +129,32 @@ permissions:
126129
pull-requests: write # To comment on pull requests
127130
```
128131

132+
## Artifact Mode
133+
134+
By default, the action posts a comment directly to the pull request. This requires `pull-requests: write` permission in the workflow that runs the analysis, which typically means using `pull_request_target` for fork PRs.
135+
136+
If you'd prefer not to use `pull_request_target`, you can use a two-workflow setup with artifact mode:
137+
138+
1. **Analyze workflow** (`pull_request`) - runs the analysis and uploads the result as an artifact:
139+
140+
```yaml
141+
- name: Analyze Dependencies
142+
uses: e18e/action-dependency-diff@v1
143+
with:
144+
mode: artifact
145+
```
146+
147+
2. **Comment workflow** (`workflow_run`) - downloads the artifact and posts the comment:
148+
149+
```yaml
150+
- name: Post Comment
151+
uses: e18e/action-dependency-diff@v1
152+
with:
153+
mode: comment-from-artifact
154+
```
155+
156+
See the [`recipes/artifact/`](./recipes/artifact/) directory for complete workflow files.
157+
129158
## Trust levels of packages
130159

131160
The following levels are considered when evaluating package trust:

action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ inputs:
4747
working-directory:
4848
description: 'Working directory to scan for package lock file'
4949
required: false
50+
mode:
51+
description: 'Run mode. "comment" posts a PR comment directly, "artifact" writes a JSON file containing the comment body and PR number, "comment-from-artifact" reads a previously written artifact file and posts it as a PR comment.'
52+
required: false
53+
default: 'comment'
54+
artifact-path:
55+
description: 'Path to the artifact JSON file. Required when mode is "comment-from-artifact".'
56+
required: false
57+
58+
outputs:
59+
artifact-path:
60+
description: 'Path to the artifact JSON file. Set when mode is "artifact".'
5061

5162
runs:
5263
using: node24

0 commit comments

Comments
 (0)