Skip to content

Commit

Permalink
Optimize benchmark skip Powershell script
Browse files Browse the repository at this point in the history
Merge is the first word of this message as a test. Checking for [skip benchmarks] first (yes I just typed it, that's another test) avoids the rare, but still possible, situation of a merge commit in a PR that's not one of Github's invisible ones after a force push. If the text is there, it's important, so obey it. Checking for 'Merge' afterwards ultimately gets the same result as checking beforehand.

This commit also gets rid of one unnecessary variable and hoists another out of the loop. Vanishingly minor imperfections, but they still bugged me.
  • Loading branch information
ItEndsWithTens authored Feb 22, 2024
1 parent fe36aa3 commit 13176d6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,30 @@ jobs:

- name: Check for [skip benchmarks]
run: |
$pr = "${{ github.event_name == 'pull_request' }}" -eq 'true'
# rev-list is necessary because the HEAD~X syntax doesn't actually go in
# order one commit at a time, instead traversing by parent, so merge
# commits cause big jumps that throw off one's expectations.
foreach ($sha in $(git rev-list HEAD))
{
# Powershell treats command output as a string if it's one line, but as
# an array of strings if it's multiline. That then changes the behavior
# of things like StartsWith or the -match operator. Piping through this
# commandlet concatenates arrays into one big string, avoiding that.
$msg = $(git show -s --format=%B $sha) | Out-String
$skip = $msg -match '\[skip benchmarks?\]'
# In case of a force push to a pull request, Github will add an
# invisible merge commit that doesn't contain the expected newest
# commit message. Merge commits should otherwise be rare in a PR,
# so simply checking the message for the word "Merge" handles this.
$pr = "${{ github.event_name == 'pull_request' }}" -eq 'true'
$merge = $msg.StartsWith('Merge')
if ($pr -and $merge)
if ((-not $skip) -and $pr -and $msg.StartsWith('Merge'))
{
continue
}
$skip = $msg -match '\[skip benchmarks?\]'
echo "skip_benchmarks=$skip" >> $env:GITHUB_ENV
break
}
Expand Down

0 comments on commit 13176d6

Please sign in to comment.