refactor: document extra methods #68
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: EinoTests | |
on: [ pull_request ] | |
jobs: | |
unit_test: | |
name: "eino unit test" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: "Set up Go" | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "1.18" | |
- name: "GoTest" | |
run: | | |
modules=`find . -name "go.mod" -exec dirname {} \;` | |
echo $modules | |
list="" | |
coverpkg="" | |
if [[ ! -f "go.work" ]];then go work init;fi | |
for module in $modules; do go work use $module; list=$module"/... "$list; coverpkg=$module"/...,"$coverpkg; done | |
go work sync | |
go test -race -coverprofile=coverage.out -gcflags="all=-l -N" -coverpkg=$coverpkg $list | |
# Download main (aka base) branch breakdown | |
- name: Download Artifact (main.breakdown) | |
id: download-main-breakdown | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
branch: main | |
workflow_conclusion: success | |
name: main.breakdown | |
if_no_artifact_found: warn | |
- name: Ensure default.breakdown exists if download fails | |
run: | | |
if [ ! -f main.breakdown ]; then | |
echo "main.breakdown not found. Creating an empty main.breakdown file." | |
touch main.breakdown | |
else | |
echo "main.breakdown found." | |
fi | |
- name: "Test Coverage" | |
uses: vladopajic/go-test-coverage@v2 | |
with: | |
config: ./.testcoverage.yml | |
# Save current coverage breakdown if current branch is main. It will be | |
# uploaded as artifact in step below. | |
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }} | |
# If this is not main branch we want to show report including | |
# file coverage difference from main branch. | |
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact && 'main.breakdown' || 'main.breakdown' }} | |
- name: Upload Artifact (main.breakdown) | |
uses: actions/upload-artifact@v4 | |
if: github.ref_name == 'main' | |
with: | |
name: main.breakdown | |
path: main.breakdown # as specified via `breakdown-file-name` | |
if-no-files-found: error | |
- name: find if coverage report is already present | |
if: ${{ github.event.pull_request.number != null }} | |
uses: peter-evans/find-comment@v3 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: 'go-test-coverage report:' | |
- name: post coverage report | |
if: ${{ github.event.pull_request.number != null }} | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-id: ${{ steps.fc.outputs.comment-id || '' }} | |
edit-mode: replace | |
body: | | |
go-test-coverage report: | |
``` | |
${{ steps.coverage.outputs.report && fromJSON(steps.coverage.outputs.report) || 'No coverage report available' }} ``` | |
- name: "finally check coverage" | |
if: steps.coverage.outcome == 'failure' | |
shell: bash | |
run: echo "coverage check failed" && exit 1 | |
unit-benchmark-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: stable | |
- name: Unit Test | |
run: go test -race -covermode=atomic -coverprofile=coverage.out ./... | |
- name: Benchmark | |
run: go test -bench=. -benchmem -run=none ./... | |
compatibility-test: | |
strategy: | |
matrix: | |
go: [ "1.18", "1.19", "1.20", "1.21", "1.22" ] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go }} | |
cache: true # don't use cache for self-hosted runners | |
- name: Unit Test | |
run: go test -race -covermode=atomic ./... |