Skip to content

Commit e899af8

Browse files
committed
Document the push/pull_request overlap in the example workflow
Move the Skipped events section below the scan-type paragraphs it had split. State the required-check risk without claiming which run GitHub picks. Explain that push on every branch also runs the job on a pull request's head commit as a full scan that exits 0, and give two ways to keep that run from satisfying a required check.
1 parent 8aa89ea commit e899af8

3 files changed

Lines changed: 52 additions & 16 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
scanning, so a reopened pull request could pass a required check on a commit an
1010
earlier run failed.
1111
- Skipped GitHub events and actions, and skipped GitLab pipeline sources, log a
12-
warning that no scan ran. `pull_request_target` gets its own message. Exit codes
13-
are unchanged.
12+
warning that no scan ran. `pull_request_target` gets its own message, and a
13+
missing event name or action says it could not be determined. Exit codes are
14+
unchanged.
15+
- `docs/ci-cd.md` explains that the example GitHub workflow's `push` trigger also
16+
runs the job on a pull request's head commit as a full scan that exits `0`, and
17+
how to keep that run from satisfying a required check.
1418

1519
## 2.13.0
1620

‎docs/ci-cd.md‎

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,27 +513,55 @@ different depending on which output format was enabled, those runs behave as if
513513
`--disable-blocking` was supplied and report through the Dashboard instead. This
514514
matches how the CLI already treats a run with no supported manifest files.
515515

516+
The event type is authoritative once `--scm` is set: `--enable-diff` and
517+
`--ignore-commit-files` do not turn a branch pipeline into a comparison. To diff
518+
a branch build, drop `--scm` and use `--enable-diff` with `--integration`, which
519+
runs the comparison without the PR comment adapter.
520+
521+
`--generate-license` and `--legal-format fossa` work on both paths; a full scan
522+
fetches the package list for them.
523+
516524
### Skipped events
517525

518526
With `--scm github`, `pull_request` runs scan on the `opened`, `synchronize`,
519527
`reopened` and `ready_for_review` actions. Other actions (`closed`, `labeled`,
520528
`edited`, ...) and events the CLI does not handle (`pull_request_target`,
521529
`merge_group`, `schedule`, ...) are skipped: no scan runs, the CLI logs a warning
522-
and exits `0`. With `--scm gitlab`, pipeline sources other than `web`,
523-
`merge_request_event`, `push`, `api`, `pipeline` and the comment flow are skipped
524-
the same way.
530+
and exits `0`. `issue_comment` runs the ignore-command flow, not a scan. With
531+
`--scm gitlab`, pipeline sources other than `web`, `merge_request_event`, `push`,
532+
`api`, `pipeline` and the comment flow are skipped the same way.
525533

526-
A required check takes the latest run on the head commit, so a skipped run that
527-
passes can replace an earlier failure. Subscribe the Socket job only to events and
534+
GitHub doesn't document which run a required check uses when a job with the same
535+
name runs more than once on a commit, so a skipped run that passes can satisfy the
536+
check in place of an earlier failure. Subscribe the Socket job only to events and
528537
actions the CLI scans.
529538

530-
The event type is authoritative once `--scm` is set: `--enable-diff` and
531-
`--ignore-commit-files` do not turn a branch pipeline into a comparison. To diff
532-
a branch build, drop `--scm` and use `--enable-diff` with `--integration`, which
533-
runs the comparison without the PR comment adapter.
534-
535-
`--generate-license` and `--legal-format fossa` work on both paths; a full scan
536-
fetches the package list for them.
539+
- `merge_group`: if the required check also runs on merge queue events, the job
540+
passes there without scanning. The `pull_request` run is the gate.
541+
- `pull_request_target` is skipped because it runs against the base branch, so it
542+
can't stand in for `pull_request` on fork pull requests. Fork pull requests on
543+
`pull_request` get no repository secrets, so the CLI has no API token and exits
544+
`3` (or the `--exit-code-on-api-error` value). Decide how fork pull requests get
545+
a token before making the check required.
546+
547+
### Push and pull request runs on the same commit
548+
549+
The [example workflow](../workflows/github-actions.yml) runs one `socket-security`
550+
job on `push` to every branch and on `pull_request`. A new commit on a pull
551+
request's branch triggers both events on the same head commit. The `pull_request`
552+
run compares against the baseline and can fail. The `push` run is a full scan,
553+
which never blocks and exits `0`. Both runs report a check with the same name, so
554+
a required check can resolve against the passing `push` run.
555+
556+
If the Socket job is a required check, do one of these:
557+
558+
- Restrict `push` to the default branch (`branches: [main]`). Default-branch scans
559+
still keep the baseline current; feature branches are scanned only through their
560+
pull requests.
561+
- Run the pull request scan in its own job (for example `socket-pr` with
562+
`if: github.event_name == 'pull_request'`, and
563+
`if: github.event_name != 'pull_request'` on the existing job), and require that
564+
job's check.
537565

538566
## Pull request and Dashboard association
539567

‎workflows/github-actions.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ run-name: Socket Security Github Action
77

88
on:
99
push:
10+
# On a branch with an open pull request, this also runs the job on the PR head
11+
# commit as a full scan, which exits 0. If this job is a required check, restrict
12+
# push to the default branch or give the pull_request run its own job name. See
13+
# "Push and pull request runs on the same commit" in docs/ci-cd.md.
1014
branches: ['**'] # Run on all branches, all commits
1115
pull_request:
1216
# Every listed action runs a scan. Don't add actions the CLI skips (closed,
13-
# labeled, edited, ...): a skipped run exits 0, and on a required check it can
14-
# replace an earlier failure on the same commit.
17+
# labeled, edited, ...): a skipped run exits 0 and can satisfy a required check
18+
# on a commit an earlier run failed.
1519
types: [opened, synchronize, reopened]
1620
issue_comment:
1721
types: [created]

0 commit comments

Comments
 (0)