chore: update the github ci/cd yml again #6
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: Build and Release | |
| on: | |
| push: | |
| branches: [main, dev] | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: golang:1.23.4-alpine | |
| steps: | |
| - name: Install Git and build tools | |
| run: | | |
| apk add --no-cache git make gcc musl-dev | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git safe directory | |
| run: | | |
| git config --global --add safe.directory "$(pwd)" | |
| - name: Build | |
| run: | | |
| make build | |
| - name: Test | |
| run: | | |
| make test | |
| docker: | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: hetuproject/checkpoint-dispatcher,hetuproject/checkpoint-validator | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=sha | |
| - name: Build and push dispatcher image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/dispatcher/Dockerfile | |
| push: true | |
| tags: hetuproject/checkpoint-dispatcher:${{ steps.meta.outputs.version }},hetuproject/checkpoint-dispatcher:latest | |
| cache-from: type=registry,ref=hetuproject/checkpoint-dispatcher:buildcache | |
| cache-to: type=registry,ref=hetuproject/checkpoint-dispatcher:buildcache,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Build and push validator image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/validator/Dockerfile | |
| push: true | |
| tags: hetuproject/checkpoint-validator:${{ steps.meta.outputs.version }},hetuproject/checkpoint-validator:latest | |
| cache-from: type=registry,ref=hetuproject/checkpoint-validator:buildcache | |
| cache-to: type=registry,ref=hetuproject/checkpoint-validator:buildcache,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| release: | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| runs-on: ubuntu-latest | |
| container: | |
| image: golang:1.23.4-alpine | |
| steps: | |
| - name: Install build tools | |
| run: | | |
| apk add --no-cache git make gcc musl-dev zip tar | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git safe directory | |
| run: | | |
| git config --global --add safe.directory "$(pwd)" | |
| - name: Build binaries | |
| run: | | |
| # Build for multiple platforms | |
| mkdir -p build/linux/amd64 build/linux/arm64 build/darwin/amd64 build/windows/amd64 | |
| # Linux amd64 | |
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o build/linux/amd64/dispatcher ./cmd/dispatcher | |
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o build/linux/amd64/validator ./cmd/validator | |
| # Linux arm64 | |
| CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -installsuffix cgo -o build/linux/arm64/dispatcher ./cmd/dispatcher | |
| CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -installsuffix cgo -o build/linux/arm64/validator ./cmd/validator | |
| # macOS (Darwin) | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/dispatcher ./cmd/dispatcher | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/validator ./cmd/validator | |
| # Windows | |
| CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/dispatcher.exe ./cmd/dispatcher | |
| CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/validator.exe ./cmd/validator | |
| - name: Create release archives | |
| run: | | |
| mkdir -p release | |
| cd build/linux/amd64 && tar -czvf ../../../release/checkpoint-linux-amd64.tar.gz * && cd - | |
| cd build/linux/arm64 && tar -czvf ../../../release/checkpoint-linux-arm64.tar.gz * && cd - | |
| cd build/darwin/amd64 && tar -czvf ../../../release/checkpoint-darwin-amd64.tar.gz * && cd - | |
| cd build/windows/amd64 && zip -r ../../../release/checkpoint-windows-amd64.zip * && cd - | |
| # use GitHub CLI to replace actions/upload-artifact | |
| - name: Install GitHub CLI | |
| run: | | |
| apk add --no-cache github-cli | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| gh release create $VERSION \ | |
| --title "Release $VERSION" \ | |
| --notes "Release $VERSION" \ | |
| release/checkpoint-linux-amd64.tar.gz \ | |
| release/checkpoint-linux-arm64.tar.gz \ | |
| release/checkpoint-darwin-amd64.tar.gz \ | |
| release/checkpoint-windows-amd64.zip |