name: Build and Release on: release: types: [created] workflow_dispatch: inputs: tag: description: "Release tag (e.g., v1.0.0)" required: true build_binaries: description: "Build and upload binaries" type: boolean default: true build_docker: description: "Build and push Docker image" type: boolean default: true permissions: contents: write jobs: build: name: Build binaries runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v6 with: ref: ${{ inputs.tag || github.ref }} - name: Set build metadata run: | echo "VERSION=$(git describe --tags --always)" >> $GITHUB_ENV echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV echo "GO_VERSION=1.25.5" >> $GITHUB_ENV - name: Set up Go if: github.event_name == 'release' || inputs.build_binaries uses: actions/setup-go@v6 with: go-version: ${{ env.GO_VERSION }} cache: true - name: Build binaries if: github.event_name == 'release' || inputs.build_binaries run: | LDFLAGS="-X 'go.aykhans.me/sarin/internal/version.Version=${{ env.VERSION }}' \ -X 'go.aykhans.me/sarin/internal/version.GitCommit=${{ env.GIT_COMMIT }}' \ -X 'go.aykhans.me/sarin/internal/version.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)' \ -X 'go.aykhans.me/sarin/internal/version.GoVersion=$(go version)' \ -s -w" CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o ./sarin-linux-amd64 ./cmd/cli/main.go CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=linux GOARCH=arm64 go build -ldflags "$LDFLAGS" -o ./sarin-linux-arm64 ./cmd/cli/main.go CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=darwin GOARCH=amd64 go build -ldflags "$LDFLAGS" -o ./sarin-darwin-amd64 ./cmd/cli/main.go CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=darwin GOARCH=arm64 go build -ldflags "$LDFLAGS" -o ./sarin-darwin-arm64 ./cmd/cli/main.go CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=windows GOARCH=amd64 go build -ldflags "$LDFLAGS" -o ./sarin-windows-amd64.exe ./cmd/cli/main.go CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=windows GOARCH=arm64 go build -ldflags "$LDFLAGS" -o ./sarin-windows-arm64.exe ./cmd/cli/main.go - name: Upload Release Assets if: github.event_name == 'release' || inputs.build_binaries uses: softprops/action-gh-release@v2 with: tag_name: ${{ inputs.tag || github.ref_name }} files: ./sarin-* - name: Set up QEMU if: github.event_name == 'release' || inputs.build_docker uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx if: github.event_name == 'release' || inputs.build_docker uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub if: github.event_name == 'release' || inputs.build_docker uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker image if: github.event_name == 'release' || inputs.build_docker uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64 push: true build-args: | VERSION=${{ env.VERSION }} GIT_COMMIT=${{ env.GIT_COMMIT }} GO_VERSION=${{ env.GO_VERSION }} tags: | ${{ secrets.DOCKERHUB_USERNAME }}/sarin:${{ env.VERSION }} ${{ secrets.DOCKERHUB_USERNAME }}/sarin:latest