|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | +name: Go CI |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + # https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputs |
| 7 | + inputs: |
| 8 | + mod_path: |
| 9 | + description: 'Module path' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + # example: http |
| 13 | + |
| 14 | + test-go-versions: |
| 15 | + description: 'List of golang versions to run tests. Format is json array of string.' |
| 16 | + required: false |
| 17 | + default: '["1.23", "1.24"]' |
| 18 | + type: string |
| 19 | + test-os: |
| 20 | + description: 'The OS to run tests. Format is json array of string.' |
| 21 | + required: false |
| 22 | + default: '["ubuntu-latest", "macos-latest", "windows-latest"]' |
| 23 | + type: string |
| 24 | + |
| 25 | + test-cover-go-versions: |
| 26 | + description: 'List of golang versions to run tests with cover. Format is json array of string.' |
| 27 | + required: false |
| 28 | + default: '["1.24"]' |
| 29 | + type: string |
| 30 | + test-cover-os: |
| 31 | + description: 'The OS to run tests with cover. Format is json array of string.' |
| 32 | + required: false |
| 33 | + default: '["ubuntu-latest"]' |
| 34 | + type: string |
| 35 | + |
| 36 | + lint-go-versions: |
| 37 | + description: 'List of golang versions to run linters. Format is json array of string.' |
| 38 | + required: false |
| 39 | + default: '["1.23"]' |
| 40 | + type: string |
| 41 | + lint-os: |
| 42 | + description: 'The OS to run linters. Format is json array of string.' |
| 43 | + required: false |
| 44 | + default: '["ubuntu-latest"]' |
| 45 | + type: string |
| 46 | + |
| 47 | + |
| 48 | + secrets: |
| 49 | + CODECOV_TOKEN: |
| 50 | + description: 'Codecov token' |
| 51 | + required: true |
| 52 | + |
| 53 | +jobs: |
| 54 | + test-cover: |
| 55 | + name: Test With Coverage |
| 56 | + strategy: |
| 57 | + fail-fast: false |
| 58 | + matrix: |
| 59 | + os: ${{ fromJson(inputs.test-cover-os) }} |
| 60 | + go-version: ${{ fromJson(inputs.test-cover-go-versions) }} |
| 61 | + runs-on: "${{ matrix.os }}" |
| 62 | + steps: |
| 63 | + # https://github.com/actions/checkout |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + |
| 66 | + # https://github.com/actions/setup-go/ |
| 67 | + - name: Set up Go |
| 68 | + uses: actions/setup-go@v5 |
| 69 | + with: |
| 70 | + go-version: "${{ matrix.go-version }}.x" |
| 71 | + check-latest: true |
| 72 | + cache: false |
| 73 | + |
| 74 | + - name: go test |
| 75 | + shell: bash |
| 76 | + working-directory: ${{ inputs.mod_path }} |
| 77 | + run: | |
| 78 | + make --version |
| 79 | + echo "" |
| 80 | + make env |
| 81 | + echo "" |
| 82 | + go test -timeout 60s -race -coverprofile=coverage.txt -covermode=atomic ./... |
| 83 | +
|
| 84 | + - name: Upload results to Codecov |
| 85 | + uses: codecov/codecov-action@v5 |
| 86 | + with: |
| 87 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 88 | + slug: ifnotnil/x |
| 89 | + files: ./${{ inputs.mod_path }}/coverage.txt |
| 90 | + codecov_yml_path: ./codecov.yml |
| 91 | + verbose: true |
| 92 | + |
| 93 | + |
| 94 | + test: |
| 95 | + name: Tests |
| 96 | + strategy: |
| 97 | + fail-fast: false |
| 98 | + matrix: |
| 99 | + os: ${{ fromJson(inputs.test-os) }} |
| 100 | + go-version: ${{ fromJson(inputs.test-go-versions) }} |
| 101 | + runs-on: "${{ matrix.os }}" |
| 102 | + steps: |
| 103 | + # https://github.com/actions/checkout |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + |
| 106 | + # https://github.com/actions/setup-go/ |
| 107 | + - name: Set up Go |
| 108 | + uses: actions/setup-go@v5 |
| 109 | + with: |
| 110 | + # go-version-file: ./http/go.mod |
| 111 | + go-version: "${{ matrix.go-version }}.x" |
| 112 | + check-latest: true |
| 113 | + cache: false |
| 114 | + # cache: true |
| 115 | + # cache-dependency-path: ./http/go.sum |
| 116 | + |
| 117 | + - name: go test |
| 118 | + shell: bash |
| 119 | + working-directory: ${{ inputs.mod_path }} |
| 120 | + run: | |
| 121 | + go test -timeout 60s ./... |
| 122 | +
|
| 123 | +
|
| 124 | + lint: |
| 125 | + name: Lint |
| 126 | + strategy: |
| 127 | + fail-fast: false |
| 128 | + matrix: |
| 129 | + os: ${{ fromJson(inputs.lint-os) }} |
| 130 | + go-version: ${{ fromJson(inputs.lint-go-versions) }} |
| 131 | + runs-on: "${{ matrix.os }}" |
| 132 | + defaults: |
| 133 | + run: |
| 134 | + working-directory: ./${{ inputs.mod_path }} |
| 135 | + steps: |
| 136 | + # https://github.com/actions/checkout |
| 137 | + - uses: actions/checkout@v4 |
| 138 | + |
| 139 | + # https://github.com/actions/setup-go/ |
| 140 | + - name: set up go |
| 141 | + uses: actions/setup-go@v5 |
| 142 | + with: |
| 143 | + # go-version-file: ${{ inputs.mod_path }}/go.mod |
| 144 | + go-version: "${{ matrix.go-version }}.x" |
| 145 | + check-latest: true |
| 146 | + cache: false |
| 147 | + # cache: true |
| 148 | + # cache-dependency-path: ./http/go.sum |
| 149 | + |
| 150 | + - id: tools |
| 151 | + uses: ./.github/actions/tools |
| 152 | + |
| 153 | + - name: env |
| 154 | + shell: bash |
| 155 | + run: | |
| 156 | + make --version |
| 157 | + echo "" |
| 158 | + make env |
| 159 | +
|
| 160 | + # todo: reconsider to remove in favor of golangci-lint run. |
| 161 | + - name: fmt |
| 162 | + shell: bash |
| 163 | + run: make ci-fmt |
| 164 | + |
| 165 | + - name: go mod |
| 166 | + shell: bash |
| 167 | + run: make ci-mod |
| 168 | + |
| 169 | + - name: vet |
| 170 | + shell: bash |
| 171 | + run: make vet |
| 172 | + |
| 173 | + - name: staticcheck |
| 174 | + shell: bash |
| 175 | + run: make staticcheck |
| 176 | + |
| 177 | + - name: golangci-lint |
| 178 | + shell: bash |
| 179 | + run: make golangci-lint |
0 commit comments