Skip to content

Upload code scanning results to correct ref when releasing #3006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}

- name: "Get SHA hash of checked out ref"
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo CHECKED_OUT_SHA=$(git rev-parse HEAD) >> $GITHUB_ENV

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -58,12 +63,21 @@ jobs:

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi --error-format=sarif > phpstan.sarif
continue-on-error: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an error, the file won't be generated and subsequent steps will crash, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends. IIRC, if PHPStan detects errors it will exit with a non-zero exit code but still write the file. Default behaviour in GHA would be to stop the job, but we want to at least continue to the next step to upload a SARIF file if it exists. If PHPStan crashed and didn't produce a file, I'm fine with the upload-sarif step failing as well.


- name: "Upload SARIF report"
if: always()
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: "github/codeql-action/upload-sarif@v3"
with:
sarif_file: phpstan.sarif

- name: "Upload SARIF report"
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: "github/codeql-action/upload-sarif@v3"
with:
sarif_file: phpstan.sarif
ref: ${{ inputs.ref }}
sha: ${{ env.CHECKED_OUT_SHA }}

- name: Save cache PHPStan results
id: phpstan-cache-save
Expand Down