| 1 | name: Go Test |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | pull_request: |
| 6 | paths-ignore: |
| 7 | - '**/*.md' |
| 8 | push: |
| 9 | branches: |
| 10 | - 'master' |
| 11 | |
| 12 | concurrency: |
| 13 | group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} |
| 14 | cancel-in-progress: true |
| 15 | |
| 16 | jobs: |
| 17 | # Unit tests with coverage collection (uploaded to Codecov) |
| 18 | unit-tests: |
| 19 | if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch' |
| 20 | runs-on: ${{ fromJSON(github.repository == 'ipfs/kubo' && '["self-hosted", "linux", "x64", "2xlarge"]' || '"ubuntu-latest"') }} |
| 21 | timeout-minutes: 15 |
| 22 | env: |
| 23 | GOTRACEBACK: single # reduce noise on test timeout panics |
| 24 | TEST_DOCKER: 0 |
| 25 | TEST_FUSE: 0 |
| 26 | TEST_VERBOSE: 1 |
| 27 | GIT_PAGER: cat |
| 28 | IPFS_CHECK_RCMGR_DEFAULTS: 1 |
| 29 | defaults: |
| 30 | run: |
| 31 | shell: bash |
| 32 | steps: |
| 33 | - name: Check out Kubo |
| 34 | uses: actions/checkout@v6 |
| 35 | - name: Set up Go |
| 36 | uses: actions/setup-go@v6 |
| 37 | with: |
| 38 | go-version-file: 'go.mod' |
| 39 | - name: Install missing tools |
| 40 | run: sudo apt update && sudo apt install -y zsh |
| 41 | - name: Run unit tests |
| 42 | run: | |
| 43 | make test_unit && |
| 44 | [[ ! $(jq -s -c 'map(select(.Action == "fail")) | .[]' test/unit/gotest.json) ]] |
| 45 | - name: Upload coverage to Codecov |
| 46 | uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1 |
| 47 | if: failure() || success() |
| 48 | with: |
| 49 | name: unittests |
| 50 | files: coverage/unit_tests.coverprofile |
| 51 | token: ${{ secrets.CODECOV_TOKEN }} |
| 52 | fail_ci_if_error: false |
| 53 | - name: Create a proper JUnit XML report |
| 54 | uses: ipdxco/gotest-json-to-junit-xml@v1 |
| 55 | with: |
| 56 | input: test/unit/gotest.json |
| 57 | output: test/unit/gotest.junit.xml |
| 58 | if: failure() || success() |
| 59 | - name: Archive the JUnit XML report |
| 60 | uses: actions/upload-artifact@v7 |
| 61 | with: |
| 62 | name: unit-tests-junit |
| 63 | path: test/unit/gotest.junit.xml |
| 64 | if: failure() || success() |
| 65 | - name: Create a HTML report |
| 66 | uses: ipdxco/junit-xml-to-html@v1 |
| 67 | with: |
| 68 | mode: no-frames |
| 69 | input: test/unit/gotest.junit.xml |
| 70 | output: test/unit/gotest.html |
| 71 | if: failure() || success() |
| 72 | - name: Archive the HTML report |
| 73 | uses: actions/upload-artifact@v7 |
| 74 | with: |
| 75 | name: unit-tests-html |
| 76 | path: test/unit/gotest.html |
| 77 | if: failure() || success() |
| 78 | - name: Create a Markdown report |
| 79 | uses: ipdxco/junit-xml-to-html@v1 |
| 80 | with: |
| 81 | mode: summary |
| 82 | input: test/unit/gotest.junit.xml |
| 83 | output: test/unit/gotest.md |
| 84 | if: failure() || success() |
| 85 | - name: Set the summary |
| 86 | run: cat test/unit/gotest.md >> $GITHUB_STEP_SUMMARY |
| 87 | if: failure() || success() |
| 88 | |
| 89 | # End-to-end integration/regression tests from test/cli |
| 90 | # (Go-based replacement for legacy test/sharness shell scripts) |
| 91 | cli-tests: |
| 92 | if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch' |
| 93 | runs-on: ${{ fromJSON(github.repository == 'ipfs/kubo' && '["self-hosted", "linux", "x64", "2xlarge"]' || '"ubuntu-latest"') }} |
| 94 | timeout-minutes: 15 |
| 95 | env: |
| 96 | GOTRACEBACK: single # reduce noise on test timeout panics |
| 97 | TEST_VERBOSE: 1 |
| 98 | GIT_PAGER: cat |
| 99 | IPFS_CHECK_RCMGR_DEFAULTS: 1 |
| 100 | defaults: |
| 101 | run: |
| 102 | shell: bash |
| 103 | steps: |
| 104 | - name: Check out Kubo |
| 105 | uses: actions/checkout@v6 |
| 106 | - name: Set up Go |
| 107 | uses: actions/setup-go@v6 |
| 108 | with: |
| 109 | go-version-file: 'go.mod' |
| 110 | - name: Install missing tools |
| 111 | run: sudo apt update && sudo apt install -y zsh |
| 112 | - name: Run CLI tests |
| 113 | env: |
| 114 | IPFS_PATH: ${{ runner.temp }}/ipfs-test |
| 115 | run: make test_cli |
| 116 | - name: Create JUnit XML report |
| 117 | uses: ipdxco/gotest-json-to-junit-xml@v1 |
| 118 | with: |
| 119 | input: test/cli/cli-tests.json |
| 120 | output: test/cli/cli-tests.junit.xml |
| 121 | if: failure() || success() |
| 122 | - name: Archive JUnit XML report |
| 123 | uses: actions/upload-artifact@v7 |
| 124 | with: |
| 125 | name: cli-tests-junit |
| 126 | path: test/cli/cli-tests.junit.xml |
| 127 | if: failure() || success() |
| 128 | - name: Create HTML report |
| 129 | uses: ipdxco/junit-xml-to-html@v1 |
| 130 | with: |
| 131 | mode: no-frames |
| 132 | input: test/cli/cli-tests.junit.xml |
| 133 | output: test/cli/cli-tests.html |
| 134 | if: failure() || success() |
| 135 | - name: Archive HTML report |
| 136 | uses: actions/upload-artifact@v7 |
| 137 | with: |
| 138 | name: cli-tests-html |
| 139 | path: test/cli/cli-tests.html |
| 140 | if: failure() || success() |
| 141 | - name: Create Markdown report |
| 142 | uses: ipdxco/junit-xml-to-html@v1 |
| 143 | with: |
| 144 | mode: summary |
| 145 | input: test/cli/cli-tests.junit.xml |
| 146 | output: test/cli/cli-tests.md |
| 147 | if: failure() || success() |
| 148 | - name: Set summary |
| 149 | run: cat test/cli/cli-tests.md >> $GITHUB_STEP_SUMMARY |
| 150 | if: failure() || success() |
| 151 | |
| 152 | # FUSE filesystem tests (require /dev/fuse and fusermount) |
| 153 | # Runs both FUSE unit tests (./fuse/...) and CLI integration tests (./test/cli/fuse/...) |
| 154 | fuse-tests: |
| 155 | if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch' |
| 156 | runs-on: ${{ fromJSON(github.repository == 'ipfs/kubo' && '["self-hosted", "linux", "x64", "2xlarge"]' || '"ubuntu-latest"') }} |
| 157 | concurrency: |
| 158 | group: fuse-tests-${{ github.repository }} |
| 159 | cancel-in-progress: false |
| 160 | # A normal run takes ~3min. 6min gives roughly 2x and lets Go's 4min |
| 161 | # test timeout fire first (printing a stack trace) on a hang, instead |
| 162 | # of GitHub silently cancelling the job. |
| 163 | timeout-minutes: 6 |
| 164 | env: |
| 165 | # Dump all goroutines on a test panic, not just the panicking one, |
| 166 | # so we can see which test is actually hung. |
| 167 | GOTRACEBACK: all |
| 168 | TEST_FUSE: 1 |
| 169 | defaults: |
| 170 | run: |
| 171 | shell: bash |
| 172 | steps: |
| 173 | - name: Check out Kubo |
| 174 | uses: actions/checkout@v6 |
| 175 | - name: Set up Go |
| 176 | uses: actions/setup-go@v6 |
| 177 | with: |
| 178 | go-version-file: 'go.mod' |
| 179 | - name: Install FUSE |
| 180 | run: | |
| 181 | if ! command -v fusermount3 &>/dev/null && ! command -v fusermount &>/dev/null; then |
| 182 | sudo apt-get update |
| 183 | sudo apt-get install -y fuse3 |
| 184 | fi |
| 185 | - name: Clean up stale FUSE mounts |
| 186 | run: | |
| 187 | # On shared self-hosted runners, leftover mounts from previous |
| 188 | # runs can exhaust the kernel FUSE mount limit (mount_max). |
| 189 | # Unit tests mount with FsName "kubo-test"; CLI tests mount |
| 190 | # under the harness temp dir (ipfs/ipns/mfs subdirectories). |
| 191 | awk '$1 == "kubo-test" || $2 ~ /\/tmp\/.*\/(ipfs|ipns|mfs)$/ { print $2 }' /proc/mounts 2>/dev/null \ |
| 192 | | while read -r mp; do |
| 193 | fusermount3 -uz "$mp" 2>/dev/null || fusermount -uz "$mp" 2>/dev/null || true |
| 194 | done |
| 195 | - name: Run FUSE tests |
| 196 | run: make test_fuse |
| 197 | - name: Clean up FUSE mounts |
| 198 | if: always() |
| 199 | run: | |
| 200 | awk '$1 == "kubo-test" || $2 ~ /\/tmp\/.*\/(ipfs|ipns|mfs)$/ { print $2 }' /proc/mounts 2>/dev/null \ |
| 201 | | while read -r mp; do |
| 202 | fusermount3 -uz "$mp" 2>/dev/null || fusermount -uz "$mp" 2>/dev/null || true |
| 203 | done |
| 204 | |
| 205 | # Example tests (kubo-as-a-library) |
| 206 | example-tests: |
| 207 | if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch' |
| 208 | runs-on: ${{ fromJSON(github.repository == 'ipfs/kubo' && '["self-hosted", "linux", "x64", "2xlarge"]' || '"ubuntu-latest"') }} |
| 209 | timeout-minutes: 5 |
| 210 | env: |
| 211 | GOTRACEBACK: single |
| 212 | defaults: |
| 213 | run: |
| 214 | shell: bash |
| 215 | steps: |
| 216 | - name: Check out Kubo |
| 217 | uses: actions/checkout@v6 |
| 218 | - name: Set up Go |
| 219 | uses: actions/setup-go@v6 |
| 220 | with: |
| 221 | go-version-file: 'go.mod' |
| 222 | - name: Run example tests |
| 223 | run: make test_examples |