From baf36760b1c41baefc1c53dc2f45ebdb4129154f Mon Sep 17 00:00:00 2001 From: "A. Renz" Date: Thu, 11 Dec 2025 15:05:19 +0100 Subject: [PATCH] ci: fix YAML syntax error (duplicate with) --- .gitea/workflows/ci.yml | 196 +++------------------------------------- 1 file changed, 12 insertions(+), 184 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index ba80a84..efedf3e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,29 +1,17 @@ # CI/CD Pipeline for dbbackup -# Triggers: push, pull_request, tags - name: CI/CD on: push: - branches: - - main - - master - - develop - tags: - - 'v*' + branches: [main, master, develop] + tags: ['v*'] pull_request: - branches: - - main - - master + branches: [main, master] env: GO_VERSION: '1.23' - GOLANGCI_LINT_VERSION: 'v1.62.2' jobs: - # ============================================================================= - # Test Job - Runs tests with race detection and coverage - # ============================================================================= test: name: Test runs-on: ubuntu-latest @@ -35,66 +23,17 @@ jobs: with: 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 run: go mod download - name: Run tests with race detection - run: | - go test -race -coverprofile=coverage.out -covermode=atomic ./... + 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 - - 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: name: Lint runs-on: ubuntu-latest @@ -106,29 +45,14 @@ jobs: with: 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 - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin ${{ env.GOLANGCI_LINT_VERSION }} + 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 --out-format=colored-line-number ./... + run: golangci-lint run --timeout=5m ./... - # ============================================================================= - # Build Job - Verify build for all platforms - # ============================================================================= build: - name: Build + name: Build (${{ matrix.goos }}-${{ matrix.goarch }}) runs-on: ubuntu-latest needs: [test, lint] container: @@ -143,16 +67,6 @@ jobs: with: 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 env: GOOS: ${{ matrix.goos }} @@ -163,21 +77,8 @@ jobs: if [ "${{ matrix.goos }}" = "windows" ]; then BINARY_NAME="${BINARY_NAME}.exe" fi - - go build -ldflags="-s -w -X main.version=${{ github.ref_name }} -X main.commit=${{ github.sha }}" \ - -o dist/${BINARY_NAME}-${{ matrix.goos }}-${{ matrix.goarch }} \ - ./... + go build -ldflags="-s -w" -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: name: Generate SBOM runs-on: ubuntu-latest @@ -191,29 +92,13 @@ jobs: fetch-depth: 1 - name: Install Syft - run: | - curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin + run: 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: | syft . -o spdx-json=sbom-spdx.json - - - name: Generate SBOM (CycloneDX) - run: | 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: name: Release runs-on: ubuntu-latest @@ -224,73 +109,16 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-depth: 1 with: fetch-depth: 0 - - name: Install goreleaser + - 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 - - - name: Install Syft for SBOM - run: | 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 env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - 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 \ - . + run: goreleaser release --clean