|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | +--- |
| 3 | +name: Go Continuous Integration |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + secrets: |
| 8 | + gh_username: |
| 9 | + required: false |
| 10 | + gh_token: |
| 11 | + required: false |
| 12 | + inputs: |
| 13 | + go-version: |
| 14 | + description: "The version of Go to use" |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + go-private: |
| 18 | + description: "The GOPRIVATE environment variable" |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + run-benchmarks: |
| 22 | + description: "Run benchmarks" |
| 23 | + required: false |
| 24 | + default: false |
| 25 | + type: boolean |
| 26 | + run-release-test: |
| 27 | + description: "Run release dry-run using GoReleaser" |
| 28 | + required: false |
| 29 | + default: false |
| 30 | + type: boolean |
| 31 | + |
| 32 | +jobs: |
| 33 | + tests: |
| 34 | + env: |
| 35 | + GOPRIVATE: "${{ inputs.go-private }}" |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Setup Go |
| 42 | + if: inputs.go-version != '' |
| 43 | + uses: actions/setup-go@v5 |
| 44 | + with: |
| 45 | + go-version: ${{ inputs.go-version }} |
| 46 | + |
| 47 | + - name: Setup Go |
| 48 | + if: inputs.go-version == '' |
| 49 | + uses: actions/setup-go@v5 |
| 50 | + with: |
| 51 | + go-version-file: go.mod |
| 52 | + |
| 53 | + - name: Setup private repository access |
| 54 | + if: inputs.go-private != '' |
| 55 | + run: git config --global url."https://${{ secrets.gh_username }}:${{ secrets.gh_token }}@github.com".insteadOf "https://github.com" |
| 56 | + |
| 57 | + - name: Check go mod tidy |
| 58 | + run: | |
| 59 | + go mod tidy |
| 60 | + if git diff --exit-code go.mod go.sum; then |
| 61 | + echo "go.mod and go.sum are tidy." |
| 62 | + else |
| 63 | + echo "::error go.mod or go.sum are not tidy. Please run 'go mod tidy'." |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Install Go dependencies |
| 68 | + run: | |
| 69 | + go mod download |
| 70 | + go mod verify |
| 71 | +
|
| 72 | + - name: golangci-lint |
| 73 | + uses: golangci/golangci-lint-action@v6 |
| 74 | + with: |
| 75 | + version: latest |
| 76 | + |
| 77 | + # go test will compile the code, so we don't need to run go build |
| 78 | + - name: Go Compile and Test |
| 79 | + run: go test -cover -v ./... |
| 80 | + |
| 81 | + - name: Run benchmarks |
| 82 | + if: inputs.run-benchmarks |
| 83 | + run: go test -bench=./... |
| 84 | + |
| 85 | + - name: Install GoReleaser |
| 86 | + uses: goreleaser/goreleaser-action@v6 |
| 87 | + with: |
| 88 | + distribution: goreleaser |
| 89 | + version: latest |
| 90 | + install-only: true |
| 91 | + |
| 92 | + - name: Run GoReleaser healthcheck |
| 93 | + run: goreleaser healthcheck |
| 94 | + |
| 95 | + - name: Check GoReleaser config |
| 96 | + run: goreleaser check |
| 97 | + |
| 98 | + - name: Run GoReleaser dry-run |
| 99 | + if: inputs.run-release-test |
| 100 | + run: goreleaser release --snapshot --skip=publish --clean |
| 101 | + |
| 102 | + vuln-scan: |
| 103 | + runs-on: ubuntu-latest |
| 104 | + steps: |
| 105 | + - name: Checkout code |
| 106 | + uses: actions/checkout@v4 |
| 107 | + - name: Run Trivy vulnerability scanner |
| 108 | + uses: aquasecurity/trivy-action@0.30.0 |
| 109 | + with: |
| 110 | + scan-type: "fs" |
| 111 | + format: "table" |
| 112 | + exit-code: "1" |
| 113 | + ignore-unfixed: true |
| 114 | + vuln-type: "library" |
0 commit comments