Optimize CI/CD and Versioning System #3
This file contains hidden or 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: | |
| pull_request: | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| goos: [linux, windows, darwin] | |
| goarch: [amd64, arm64, 386, arm] | |
| exclude: | |
| - goos: darwin | |
| goarch: 386 | |
| - goos: darwin | |
| goarch: arm | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Install Protoc | |
| uses: arduino/setup-protoc@v3 | |
| - name: Install Protoc Gen Go | |
| run: | | |
| go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | |
| go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | |
| - name: Generate Protos | |
| run: make proto | |
| - name: Build | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| CGO_ENABLED: 0 | |
| run: | | |
| VERSION=${{ github.sha }} | |
| COMMIT=${{ github.sha }} | |
| BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
| LDFLAGS="-X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.Version=$VERSION' -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.CommitHash=$COMMIT' -X 'github.com/MINIOpenSource/CIMS-backend/internal/pkg/version.BuildTime=$BUILD_TIME' -s -w" | |
| OUTPUT_NAME=cims-backend-${{ matrix.goos }}-${{ matrix.goarch }} | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| OUTPUT_NAME+='.exe' | |
| fi | |
| go build -ldflags "$LDFLAGS" -o $OUTPUT_NAME ./cmd/cims/main.go | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: cims-backend-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: cims-backend-* | |
| retention-days: 1 | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Install Protoc | |
| uses: arduino/setup-protoc@v3 | |
| - name: Install Protoc Gen Go | |
| run: | | |
| go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | |
| go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | |
| - name: Generate Protos | |
| run: make proto | |
| - name: Run golangci-lint | |
| uses: golangci/golangci-lint-action@v6 | |
| with: | |
| version: latest | |
| args: --timeout=5m | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Install Protoc | |
| uses: arduino/setup-protoc@v3 | |
| - name: Install Protoc Gen Go | |
| run: | | |
| go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | |
| go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | |
| - name: Generate Protos | |
| run: make proto | |
| - name: Run tests | |
| run: go test -v ./... |