Aggregator sequence and postgres implementation #137
This file contains hidden or 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: Test Coverage | |
on: | |
pull_request: | |
jobs: | |
test-coverage: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v6 # v6 | |
with: | |
cache: true | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- name: Populate go envs | |
run: | | |
echo "GOBIN=$(go env GOPATH)/bin" >> $GITHUB_ENV | |
echo "GOCACHE=$(go env GOPATH)/build" >> $GITHUB_ENV | |
- name: Cache Go toolchain artifacts | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ env.GOBIN }} | |
${{ env.GOCACHE }} | |
# hashFiles paths are repo-root relative (not affected by working-directory) | |
key: chainlink-ccv-gotools-${{ runner.os }}-${{ hashFiles('tool-versions.env') }} | |
restore-keys: | | |
chainlink-ccv-gotools-${{ runner.os }}- | |
- name: Install just | |
uses: extractions/setup-just@69d82fb0233557aec017ef13706851d0694e0f1d # v2.0.0 | |
- name: Install go-tools | |
run: just install-go-tools | |
- name: Run tests | |
run: | | |
just test-coverage coverage.out | |
total=$(go tool cover -func=coverage.out | grep total | awk '{print $3}') | |
echo "coverage=$total" >> $GITHUB_ENV | |
- name: Coverage on target branch | |
if: github.event_name == 'pull_request' | |
run: | | |
cp ./tools/bin/cov_compare.sh ${{ runner.temp }} | |
git fetch origin ${{ github.base_ref }} | |
git branch -a | |
git checkout ${{ github.base_ref }} | |
# TODO: enable after available on base branch. | |
# just test-coverage coverage_file=coverage_target.out | |
go test -shuffle on -v -coverprofile=coverage_target.out ./... | |
total=$(go tool cover -func=coverage_target.out | grep total | awk '{print $3}') | |
echo "coverage_target=$total" >> $GITHUB_ENV | |
cp ${{ runner.temp }}/cov_compare.sh cov_compare.sh | |
{ | |
echo 'coverage_report<<COVERAGE_REPORT_DELIM' | |
./cov_compare.sh --no-header coverage_target.out coverage.out | |
echo 'COVERAGE_REPORT_DELIM' | |
} >> "$GITHUB_ENV" | |
- name: Remove previous coverage comments | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { owner, repo, number: issue_number } = context.issue; | |
const comments = await github.rest.issues.listComments({ | |
owner, | |
repo, | |
issue_number | |
}); | |
const coverageCommentPrefix = "Code coverage report:"; | |
for (const comment of comments.data) { | |
if (comment.body.startsWith(coverageCommentPrefix)) { | |
await github.rest.issues.deleteComment({ | |
owner, | |
repo, | |
comment_id: comment.id | |
}); | |
} | |
} | |
- name: Display coverage in PR comment | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const coverage = process.env.coverage; | |
const coverage_target = process.env.coverage_target; | |
const coverage_report = process.env.coverage_report; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Code coverage report:\n| Package | \`${{ github.base_ref }}\` | \`${{ github.head_ref }}\` |\n ${coverage_report}` | |
}); |