# File: .drone.yml (Phiên bản cải thiện) kind: pipeline type: docker # Giữ nguyên type bạn đã chỉ định name: default volumes: - name: go-modules # Cache thư viện Go temp: {} # (Optional) Thêm volume cache cho trivy nếu cần và runner hỗ trợ # - name: trivy-cache # path: /root/.cache/trivy # temp: {} steps: # ===== Các bước kiểm tra có thể chạy song song ===== - name: lint image: golangci/golangci-lint:latest commands: - golangci-lint run depends_on: [] # Chạy song song, không phụ thuộc bước nào khác when: event: [push, pull_request, tag] - name: security-scan # Đã cập nhật lệnh trivy image: aquasec/trivy:latest # volumes: # (Optional) Nếu dùng cache trivy # - name: trivy-cache # path: /root/.cache/trivy commands: # Cập nhật: Thêm --exit-code, --severity, --ignore-unfixed để làm Security Gate - trivy fs --exit-code 1 --severity HIGH,CRITICAL --ignore-unfixed --security-checks vuln . depends_on: [] # Chạy song song, không phụ thuộc bước nào khác when: event: [push, pull_request, tag] - name: test image: golang:1.23 # Thống nhất phiên bản Go volumes: - name: go-modules path: /go/pkg/mod commands: - go test -v -coverprofile=coverage.out ./... - go tool cover -func=coverage.out depends_on: [] # Chạy song song, không phụ thuộc bước nào khác when: event: [push, pull_request, tag] # ===== Kết thúc các bước chạy song song ===== # ===== Bước Build - Chạy SAU KHI các kiểm tra thành công ===== - name: build image: golang:1.23 # Thống nhất phiên bản Go volumes: - name: go-modules path: /go/pkg/mod commands: - go build -o bin/server ./cmd/server # Cập nhật: Thêm depends_on để đảm bảo các bước kiểm tra hoàn thành trước depends_on: - lint - security-scan - test when: event: [push, pull_request, tag] # ===== Bước Notify - Chạy cuối cùng ===== - name: notify image: appleboy/drone-telegram depends_on: [build] # Chỉ chạy sau khi bước build hoàn tất settings: # Giữ nguyên cấu hình secret đã sửa đúng token: from_secret: TELEGRAM_TOKEN to: from_secret: TELEGRAM_CHAT_ID message: | *Build Status*: `{{build.status}}` *Project*: {{repo.name}} *Branch*: {{build.branch}} *Commit*: `{{truncate build.commit 8}}` *Author*: {{build.author}} *Link*: {{build.link}} # depends_on: [ build ] # Thường không cần thiết vì when status sẽ xử lý when: status: [success, failure] # Chạy khi pipeline thành công hoặc thất bại event: [push, pull_request, tag]