feat: add ci/cd workflow & docker scripts #1
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] | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: "1.23.4" | |
| - name: Build | |
| run: | | |
| go build -v ./cmd/dispatcher | |
| go build -v ./cmd/validator | |
| - name: Test | |
| run: go test -v ./... | |
| docker: | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v4 | |
| 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@v4 | |
| 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 | |
| - name: Build and push validator image | |
| uses: docker/build-push-action@v4 | |
| 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 | |
| release: | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: "1.23.4" | |
| - name: Build binaries | |
| run: | | |
| # Build for multiple platforms | |
| GOOS=linux GOARCH=amd64 go build -o build/linux/amd64/dispatcher ./cmd/dispatcher | |
| GOOS=linux GOARCH=amd64 go build -o build/linux/amd64/validator ./cmd/validator | |
| GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/dispatcher ./cmd/dispatcher | |
| GOOS=darwin GOARCH=amd64 go build -o build/darwin/amd64/validator ./cmd/validator | |
| GOOS=windows GOARCH=amd64 go build -o build/windows/amd64/dispatcher.exe ./cmd/dispatcher | |
| 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/darwin/amd64 && tar -czvf ../../../release/checkpoint-darwin-amd64.tar.gz * && cd - | |
| cd build/windows/amd64 && zip -r ../../../release/checkpoint-windows-amd64.zip * && cd - | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| release/checkpoint-linux-amd64.tar.gz | |
| release/checkpoint-darwin-amd64.tar.gz | |
| release/checkpoint-windows-amd64.zip | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |