name: Build and Push Docker Image on: push: branches: - main tags: - v* env: IMAGE_NAME: oapi-feishu jobs: build: runs-on: ubuntu-latest strategy: matrix: go-version: [1.23.x] platform: [linux/amd64, linux/arm64] steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - name: Initialize Go module if needed working-directory: ./code run: | if [ ! -f go.mod ]; then go mod init github.com/${{ github.repository }} go mod tidy fi - name: Build Go binary working-directory: ./code run: | CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} go build -ldflags '-w -s' -o ../feishu_chatgpt - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to DockerHub uses: docker/login-action@v2 with: username: woodchen password: ${{ secrets.ACCESS_TOKEN }} - name: Prepare Docker metadata id: meta uses: docker/metadata-action@v4 with: images: woodchen/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . platforms: ${{ matrix.platform }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}