feat: add lint, build and test job in ci #9
Workflow file for this run
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: ci | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
paths-ignore: | |
- 'doc/**' | |
- 'README.md' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
GO_VERSION: 1.17 | |
GOPLS_VERSION: 0.12 # last version to support go1.17 (https://github.com/golang/tools/releases/tag/gopls%2Fv0.12.0) | |
jobs: | |
prep-matrix: | |
name: prep-matrix | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Set matrix | |
id: set-matrix | |
run: echo "matrix=$(ls | grep 'operator-v*' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
lint: | |
name: lint | |
needs: prep-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
folder-path: ${{ fromJson(needs.prep-matrix.outputs.matrix) }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Install go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Run go fmt | |
run: go fmt ./... | |
working-directory: ${{ matrix.folder-path }} | |
- name: Run go vet | |
run: go vet ./... | |
working-directory: ${{ matrix.folder-path }} | |
- name: Install golangci-lint | |
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin | |
- name: Run golangci-lint | |
run: golangci-lint run --fix --timeout 5m | |
working-directory: ${{ matrix.folder-path }} | |
- name: Install shadow | |
run: go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@${{ env.GOPLS_VERSION }} | |
- name: Run shadow | |
run: shadow ./... | |
working-directory: ${{ matrix.folder-path }} | |
build: | |
name: build | |
needs: lint | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
folder-path: ${{ fromJson(needs.prep-matrix.outputs.matrix) }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Install go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Build binary | |
run: make build | |
working-directory: ${{ matrix.folder-path }} | |
test: | |
name: test | |
needs: lint | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
folder-path: ${{ fromJson(needs.prep-matrix.outputs.matrix) }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Install go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Run tests | |
run: make test | |
working-directory: ${{ matrix.folder-path }} |