CI/CD #161
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD | |
| on: | |
| push: | |
| branches: [main] | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: [main] | |
| # 取消相同分支的旧运行 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.25.7" | |
| cache: true | |
| - name: Build | |
| run: go build ./... | |
| - name: Test with coverage | |
| run: go test -timeout 30s -short -coverprofile=coverage.out -covermode=atomic ./... 2>&1 | grep -v "badger" || true | |
| - name: Upload coverage | |
| if: always() | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage.out | |
| fail_ci_if_error: false | |
| test-integration: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.25.7" | |
| cache: true | |
| - name: Run integration tests | |
| run: go test -timeout 60s ./cmd/integration/... | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: [test, test-integration] | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.25.7" | |
| cache: true | |
| - name: Create version variable | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
| - name: Build binaries | |
| run: | | |
| PLATFORMS=("linux-amd64 linux amd64" "linux-arm64 linux arm64" "darwin-amd64 darwin amd64" "darwin-arm64 darwin arm64" "windows-amd64 windows amd64") | |
| for platform in "${PLATFORMS[@]}"; do | |
| IFS=' ' read -r osarch os arch <<< "$platform" | |
| ext="" | |
| if [ "$os" = "windows" ]; then ext=".exe"; fi | |
| echo "Building for $os-$arch..." | |
| # Main binary (includes sentinel functionality) | |
| GIT_COMMIT_ID=${GITHUB_SHA:0:7} | |
| BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ') | |
| CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o boltDB-${VERSION}-${osarch}${ext} -ldflags "-s -w -X github.com/lbp0200/BoltDB/internal/server.Version=${VERSION} -X github.com/lbp0200/BoltDB/internal/server.GitCommitID=${GIT_COMMIT_ID} -X github.com/lbp0200/BoltDB/internal/server.BuildTime=${BUILD_TIME}" ./cmd/boltDB/ | |
| done | |
| - name: Calculate checksums | |
| run: | | |
| shasum -a 256 boltDB-${VERSION}-* > boltDB-${VERSION}-checksums.txt | |
| cat boltDB-${VERSION}-checksums.txt | |
| - name: Install packaging tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y dpkg-dev | |
| - name: Build .deb package | |
| run: | | |
| VERSION_NUM=${VERSION#v} | |
| # Create temporary directory for package | |
| mkdir -p pkg/boltDB/usr/bin | |
| mkdir -p pkg/boltDB/var/lib/boltdb | |
| # Copy binary | |
| cp boltDB-${VERSION}-linux-amd64 pkg/boltDB/usr/bin/boltdb | |
| chmod 755 pkg/boltDB/usr/bin/boltdb | |
| # Create control file for deb | |
| mkdir -p pkg/boltDB/DEBIAN | |
| printf 'Package: boltdb\nVersion: %s\nSection: database\nPriority: optional\nArchitecture: amd64\nDepends: libc6\nMaintainer: BoltDB Team <lbp@boltdb.dev>\nDescription: Redis-compatible key-value database with 100TB storage\n A high-performance, disk-persistent key-value database.\n' "$VERSION_NUM" > pkg/boltDB/DEBIAN/control | |
| # Create postinst script for deb | |
| printf '#!/bin/sh\ncase "$1" in\n configure)\n mkdir -p /var/lib/boltdb\n ;;\nesac\nexit 0\n' > pkg/boltDB/DEBIAN/postinst | |
| chmod 755 pkg/boltDB/DEBIAN/postinst | |
| # Build .deb package | |
| dpkg-deb --build pkg/boltDB boltDB_${VERSION_NUM}_amd64.deb | |
| # Rename for release upload (from boltDB_1.0.15_amd64.deb to boltDB-v1.0.15-amd64.deb) | |
| mv boltDB_${VERSION_NUM}_amd64.deb boltDB-${VERSION}-amd64.deb | |
| - name: Upload Release Assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| boltDB-${{ env.VERSION }}-linux-amd64 | |
| boltDB-${{ env.VERSION }}-linux-arm64 | |
| boltDB-${{ env.VERSION }}-darwin-amd64 | |
| boltDB-${{ env.VERSION }}-darwin-arm64 | |
| boltDB-${{ env.VERSION }}-windows-amd64.exe | |
| boltDB-${{ env.VERSION }}-checksums.txt | |
| boltDB-${{ env.VERSION }}-amd64.deb | |
| generate_release_notes: true | |
| name: Release ${{ env.VERSION }} | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update Homebrew Formula | |
| run: | | |
| VERSION=${{ env.VERSION }} | |
| VERSION_NUM=${VERSION#v} | |
| echo "Updating Homebrew formula to version $VERSION_NUM" | |
| # Download files and calculate SHA256 (use VERSION for download URL) | |
| curl -sL "https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-${VERSION}-darwin-arm64" -o /tmp/darwin-arm64 | |
| curl -sL "https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-${VERSION}-darwin-amd64" -o /tmp/darwin-amd64 | |
| curl -sL "https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-${VERSION}-linux-arm64" -o /tmp/linux-arm64 | |
| curl -sL "https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-${VERSION}-linux-amd64" -o /tmp/linux-amd64 | |
| DARWIN_ARM64=$(shasum -a 256 /tmp/darwin-arm64 | awk '{print $1}') | |
| DARWIN_AMD64=$(shasum -a 256 /tmp/darwin-amd64 | awk '{print $1}') | |
| LINUX_ARM64=$(shasum -a 256 /tmp/linux-arm64 | awk '{print $1}') | |
| LINUX_AMD64=$(shasum -a 256 /tmp/linux-amd64 | awk '{print $1}') | |
| # Clone homebrew formula repo using token | |
| git clone https://x-access-token:${{ secrets.HOMEBREW_TOKEN }}@github.com/lbp0200/homebrew-boltdb.git /tmp/homebrew-boltdb | |
| # Write formula file | |
| cd /tmp/homebrew-boltdb | |
| echo 'class Boltdb < Formula' > Formula/boltdb.rb | |
| echo ' desc "Redis-compatible key-value database with 100TB storage"' >> Formula/boltdb.rb | |
| echo ' homepage "https://github.com/lbp0200/BoltDB"' >> Formula/boltdb.rb | |
| echo " version \"$VERSION_NUM\"" >> Formula/boltdb.rb | |
| echo ' license "MIT"' >> Formula/boltdb.rb | |
| echo '' >> Formula/boltdb.rb | |
| echo ' on_macos do' >> Formula/boltdb.rb | |
| echo ' if Hardware::CPU.arm?' >> Formula/boltdb.rb | |
| echo " url \"https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-$VERSION-darwin-arm64\"" >> Formula/boltdb.rb | |
| echo " sha256 \"$DARWIN_ARM64\"" >> Formula/boltdb.rb | |
| echo ' else' >> Formula/boltdb.rb | |
| echo " url \"https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-$VERSION-darwin-amd64\"" >> Formula/boltdb.rb | |
| echo " sha256 \"$DARWIN_AMD64\"" >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo '' >> Formula/boltdb.rb | |
| echo ' on_linux do' >> Formula/boltdb.rb | |
| echo ' if Hardware::CPU.arm?' >> Formula/boltdb.rb | |
| echo " url \"https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-$VERSION-linux-arm64\"" >> Formula/boltdb.rb | |
| echo " sha256 \"$LINUX_ARM64\"" >> Formula/boltdb.rb | |
| echo ' else' >> Formula/boltdb.rb | |
| echo " url \"https://github.com/lbp0200/BoltDB/releases/download/$VERSION/boltDB-$VERSION-linux-amd64\"" >> Formula/boltdb.rb | |
| echo " sha256 \"$LINUX_AMD64\"" >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo '' >> Formula/boltdb.rb | |
| echo ' def install' >> Formula/boltdb.rb | |
| echo ' arch = Hardware::CPU.arm? ? "arm64" : "amd64"' >> Formula/boltdb.rb | |
| echo ' os = OS.mac? ? "darwin" : "linux"' >> Formula/boltdb.rb | |
| echo " bin.install \"boltDB-$VERSION_NUM-${os}-${arch}\" => \"boltdb\"" >> Formula/boltdb.rb | |
| echo " (bin/\"boltdb-run\").write <<~EOS" >> Formula/boltdb.rb | |
| echo ' #!/bin/bash' >> Formula/boltdb.rb | |
| echo ' exec "#{bin}/boltdb" -dir /var/lib/boltdb -addr 0.0.0.0:6379' >> Formula/boltdb.rb | |
| echo ' EOS' >> Formula/boltdb.rb | |
| echo ' chmod "+x", bin/"boltdb-run"' >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo '' >> Formula/boltdb.rb | |
| echo ' service do' >> Formula/boltdb.rb | |
| echo ' run bin/"boltdb-run"' >> Formula/boltdb.rb | |
| echo ' keep_alive true' >> Formula/boltdb.rb | |
| echo ' working_dir "/var/lib/boltdb"' >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo '' >> Formula/boltdb.rb | |
| echo ' test do' >> Formula/boltdb.rb | |
| echo ' assert_predicate bin/"boltdb", :exist?' >> Formula/boltdb.rb | |
| echo ' end' >> Formula/boltdb.rb | |
| echo 'end' >> Formula/boltdb.rb | |
| # Commit and push | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add Formula/boltdb.rb | |
| git commit -m "Update BoltDB to $VERSION" | |
| git push https://x-access-token:${{ secrets.HOMEBREW_TOKEN }}@github.com/lbp0200/homebrew-boltdb.git | |
| lint: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.25.7" | |
| cache: true | |
| - name: golangci-lint | |
| uses: golangci/golangci-lint-action@v7 | |
| with: | |
| version: v2.8.0 | |
| args: --timeout 5m |