|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + name: Lint and Format Check |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up Go |
| 18 | + uses: actions/setup-go@v4 |
| 19 | + with: |
| 20 | + go-version: '1.25' |
| 21 | + |
| 22 | + - name: Install golangci-lint |
| 23 | + uses: golangci/golangci-lint-action@v8 |
| 24 | + with: |
| 25 | + version: v2.4.0 |
| 26 | + args: --timeout=10m |
| 27 | + skip-cache: true |
| 28 | + |
| 29 | + - name: Install goimports |
| 30 | + run: go install golang.org/x/tools/cmd/goimports@latest |
| 31 | + |
| 32 | + - name: Check formatting |
| 33 | + run: | |
| 34 | + if [ "$(gofmt -l . | wc -l)" -gt 0 ]; then |
| 35 | + echo "Code is not formatted. Please run 'make fmt' and commit changes." |
| 36 | + gofmt -l . |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Check imports |
| 41 | + run: | |
| 42 | + if [ "$(goimports -l . | wc -l)" -gt 0 ]; then |
| 43 | + echo "Imports are not properly formatted. Please run 'make fmt' and commit changes." |
| 44 | + goimports -l . |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + test: |
| 49 | + name: Test |
| 50 | + runs-on: ubuntu-latest |
| 51 | + strategy: |
| 52 | + matrix: |
| 53 | + go-version: [ '1.25' ] |
| 54 | + os: [ ubuntu-latest, macos-latest, windows-latest ] |
| 55 | + steps: |
| 56 | + - name: Checkout code |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Set up Go ${{ matrix.go-version }} |
| 60 | + uses: actions/setup-go@v4 |
| 61 | + with: |
| 62 | + go-version: ${{ matrix.go-version }} |
| 63 | + |
| 64 | + - name: Install dependencies |
| 65 | + run: go mod download |
| 66 | + |
| 67 | + - name: Verify dependencies |
| 68 | + run: go mod verify |
| 69 | + |
| 70 | + - name: Run tests |
| 71 | + run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... |
| 72 | + |
| 73 | + - name: Upload coverage to Codecov |
| 74 | + uses: codecov/codecov-action@v4 |
| 75 | + with: |
| 76 | + file: ./coverage.out |
| 77 | + flags: unittests |
| 78 | + name: codecov-umbrella |
| 79 | + fail_ci_if_error: false |
| 80 | + |
| 81 | + security: |
| 82 | + name: Security Scan |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: [lint, test] |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Set up Go |
| 89 | + uses: actions/setup-go@v4 |
| 90 | + with: |
| 91 | + go-version: '1.25' |
| 92 | + |
| 93 | + - name: Install GoSec |
| 94 | + run: | |
| 95 | + go install github.com/securego/gosec/v2/cmd/gosec@latest |
| 96 | +
|
| 97 | + - name: Run GoSec |
| 98 | + run: | |
| 99 | + gosec -fmt sarif -out results.sarif ./... |
| 100 | + |
| 101 | + - name: Upload GoSec SARIF |
| 102 | + uses: github/codeql-action/upload-sarif@v3 |
| 103 | + if: always() |
| 104 | + with: |
| 105 | + sarif_file: results.sarif |
| 106 | + |
| 107 | + - name: Run govulncheck |
| 108 | + run: | |
| 109 | + go install golang.org/x/vuln/cmd/govulncheck@latest |
| 110 | + govulncheck ./... |
| 111 | +
|
| 112 | + build: |
| 113 | + name: Build |
| 114 | + runs-on: ubuntu-latest |
| 115 | + needs: [lint, test] |
| 116 | + strategy: |
| 117 | + matrix: |
| 118 | + goos: [linux, darwin, windows] |
| 119 | + goarch: [amd64, arm64] |
| 120 | + exclude: |
| 121 | + - goos: windows |
| 122 | + goarch: arm64 |
| 123 | + steps: |
| 124 | + - name: Checkout code |
| 125 | + uses: actions/checkout@v4 |
| 126 | + |
| 127 | + - name: Set up Go |
| 128 | + uses: actions/setup-go@v4 |
| 129 | + with: |
| 130 | + go-version: '1.25' |
| 131 | + |
| 132 | + - name: Build for ${{ matrix.goos }}/${{ matrix.goarch }} |
| 133 | + env: |
| 134 | + GOOS: ${{ matrix.goos }} |
| 135 | + GOARCH: ${{ matrix.goarch }} |
| 136 | + run: | |
| 137 | + go build -v -ldflags="-s -w -X main.Version=$(cat VERSION)" -o "ssh-aliases-${{ matrix.goos }}-${{ matrix.goarch }}" |
| 138 | +
|
| 139 | + - name: Upload build artifacts |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: ssh-aliases-${{ matrix.goos }}-${{ matrix.goarch }} |
| 143 | + path: ssh-aliases-${{ matrix.goos }}-${{ matrix.goarch }} |
| 144 | + |
| 145 | + dependency-review: |
| 146 | + name: Dependency Review |
| 147 | + runs-on: ubuntu-latest |
| 148 | + if: github.event_name == 'pull_request' |
| 149 | + steps: |
| 150 | + - name: Checkout code |
| 151 | + uses: actions/checkout@v4 |
| 152 | + |
| 153 | + - name: Dependency Review |
| 154 | + uses: actions/dependency-review-action@v4 |
| 155 | + with: |
| 156 | + fail-on-severity: moderate |
0 commit comments