|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + go-version: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + |
| 10 | +jobs: |
| 11 | + preflight: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + gopath: ${{ steps.gopath.outputs.value }} |
| 15 | + go-mods-cache-key: ${{ steps.cache-keys.outputs.go-mods-cache-key }} |
| 16 | + go-bins-cache-key: ${{ steps.cache-keys.outputs.go-bins-cache-key }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + persist-credentials: false |
| 21 | + |
| 22 | + - uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 |
| 23 | + with: |
| 24 | + cache: true |
| 25 | + reshim: true |
| 26 | + tool_versions: | |
| 27 | + go ${{ inputs.go-version }} |
| 28 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Get Go path |
| 31 | + id: gopath |
| 32 | + run: echo "value=$(go env GOPATH)" >> $GITHUB_OUTPUT |
| 33 | + |
| 34 | + - name: Cache keys |
| 35 | + id: cache-keys |
| 36 | + run: | |
| 37 | + echo "go-mods-cache-key=go-mods-${{ runner.os }}-${{ hashFiles('**/go.sum') }}" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + - name: Cache Go mods |
| 40 | + id: go-mods-cache |
| 41 | + uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + lookup-only: true |
| 44 | + path: ${{ steps.gopath.outputs.value }}/pkg/mod |
| 45 | + key: ${{ steps.cache-keys.outputs.go-mods-cache-key }} |
| 46 | + |
| 47 | + - name: 📥 Download dependencies |
| 48 | + if: steps.go-mods-cache.outputs.cache-hit != 'true' |
| 49 | + run: go mod download |
| 50 | + |
| 51 | + test: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: preflight |
| 54 | + services: |
| 55 | + postgres: |
| 56 | + image: postgres:17.4 |
| 57 | + ports: |
| 58 | + - 5444:5432 |
| 59 | + options: >- |
| 60 | + --health-cmd pg_isready |
| 61 | + --health-interval 10s |
| 62 | + --health-timeout 5s |
| 63 | + --health-retries 5 |
| 64 | + env: |
| 65 | + POSTGRES_PASSWORD: password |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + persist-credentials: false |
| 70 | + - uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 |
| 71 | + with: |
| 72 | + cache: true |
| 73 | + reshim: true |
| 74 | + tool_versions: | |
| 75 | + go ${{ inputs.go-version }} |
| 76 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + - name: 💾 Cache Go mods |
| 78 | + uses: actions/cache@v4 |
| 79 | + with: |
| 80 | + path: ${{ needs.preflight.outputs.gopath }}/pkg/mod |
| 81 | + key: ${{ needs.preflight.outputs.go-mods-cache-key }} |
| 82 | + fail-on-cache-miss: true |
| 83 | + - name: Run tests units |
| 84 | + run: | |
| 85 | + mkdir -p /tmp/test-reports |
| 86 | + gotestsum --junitfile /tmp/test-reports/unit-tests.xml |
| 87 | + - uses: actions/upload-artifact@v4 |
| 88 | + name: Upload test results |
| 89 | + with: |
| 90 | + name: test-reports-${{ inputs.go-version }} |
| 91 | + path: /tmp/test-reports |
| 92 | + - name: Run Examples |
| 93 | + run: make test-examples |
| 94 | + |
| 95 | + - name: Update coverage report |
| 96 | + uses: ncruces/go-coverage-report@aa507d98fb11c2b4dffa1b731e0786f50fd8ec93 |
| 97 | + with: |
| 98 | + report: true |
| 99 | + chart: true |
| 100 | + amend: true |
| 101 | + if: | |
| 102 | + inputs.go-version == '1.25' |
| 103 | + continue-on-error: true |
| 104 | + |
| 105 | + test-race: |
| 106 | + runs-on: ubuntu-latest |
| 107 | + needs: preflight |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + with: |
| 111 | + persist-credentials: false |
| 112 | + - uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 |
| 113 | + with: |
| 114 | + cache: true |
| 115 | + reshim: true |
| 116 | + tool_versions: | |
| 117 | + go ${{ inputs.go-version }} |
| 118 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + - name: 💾 Cache Go mods |
| 120 | + uses: actions/cache@v4 |
| 121 | + with: |
| 122 | + path: ${{ needs.preflight.outputs.gopath }}/pkg/mod |
| 123 | + key: ${{ needs.preflight.outputs.go-mods-cache-key }} |
| 124 | + fail-on-cache-miss: true |
| 125 | + - name: Run tests with race detector |
| 126 | + run: make test-race |
| 127 | + |
| 128 | + lint: |
| 129 | + runs-on: ubuntu-latest |
| 130 | + needs: preflight |
| 131 | + steps: |
| 132 | + - uses: actions/checkout@v4 |
| 133 | + with: |
| 134 | + persist-credentials: false |
| 135 | + - uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 |
| 136 | + with: |
| 137 | + cache: true |
| 138 | + reshim: true |
| 139 | + tool_versions: | |
| 140 | + go ${{ inputs.go-version }} |
| 141 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + - name: 💾 Cache Go mods |
| 143 | + uses: actions/cache@v4 |
| 144 | + with: |
| 145 | + path: ${{ needs.preflight.outputs.gopath }}/pkg/mod |
| 146 | + key: ${{ needs.preflight.outputs.go-mods-cache-key }} |
| 147 | + fail-on-cache-miss: true |
| 148 | + - name: go vet |
| 149 | + run: mise vet |
| 150 | + - name: Running staticcheck |
| 151 | + run: mise static |
| 152 | + - name: Running vulncheck |
| 153 | + run: mise vuln |
| 154 | + |
| 155 | + fmt: |
| 156 | + runs-on: ubuntu-latest |
| 157 | + needs: preflight |
| 158 | + steps: |
| 159 | + - uses: actions/checkout@v4 |
| 160 | + with: |
| 161 | + persist-credentials: false |
| 162 | + - uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 |
| 163 | + with: |
| 164 | + cache: true |
| 165 | + reshim: true |
| 166 | + tool_versions: | |
| 167 | + go ${{ inputs.go-version }} |
| 168 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 169 | + - name: 💾 Cache Go mods |
| 170 | + uses: actions/cache@v4 |
| 171 | + with: |
| 172 | + path: ${{ needs.preflight.outputs.gopath }}/pkg/mod |
| 173 | + key: ${{ needs.preflight.outputs.go-mods-cache-key }} |
| 174 | + fail-on-cache-miss: true |
| 175 | + - name: Running formatting |
| 176 | + run: | |
| 177 | + mise fmt |
| 178 | + mise has-changes |
0 commit comments