All checks were successful
CI/CD / Test (push) Successful in 1m15s
CI/CD / Lint (push) Successful in 1m21s
CI/CD / Build (amd64, darwin) (push) Successful in 42s
CI/CD / Build (amd64, linux) (push) Successful in 30s
CI/CD / Build (arm64, darwin) (push) Successful in 30s
CI/CD / Build (arm64, linux) (push) Successful in 31s
CI/CD / Release (push) Has been skipped
- Upload artifacts on tag pushes - Create release via Gitea API - Attach all platform binaries to release
144 lines
4.4 KiB
YAML
144 lines
4.4 KiB
YAML
# CI/CD Pipeline for dbbackup
|
|
name: CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master, develop]
|
|
tags: ['v*']
|
|
pull_request:
|
|
branches: [main, master]
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: golang:1.24-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
env:
|
|
TOKEN: ${{ github.token }}
|
|
run: |
|
|
apt-get update && apt-get install -y -qq git ca-certificates
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
git init
|
|
git remote add origin "https://${TOKEN}@git.uuxo.net/${GITHUB_REPOSITORY}.git"
|
|
git fetch --depth=1 origin "${GITHUB_SHA}"
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Download dependencies
|
|
run: go mod download
|
|
|
|
- name: Run tests
|
|
run: go test -race -coverprofile=coverage.out ./...
|
|
|
|
- name: Coverage summary
|
|
run: go tool cover -func=coverage.out | tail -1
|
|
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: golang:1.24-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
env:
|
|
TOKEN: ${{ github.token }}
|
|
run: |
|
|
apt-get update && apt-get install -y -qq git ca-certificates
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
git init
|
|
git remote add origin "https://${TOKEN}@git.uuxo.net/${GITHUB_REPOSITORY}.git"
|
|
git fetch --depth=1 origin "${GITHUB_SHA}"
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Install and run golangci-lint
|
|
run: |
|
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
|
|
golangci-lint run --timeout=5m ./...
|
|
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
needs: [test, lint]
|
|
container:
|
|
image: golang:1.24-bookworm
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- goos: linux
|
|
goarch: amd64
|
|
- goos: linux
|
|
goarch: arm64
|
|
- goos: darwin
|
|
goarch: amd64
|
|
- goos: darwin
|
|
goarch: arm64
|
|
steps:
|
|
- name: Checkout code
|
|
env:
|
|
TOKEN: ${{ github.token }}
|
|
run: |
|
|
apt-get update && apt-get install -y -qq git ca-certificates
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
git init
|
|
git remote add origin "https://${TOKEN}@git.uuxo.net/${GITHUB_REPOSITORY}.git"
|
|
git fetch --depth=1 origin "${GITHUB_SHA}"
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Build
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
CGO_ENABLED: "0"
|
|
run: |
|
|
go build -ldflags="-s -w" -o dbbackup-${GOOS}-${GOARCH} .
|
|
ls -lh dbbackup-*
|
|
|
|
- name: Upload artifact
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dbbackup-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
path: dbbackup-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
|
|
release:
|
|
name: Release
|
|
runs-on: ubuntu-latest
|
|
needs: [build]
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
steps:
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
path: artifacts
|
|
|
|
- name: Prepare release files
|
|
run: |
|
|
mkdir -p release
|
|
find artifacts -type f -name 'dbbackup-*' -exec cp {} release/ \;
|
|
cd release && ls -lh
|
|
|
|
- name: Create Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
|
|
# Create release via API
|
|
RELEASE_ID=$(curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG} - Systemd Integration & Prometheus Metrics\",\"body\":\"## Download\\n\\nSelect the binary for your platform.\",\"draft\":false,\"prerelease\":false}" \
|
|
"https://git.uuxo.net/api/v1/repos/${GITHUB_REPOSITORY}/releases" | jq -r '.id')
|
|
|
|
echo "Created release ID: $RELEASE_ID"
|
|
|
|
# Upload each binary
|
|
for file in release/dbbackup-*; do
|
|
echo "Uploading $file..."
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${file}" \
|
|
"https://git.uuxo.net/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=$(basename $file)"
|
|
done |