Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7770abab6f | |||
| f6a20f035b |
@@ -1,4 +1,6 @@
|
|||||||
# CI/CD Pipeline for dbbackup
|
# CI/CD Pipeline for dbbackup
|
||||||
|
# Main repo: Gitea (git.uuxo.net)
|
||||||
|
# Mirror: GitHub (github.com/PlusOne/dbbackup)
|
||||||
name: CI/CD
|
name: CI/CD
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -57,67 +59,51 @@ jobs:
|
|||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
|
||||||
golangci-lint run --timeout=5m ./...
|
golangci-lint run --timeout=5m ./...
|
||||||
|
|
||||||
build:
|
build-and-release:
|
||||||
name: Build
|
name: Build & Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [test, lint]
|
needs: [test, lint]
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
container:
|
container:
|
||||||
image: golang:1.24-bookworm
|
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:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ github.token }}
|
TOKEN: ${{ github.token }}
|
||||||
run: |
|
run: |
|
||||||
apt-get update && apt-get install -y -qq git ca-certificates
|
apt-get update && apt-get install -y -qq git ca-certificates curl jq
|
||||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||||
git init
|
git init
|
||||||
git remote add origin "https://${TOKEN}@git.uuxo.net/${GITHUB_REPOSITORY}.git"
|
git remote add origin "https://${TOKEN}@git.uuxo.net/${GITHUB_REPOSITORY}.git"
|
||||||
git fetch --depth=1 origin "${GITHUB_SHA}"
|
git fetch --depth=1 origin "${GITHUB_SHA}"
|
||||||
git checkout FETCH_HEAD
|
git checkout FETCH_HEAD
|
||||||
|
|
||||||
- name: Build
|
- name: Build all platforms
|
||||||
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: |
|
run: |
|
||||||
mkdir -p release
|
mkdir -p release
|
||||||
find artifacts -type f -name 'dbbackup-*' -exec cp {} release/ \;
|
|
||||||
cd release && ls -lh
|
# Linux amd64
|
||||||
|
echo "Building linux/amd64..."
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o release/dbbackup-linux-amd64 .
|
||||||
|
|
||||||
|
# Linux arm64
|
||||||
|
echo "Building linux/arm64..."
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o release/dbbackup-linux-arm64 .
|
||||||
|
|
||||||
|
# Darwin amd64
|
||||||
|
echo "Building darwin/amd64..."
|
||||||
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o release/dbbackup-darwin-amd64 .
|
||||||
|
|
||||||
|
# Darwin arm64
|
||||||
|
echo "Building darwin/arm64..."
|
||||||
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o release/dbbackup-darwin-arm64 .
|
||||||
|
|
||||||
|
# FreeBSD amd64
|
||||||
|
echo "Building freebsd/amd64..."
|
||||||
|
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w" -o release/dbbackup-freebsd-amd64 .
|
||||||
|
|
||||||
|
echo "All builds complete:"
|
||||||
|
ls -lh release/
|
||||||
|
|
||||||
- name: Create Gitea Release
|
- name: Create Gitea Release
|
||||||
env:
|
env:
|
||||||
@@ -125,20 +111,69 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
TAG=${GITHUB_REF#refs/tags/}
|
TAG=${GITHUB_REF#refs/tags/}
|
||||||
|
|
||||||
|
echo "Creating Gitea release for ${TAG}..."
|
||||||
|
|
||||||
|
# Create JSON payload (avoid shell escaping issues)
|
||||||
|
cat > /tmp/release.json << EOF
|
||||||
|
{
|
||||||
|
"tag_name": "${TAG}",
|
||||||
|
"name": "${TAG}",
|
||||||
|
"body": "## Download\n\nSelect the binary for your platform.\n\n### Platforms\n- Linux (amd64, arm64)\n- macOS (Intel, Apple Silicon)\n- FreeBSD (amd64)",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
# Create release via API
|
# Create release via API
|
||||||
RELEASE_ID=$(curl -s -X POST \
|
RESPONSE=$(curl -s -X POST \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-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}" \
|
-d @/tmp/release.json \
|
||||||
"https://git.uuxo.net/api/v1/repos/${GITHUB_REPOSITORY}/releases" | jq -r '.id')
|
"https://git.uuxo.net/api/v1/repos/${GITHUB_REPOSITORY}/releases")
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
||||||
|
|
||||||
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Failed to create release. Response:"
|
||||||
|
echo "$RESPONSE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Created release ID: $RELEASE_ID"
|
echo "Created release ID: $RELEASE_ID"
|
||||||
|
|
||||||
# Upload each binary
|
# Upload each binary
|
||||||
for file in release/dbbackup-*; do
|
for file in release/dbbackup-*; do
|
||||||
echo "Uploading $file..."
|
FILENAME=$(basename "$file")
|
||||||
|
echo "Uploading $FILENAME..."
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
-F "attachment=@${file}" \
|
-F "attachment=@${file}" \
|
||||||
"https://git.uuxo.net/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=$(basename $file)"
|
"https://git.uuxo.net/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "Gitea release complete!"
|
||||||
|
|
||||||
|
# Mirror to GitHub (optional - runs if GITHUB_MIRROR_TOKEN secret is set)
|
||||||
|
mirror-to-github:
|
||||||
|
name: Mirror to GitHub
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build-and-release]
|
||||||
|
if: startsWith(github.ref, 'refs/tags/') && vars.GITHUB_MIRROR_TOKEN != ''
|
||||||
|
continue-on-error: true
|
||||||
|
steps:
|
||||||
|
- name: Mirror to GitHub
|
||||||
|
env:
|
||||||
|
GITHUB_MIRROR_TOKEN: ${{ vars.GITHUB_MIRROR_TOKEN }}
|
||||||
|
run: |
|
||||||
|
TAG=${GITHUB_REF#refs/tags/}
|
||||||
|
|
||||||
|
echo "Mirroring ${TAG} to GitHub..."
|
||||||
|
|
||||||
|
# Clone from Gitea
|
||||||
|
git clone --bare "https://git.uuxo.net/${GITHUB_REPOSITORY}.git" repo.git
|
||||||
|
cd repo.git
|
||||||
|
|
||||||
|
# Push to GitHub
|
||||||
|
git push --mirror "https://${GITHUB_MIRROR_TOKEN}@github.com/PlusOne/dbbackup.git" || echo "Mirror push failed (non-critical)"
|
||||||
|
|
||||||
|
echo "GitHub mirror complete!"
|
||||||
Reference in New Issue
Block a user