How to Set Up a CI/CD Pipeline for Go with GitLab CI

Set up a GitLab CI pipeline for Go by creating a .gitlab-ci.yml file with build, test, and deploy stages.

Create a .gitlab-ci.yml file in your repository root to define the build, test, and deploy stages for your Go application.

stages:
  - build
  - test
  - deploy

build:
  stage: build
  image: golang:1.21
  script:
    - go build -o myapp .

test:
  stage: test
  image: golang:1.21
  script:
    - go test -v ./...

deploy:
  stage: deploy
  image: alpine:latest
  script:
    - echo "Deploying myapp..."
  only:
    - main

Commit and push this file to trigger the pipeline.