125 lines
3.2 KiB
YAML
125 lines
3.2 KiB
YAML
# CI/CD Pipeline for dbbackup
|
|
name: CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master, develop]
|
|
tags: ['v*']
|
|
pull_request:
|
|
branches: [main, master]
|
|
|
|
env:
|
|
GO_VERSION: '1.23'
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: golang:1.23-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Download dependencies
|
|
run: go mod download
|
|
|
|
- name: Run tests with race detection
|
|
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
|
|
|
- name: Generate coverage report
|
|
run: |
|
|
go tool cover -func=coverage.out
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: golang:1.23-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Install golangci-lint
|
|
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.62.2
|
|
|
|
- name: Run golangci-lint
|
|
run: golangci-lint run --timeout=5m ./...
|
|
|
|
build:
|
|
name: Build (${{ matrix.goos }}-${{ matrix.goarch }})
|
|
runs-on: ubuntu-latest
|
|
needs: [test, lint]
|
|
container:
|
|
image: golang:1.23-bookworm
|
|
strategy:
|
|
matrix:
|
|
goos: [linux, darwin, windows]
|
|
goarch: [amd64, arm64]
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Build binary
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
CGO_ENABLED: 0
|
|
run: |
|
|
BINARY_NAME=dbbackup
|
|
if [ "${{ matrix.goos }}" = "windows" ]; then
|
|
BINARY_NAME="${BINARY_NAME}.exe"
|
|
fi
|
|
go build -ldflags="-s -w" -o dist/${BINARY_NAME}-${{ matrix.goos }}-${{ matrix.goarch }} ./...
|
|
|
|
sbom:
|
|
name: Generate SBOM
|
|
runs-on: ubuntu-latest
|
|
needs: [test]
|
|
container:
|
|
image: golang:1.23-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Install Syft
|
|
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
|
|
|
- name: Generate SBOM
|
|
run: |
|
|
syft . -o spdx-json=sbom-spdx.json
|
|
syft . -o cyclonedx-json=sbom-cyclonedx.json
|
|
|
|
release:
|
|
name: Release
|
|
runs-on: ubuntu-latest
|
|
needs: [test, lint, build]
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
container:
|
|
image: golang:1.23-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install tools
|
|
run: |
|
|
apt-get update && apt-get install -y git
|
|
curl -sSfL https://github.com/goreleaser/goreleaser/releases/download/v2.4.8/goreleaser_Linux_x86_64.tar.gz | tar xz -C /usr/local/bin goreleaser
|
|
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
|
|
|
- name: Run goreleaser
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: goreleaser release --clean
|