ci: fix YAML syntax error (duplicate with)
This commit is contained in:
@@ -1,29 +1,17 @@
|
|||||||
# CI/CD Pipeline for dbbackup
|
# CI/CD Pipeline for dbbackup
|
||||||
# Triggers: push, pull_request, tags
|
|
||||||
|
|
||||||
name: CI/CD
|
name: CI/CD
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [main, master, develop]
|
||||||
- main
|
tags: ['v*']
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches: [main, master]
|
||||||
- main
|
|
||||||
- master
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GO_VERSION: '1.23'
|
GO_VERSION: '1.23'
|
||||||
GOLANGCI_LINT_VERSION: 'v1.62.2'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# =============================================================================
|
|
||||||
# Test Job - Runs tests with race detection and coverage
|
|
||||||
# =============================================================================
|
|
||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -35,66 +23,17 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Cache Go modules
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cache/go-build
|
|
||||||
/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Download dependencies
|
- name: Download dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|
||||||
- name: Run tests with race detection
|
- name: Run tests with race detection
|
||||||
run: |
|
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
||||||
go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
|
||||||
|
|
||||||
- name: Generate coverage report
|
- name: Generate coverage report
|
||||||
run: |
|
run: |
|
||||||
go tool cover -func=coverage.out
|
go tool cover -func=coverage.out
|
||||||
go tool cover -html=coverage.out -o coverage.html
|
go tool cover -html=coverage.out -o coverage.html
|
||||||
|
|
||||||
- name: Upload coverage artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: coverage-report
|
|
||||||
path: |
|
|
||||||
coverage.out
|
|
||||||
coverage.html
|
|
||||||
retention-days: 30
|
|
||||||
|
|
||||||
- name: Generate coverage badge
|
|
||||||
run: |
|
|
||||||
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
|
||||||
echo "Total coverage: ${COVERAGE}%"
|
|
||||||
|
|
||||||
# Determine badge color
|
|
||||||
if [ "$(echo "$COVERAGE >= 80" | bc)" -eq 1 ]; then
|
|
||||||
COLOR="brightgreen"
|
|
||||||
elif [ "$(echo "$COVERAGE >= 60" | bc)" -eq 1 ]; then
|
|
||||||
COLOR="green"
|
|
||||||
elif [ "$(echo "$COVERAGE >= 40" | bc)" -eq 1 ]; then
|
|
||||||
COLOR="yellow"
|
|
||||||
else
|
|
||||||
COLOR="red"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create badge JSON (can be served via shields.io endpoint)
|
|
||||||
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${COVERAGE}%\",\"color\":\"${COLOR}\"}" > coverage-badge.json
|
|
||||||
|
|
||||||
- name: Upload coverage badge
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: coverage-badge
|
|
||||||
path: coverage-badge.json
|
|
||||||
retention-days: 90
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Lint Job - Static code analysis with golangci-lint
|
|
||||||
# =============================================================================
|
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -106,29 +45,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Cache Go modules
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cache/go-build
|
|
||||||
/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Install golangci-lint
|
- name: Install golangci-lint
|
||||||
run: |
|
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.62.2
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin ${{ env.GOLANGCI_LINT_VERSION }}
|
|
||||||
|
|
||||||
- name: Run golangci-lint
|
- name: Run golangci-lint
|
||||||
run: |
|
run: golangci-lint run --timeout=5m ./...
|
||||||
golangci-lint run --timeout=5m --out-format=colored-line-number ./...
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Build Job - Verify build for all platforms
|
|
||||||
# =============================================================================
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build (${{ matrix.goos }}-${{ matrix.goarch }})
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [test, lint]
|
needs: [test, lint]
|
||||||
container:
|
container:
|
||||||
@@ -143,16 +67,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Cache Go modules
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cache/go-build
|
|
||||||
/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
env:
|
env:
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
@@ -163,21 +77,8 @@ jobs:
|
|||||||
if [ "${{ matrix.goos }}" = "windows" ]; then
|
if [ "${{ matrix.goos }}" = "windows" ]; then
|
||||||
BINARY_NAME="${BINARY_NAME}.exe"
|
BINARY_NAME="${BINARY_NAME}.exe"
|
||||||
fi
|
fi
|
||||||
|
go build -ldflags="-s -w" -o dist/${BINARY_NAME}-${{ matrix.goos }}-${{ matrix.goarch }} ./...
|
||||||
go build -ldflags="-s -w -X main.version=${{ github.ref_name }} -X main.commit=${{ github.sha }}" \
|
|
||||||
-o dist/${BINARY_NAME}-${{ matrix.goos }}-${{ matrix.goarch }} \
|
|
||||||
./...
|
|
||||||
|
|
||||||
- name: Upload build artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
||||||
path: dist/
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# SBOM Job - Generate Software Bill of Materials
|
|
||||||
# =============================================================================
|
|
||||||
sbom:
|
sbom:
|
||||||
name: Generate SBOM
|
name: Generate SBOM
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -191,29 +92,13 @@ jobs:
|
|||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Install Syft
|
- name: Install Syft
|
||||||
run: |
|
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
||||||
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
|
||||||
|
|
||||||
- name: Generate SBOM (SPDX)
|
- name: Generate SBOM
|
||||||
run: |
|
run: |
|
||||||
syft . -o spdx-json=sbom-spdx.json
|
syft . -o spdx-json=sbom-spdx.json
|
||||||
|
|
||||||
- name: Generate SBOM (CycloneDX)
|
|
||||||
run: |
|
|
||||||
syft . -o cyclonedx-json=sbom-cyclonedx.json
|
syft . -o cyclonedx-json=sbom-cyclonedx.json
|
||||||
|
|
||||||
- name: Upload SBOM artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sbom
|
|
||||||
path: |
|
|
||||||
sbom-spdx.json
|
|
||||||
sbom-cyclonedx.json
|
|
||||||
retention-days: 90
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Release Job - Create release with goreleaser (only on tags)
|
|
||||||
# =============================================================================
|
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -224,73 +109,16 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install goreleaser
|
- name: Install tools
|
||||||
run: |
|
run: |
|
||||||
apt-get update && apt-get install -y git
|
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://github.com/goreleaser/goreleaser/releases/download/v2.4.8/goreleaser_Linux_x86_64.tar.gz | tar xz -C /usr/local/bin goreleaser
|
||||||
|
|
||||||
- name: Install Syft for SBOM
|
|
||||||
run: |
|
|
||||||
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
|
||||||
|
|
||||||
- name: Download SBOM artifacts
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sbom
|
|
||||||
path: ./sbom/
|
|
||||||
|
|
||||||
- name: Run goreleaser
|
- name: Run goreleaser
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
run: |
|
run: goreleaser release --clean
|
||||||
goreleaser release --clean
|
|
||||||
|
|
||||||
- name: Upload release artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: release-artifacts
|
|
||||||
path: dist/
|
|
||||||
retention-days: 90
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Docker Job - Build and push Docker image (optional, on tags)
|
|
||||||
# =============================================================================
|
|
||||||
docker:
|
|
||||||
name: Docker Image
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [test, lint]
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
run: |
|
|
||||||
docker buildx create --use --name multiarch
|
|
||||||
|
|
||||||
- name: Login to Gitea Registry
|
|
||||||
run: |
|
|
||||||
echo "${{ secrets.GITEA_TOKEN }}" | docker login git.uuxo.net -u ${{ github.repository_owner }} --password-stdin
|
|
||||||
|
|
||||||
- name: Extract version
|
|
||||||
id: version
|
|
||||||
run: |
|
|
||||||
VERSION=${GITHUB_REF#refs/tags/}
|
|
||||||
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
||||||
echo "version_short=${VERSION#v}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
|
||||||
run: |
|
|
||||||
docker buildx build \
|
|
||||||
--platform linux/amd64,linux/arm64 \
|
|
||||||
--tag git.uuxo.net/${{ github.repository }}:${{ steps.version.outputs.version }} \
|
|
||||||
--tag git.uuxo.net/${{ github.repository }}:latest \
|
|
||||||
--push \
|
|
||||||
.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user