File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 bandit --recursive --aggregate file . -f json -o baseline.json || true
2727 - name : Checkout feature branch
2828 shell : bash
29+ # Fetch the pull request's head COMMIT, not its branch name. The checkout above selected
30+ # the base branch, so `origin` is the base repository -- a fork's head branch exists only
31+ # in the contributor's fork, and `git fetch origin $GITHUB_HEAD_REF` failed there with
32+ # "couldn't find remote ref" before the scan could run. GitHub serves every pull
33+ # request's head commit from the base repository (it publishes refs/pull/<n>/head), the
34+ # same mechanism actions/checkout uses, so fetching by SHA works for forked and
35+ # same-repository pull requests alike.
36+ #
37+ # By SHA rather than refs/pull/<n>/head: the ref moves if the author pushes while this
38+ # runs, whereas the SHA pins the scan to exactly the commit the event fired for.
39+ #
40+ # Deliberately NOT a second actions/checkout: its default `clean: true` runs
41+ # `git clean -ffdx`, which deletes the untracked baseline.json the previous step just
42+ # wrote, so the comparison scan would run with no baseline and nothing would flag it.
43+ env :
44+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
2945 run : |
30- git fetch origin $GITHUB_HEAD_REF
31- git checkout $GITHUB_HEAD_REF
46+ git fetch --depth=1 origin "$HEAD_SHA"
47+ git checkout --detach "$HEAD_SHA"
3248 - name : Run Scan off of baseline
3349 shell : bash
3450 run : |
You can’t perform that action at this time.
0 commit comments