Merge pull request #1 from hpowernl/code_improve #13
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: Build Cache Warmer | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ main, master ] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build Multi-Platform Binaries | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Install cross-compilation tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build Linux AMD64 | |
| run: | | |
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o cache-warmer-linux-amd64 cache-warmer.go | |
| chmod +x cache-warmer-linux-amd64 | |
| - name: Build Linux ARM64 | |
| run: | | |
| CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -ldflags="-s -w" -o cache-warmer-linux-arm64 cache-warmer.go | |
| chmod +x cache-warmer-linux-arm64 | |
| - name: Install QEMU for ARM64 testing | |
| run: | | |
| sudo apt-get install -y qemu-user-static | |
| - name: Test AMD64 binary | |
| run: | | |
| ./cache-warmer-linux-amd64 init --force | |
| ./cache-warmer-linux-amd64 status || true | |
| echo "AMD64 binary tested successfully!" | |
| rm -f config.toml warmer.db | |
| - name: Test ARM64 binary | |
| run: | | |
| qemu-aarch64-static -L /usr/aarch64-linux-gnu ./cache-warmer-linux-arm64 init --force | |
| qemu-aarch64-static -L /usr/aarch64-linux-gnu ./cache-warmer-linux-arm64 status || true | |
| echo "ARM64 binary tested successfully!" | |
| rm -f config.toml warmer.db | |
| - name: Create checksums | |
| run: | | |
| sha256sum cache-warmer-linux-amd64 > checksums.txt | |
| sha256sum cache-warmer-linux-arm64 >> checksums.txt | |
| cat checksums.txt | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: cache-warmer-binaries | |
| path: | | |
| cache-warmer-linux-amd64 | |
| cache-warmer-linux-arm64 | |
| checksums.txt | |
| retention-days: 90 | |
| - name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| cache-warmer-linux-amd64 | |
| cache-warmer-linux-arm64 | |
| checksums.txt | |
| draft: false | |
| prerelease: false | |
| make_latest: true | |
| body: | | |
| ## Cache Warmer ${{ github.ref_name }} | |
| ### 📦 Binaries | |
| Download the binary for your platform: | |
| - **Linux x86_64 (AMD64)**: `cache-warmer-linux-amd64` | |
| - **Linux ARM64**: `cache-warmer-linux-arm64` | |
| ### 🚀 Installation | |
| ```bash | |
| # Download binary (replace VERSION with the tag, e.g. v1.0.0) | |
| wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/cache-warmer-linux-amd64 | |
| # Make executable | |
| chmod +x cache-warmer-linux-amd64 | |
| # Optional: rename to cache-warmer | |
| mv cache-warmer-linux-amd64 cache-warmer | |
| # Test | |
| ./cache-warmer init | |
| ./cache-warmer status | |
| ``` | |
| ### 🔐 Checksums | |
| Verify the download with `checksums.txt`: | |
| ```bash | |
| sha256sum -c checksums.txt | |
| ``` | |
| ### 📝 Usage | |
| See the [README](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/README.md) for complete documentation. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |