Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Last active February 24, 2023 10:25
Show Gist options
  • Save Ocramius/9dd570fdcc6b53768d2dc9eceeb83e59 to your computer and use it in GitHub Desktop.
Save Ocramius/9dd570fdcc6b53768d2dc9eceeb83e59 to your computer and use it in GitHub Desktop.
Script to check whether `psalm-baseline.xml` improved/worsened over time
#!/usr/bin/env bash
export TARGET_REF=${TARGET_REF:-HEAD}
git show "$TARGET_REF:psalm-baseline.xml" | xmllint --xpath 'count(//file[not(starts-with(@src, "test"))]/*/code)' -
@Ocramius
Copy link
Author

Thanks @annervisser: applied your suggestion :)

@annervisser
Copy link

@Ocramius Another update to support the new format without occurrences= attribute:

- git show "$TARGET_REF:psalm-baseline.xml" | xmllint --xpath '//file[not(starts-with(@src, "test"))]//@occurrences' - | awk -F\" '{ print $2 }' | awk '{s+=$1} END {print s}'
+ git show "$TARGET_REF:psalm-baseline.xml" | xmllint --xpath 'count(//file[not(starts-with(@src, "test"))]/*/code)' -

@Ocramius
Copy link
Author

Applied, thanks @annervisser!

@annervisser
Copy link

I've made a GitHub action which uses this to get the score for a pull request compared to its base branch. This allows you to comment it on the PR or use it on other subsequent actions.

https://github.com/annervisser/psalm-baseline-progress-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment