Skip to content

Continuous Integration #1138

Continuous Integration

Continuous Integration #1138

Workflow file for this run

name: Continuous Integration
on:
push:
branches:
- main
pull_request:
merge_group:
types:
- checks_requested
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
permissions:
pull-requests: read
checks: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
only-new-issues: true
- name: Tidy go.mod
run: go mod tidy
- name: Check Tidy go.mod
run: |
git diff --exit-code || { echo "##[error] go.mod is not tidy, run 'go mod tidy' and commit the changes."; exit 1; }
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Build
run: make build
- name: Test
run: make test/cover
- name: Upload coverage to Codecov
# Commit SHA corresponds to version v4.4.1
# See: https://github.com/codecov/codecov-action/releases/tag/v4.4.1
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c
# Don't run coverage on merge queue CI to avoid duplicating reports to codecov.
# Otherwise base coverage from main branch does not render properly.
#
# See: https://github.com/matplotlib/napari-matplotlib/issues/155#issuecomment-1589377119
if: github.event_name != 'merge_group'
with:
files: coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
fuzz:
name: Fuzz
runs-on: ubuntu-latest
needs:
- test # Do not bother running the fuzz tests if tests fail
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Fuzz
env:
FUZZTIME: 30s
run: make fuzz
- name: Upload fuzz failure seed corpus as run artifact
if: failure()
uses: actions/upload-artifact@v4
id: testdata-upload
with:
name: testdata
path: '**/testdata/fuzz'
- name: Output message
if: failure()
shell: bash
run: |
echo -e 'Fuzz test failed on commit https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}. To troubleshoot locally, use the GitHub CLI to download the seed corpus by running:\n $ gh run download ${ github.run_id } -n testdata\nAlternatively, download from:\n ${{ steps.testdata-upload.outputs.artifact-url }}'
- name: Post PR comment
uses: actions/github-script@v7
if: failure() && github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Fuzz test failed on commit ${{ github.event.pull_request.head.sha }}. To troubleshoot locally, download the seed corpus using [GitHub CLI](https://cli.github.com) by running:\n```shell\ngh run download ${{ github.run_id }} -n testdata\n```\nAleternatively, download directly from [here](${{ steps.testdata-upload.outputs.artifact-url }}).'
})
test-race:
name: Test With Race Detector
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Test with race detection
env:
# Run tests with race detector, excluding fuzz tests.
# Fuzz tests are excluded because they will otherwise
# take too long to complete.
GOTEST_ARGS: -race -run='^[^Fuzz]' -timeout=20m
run: make test
generate:
name: Generate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Generate
run: make generate
- name: Check for changes
run: |
git diff --exit-code || { echo "##[error] Generated code differs from repository content, run 'make generate' and commit the changes."; exit 1; }