Add w/o grouping run in golden test #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Golden Test w/o grouping | |
# NilAway output may change due to introduction of new feature or bug fixes. Since NilAway is still | |
# at early stage of development, constantly updating / maintaining the golden test output will be | |
# a burden. Therefore, we run this as a separate CI job and post the differences as a PR comment | |
# for manual reviews. | |
on: | |
pull_request: | |
jobs: | |
golden-test: | |
name: Golden Test w/o grouping | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
name: Check out repository | |
- name: Fetch base branch (${{ github.event.pull_request.base.ref }}) locally | |
run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22.x | |
cache: false | |
- name: Golden Test | |
id: golden_test | |
# Run golden test by comparing HEAD and the base branch (the target branch of the PR). | |
# GitHub Actions terminates the job if it hits the resource limits. Here we limit the | |
# memory usage to 8GiB to avoid that. | |
run: | | |
make golden-test GOMEMLIMIT=8192MiB ARGS="-base-branch ${{ github.event.pull_request.base.ref }} -result-file ${{ runner.temp }}/golden-test-result.md -group-error-messages=false" | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const fsp = require('fs').promises; | |
const issueNumber = context.issue.number; | |
const owner = context.repo.owner; | |
const repo = context.repo.repo; | |
const rawData = await fsp.readFile(`${{ runner.temp }}/golden-test-result.md`, 'utf8'); | |
// GitHub API has a limit of 65536 bytes for a comment body, so here we shrink the | |
// diff part (anything between <details> and </details>) to 10,000 characters if it | |
// is too long. | |
const pattern = /(<details>)([\s\S]*?)(<\/details>)/; | |
const body = rawData.replace(pattern, function(match, p1, p2, p3) { | |
if (p2.length > 10000) { | |
return p1 + p2.substring(0, 5000) + '\n\n ...(truncated)...\n\n' + p2.substring(p2.length - 5000) + p3; | |
} | |
// No need to change anything if it is not too long. | |
return match; | |
}); | |
// First find the comments made by the bot. | |
const comments = await github.rest.issues.listComments({ | |
owner: owner, | |
repo: repo, | |
issue_number: issueNumber | |
}); | |
const botComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.startsWith('## Golden Test')); | |
// Update or create the PR comment. | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
owner: owner, | |
repo: repo, | |
comment_id: botComment.id, | |
body: body | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: owner, | |
repo: repo, | |
issue_number: issueNumber, | |
body: body | |
}); | |
} |